How to get all paper size names and corresponding pixel sizes?

I am writing a WYSIWYG page creation application that will allow the user to delete images and text on the designerโ€™s panel, and then print the panel in PDF format.

In the page settings page settings, the user needs to select a page size, and then, based on the selected page size, a panel appears on the screen, the size of which corresponds to the size (for example, the selected A4 = 8.5 x 11 inches and the panel will have a size for these pixel sizes )

Then, when the user clicks the "Print" button, the contents of the panel will be drawn in a PDF file with the selected options.

I use a set of wPDF components and a TWPPDFPrinter component, in particular, to create a PDF.

My question is:

  • How to get a list of all paper size names, and then how to get the appropriate sizes for wPDFPrinter?

Thanks in advance.

+4
source share
3 answers

To get a list of all the printer forms defined in the system:

uses winspool, printers; ... procedure TForm1.Button1Click(Sender: TObject); var HPrinter: THandle; Forms: array of TFormInfo1; Count, Needed, Returned: DWORD; i: Integer; begin Memo1.Clear; if OpenPrinter(nil, HPrinter, nil) then begin try if not EnumForms(HPrinter, 1, nil, 0, Needed, Returned) then begin // we should fail here since we didn't pass a buffer if GetLastError <> ERROR_INSUFFICIENT_BUFFER then RaiseLastOSError; Count := (Needed div SizeOf(TFormInfo1)) + 1; SetLength(Forms, Count); if EnumForms(HPrinter, 1, @Forms[0], SizeOf(TFormInfo1) * Count, Needed, Returned) then begin if Returned < Count then SetLength(Forms, Returned); for i := 0 to Returned - 1 do begin Memo1.Lines.Add(Format('Paper name: %s, Paper size: %dmm x %dmm', [Forms[i].pName, Forms[i].Size.cx div 1000, Forms[i].Size.cy div 1000])) end; end else RaiseLastOSError; end; finally ClosePrinter(HPrinter); end; end else RaiseLastOSError; end; 
+2
source

You can get a list of paper sizes using EnumForms and querying the local print server. see this question

+2
source

Why aren't you using the default printer settings dialog box?

Bind the following handler to the OnAccept event of the OnAccept action:

 procedure TForm1.FilePrintSetup1Accept(Sender: TObject); var Scale: Single; begin Scale := Printer.PageHeight / Printer.PageWidth; DesignerPanel.Height := Round(DesignerPanel.Width * Scale); end; 

ร‰t voila.

+1
source

All Articles