Recent

Author Topic: [SOLVED] Trouble with Canvas and Printing Size  (Read 1137 times)

lelu111

  • Newbie
  • Posts: 6
[SOLVED] Trouble with Canvas and Printing Size
« on: August 12, 2023, 05:09:03 pm »
I want to make a program which prints out (you know, to paper) some values. I need them to be in the right place because I have a pre-printed sheet with boxes which I have to fill with my own program's values. I can calculate where to print them based on a percentage system. I am using a TCanvas to draw all the text, however I cannot resize it to fit the paper's size. I got the paper's size in pixels with
Code: Pascal  [Select][+][-]
  1. h := Printer.PageHeight; w := Printer.PageWidth
but I cannot resize the canvas neither before nor after drawing. If I just use the PageHeight and PageWidth and don't care about canvas size then it causes a SIGSEGV exception. (at least I think it causes it)
Is there any way to work it around or should I take an other path instead of TCanvas? If the latter, what would you reccommend?
« Last Edit: August 12, 2023, 05:46:10 pm by lelu111 »

jamie

  • Hero Member
  • *****
  • Posts: 7764
Re: Trouble with Canvas and Printing Size
« Reply #1 on: August 12, 2023, 05:14:37 pm »
Create a BMP the size of your printer page, draw on that and then send the BMP to the printer?
The only true wisdom is knowing you know nothing

lelu111

  • Newbie
  • Posts: 6
Re: Trouble with Canvas and Printing Size
« Reply #2 on: August 12, 2023, 05:20:48 pm »
I was concerned if it would decrease the quality and I was also curious if it was possible to make it in a canvas, but if you think it is the best way then I believe you. So I will try it. Thanks

lelu111

  • Newbie
  • Posts: 6
Re: Trouble with Canvas and Printing Size
« Reply #3 on: August 12, 2023, 05:30:15 pm »
Now I tried with this solution (I never used Bitmaps before so there may be nooby mistakes)
I wrote this code:
Code: Pascal  [Select][+][-]
  1. var MyBitMap : TBitMap;
  2.     w, h : longint;
  3. begin
  4.   MyBitMap.Create;
  5.   w := 30;
  6.   h := 50;
  7.   MyBitMap.Width:=w;
  8.   MyBitMap.Height:=h;
  9.   MyBitMap.Canvas.Create;
  10.   ShowMessage('Canvas size: '+IntToStr(MyBitMap.Canvas.Width)+' '+IntToStr(MyBitMap.Canvas.Height));
  11.   MyBitMap.Destroy;
  12. end.  
but there was also a SIGSEGV class exception.
Where is the error?

jamie

  • Hero Member
  • *****
  • Posts: 7764
Re: Trouble with Canvas and Printing Size
« Reply #4 on: August 12, 2023, 05:37:21 pm »
Do not use the width or height property of the canvas.

Also, do not create the canvas, it's already there.
The only true wisdom is knowing you know nothing

qk

  • New Member
  • *
  • Posts: 35
Re: Trouble with Canvas and Printing Size
« Reply #5 on: August 12, 2023, 05:40:51 pm »
Too much code ...  :)

Code: Pascal  [Select][+][-]
  1. var MyBitMap : TBitMap;
  2. begin
  3.   MyBitMap := TBitMap.Create;
  4.   MyBitMap.SetSize(30, 50);
  5.   ShowMessage('Canvas size: '+IntToStr(MyBitMap.Width) + ' ' + IntToStr(MyBitMap.Height));
  6.   MyBitMap.Destroy;
  7. end;

jamie

  • Hero Member
  • *****
  • Posts: 7764
Re: Trouble with Canvas and Printing Size
« Reply #6 on: August 12, 2023, 05:42:46 pm »
Better to use FREE, just in case object is nil.
The only true wisdom is knowing you know nothing

lelu111

  • Newbie
  • Posts: 6
Re: Trouble with Canvas and Printing Size
« Reply #7 on: August 12, 2023, 05:45:22 pm »
Thank you! I didn't know about TBitmap.Setsize. Thanks again for your help!

 

TinyPortal © 2005-2018