Recent

Author Topic: Custom Paper Size for Printing  (Read 772 times)

lelu111

  • Newbie
  • Posts: 6
Custom Paper Size for Printing
« on: August 28, 2023, 11:51:04 pm »
I have a bitmap I want to print with a printer. However, I need to use a very specific paper size that does not match any common one. So I want to set the paper size in the code but only found the Papersize.PaperName working with which I can only set the common paper sizes. I checked and my printer also supports custom paper sizes. I found Printer.Papersize.PaperRect.PhysicalRect which I can calculate but I cannot change the variable.
Is there any way to set a cutom paper size?

jamie

  • Hero Member
  • *****
  • Posts: 6964
Re: Custom Paper Size for Printing
« Reply #1 on: August 29, 2023, 12:27:00 am »
Did you try the PageSetupDialog ?

there you can select CUSTOM and then adjust the size.
The only true wisdom is knowing you know nothing

lelu111

  • Newbie
  • Posts: 6
Re: Custom Paper Size for Printing
« Reply #2 on: August 29, 2023, 12:30:41 pm »
I am aware there is a dialog window for it, but firstly: I don't know if I have to extract those values and if yes, how; secondly: it would be better for me to hardcode the paper size because it would be annoying at runtime if every time I want to print I have to deal with a popup window. So I would only use it if there is no other way I can do it.

PawelO

  • New Member
  • *
  • Posts: 27
    • Polish railway traffic and interlocking simulator developed with Lazarus
Re: Custom Paper Size for Printing
« Reply #3 on: May 20, 2025, 04:53:24 pm »
Encountered same problem recently, and found a "solution": you have to set the custom PaperSize.PaperRect twice, then it would be actually used. At least this works with creating custom-sized PDF with CutePDF printer app, I haven't tried other printers. Looks like a bug, or I'm missing something?

Code: Pascal  [Select][+][-]
  1. var
  2.   paperSize: TPaperRect;
  3. begin
  4.   Printer.SetPrinter(cbPrinter.Text); //from ComboBox
  5.  
  6.   paperSize.PhysicalRect.Left   := 0;
  7.   paperSize.PhysicalRect.Top    := 0;
  8.   paperSize.PhysicalRect.Width  := round((10 / 2.54) * Printer.XDPI); //10 x 10 cm
  9.   paperSize.PhysicalRect.Height := round((10 / 2.54) * Printer.YDPI);
  10.   paperSize.WorkRect := paperSize.PhysicalRect;
  11.  
  12.   Printer.PaperSize.PaperRect := paperSize;
  13.   Printer.PaperSize.PaperRect := paperSize; //apparently this is necessary
  14.  
  15.   Printer.BeginDoc();
  16.   ...

 

TinyPortal © 2005-2018