Reputation:
I am writing a WYSIWYG page designer application, which will allow user to drop images and text onto a designer Panel and then print the panel to PDF.
In my application's Page Setup options, the user needs to select a page size, and then, based on selected page size it will show a panel on screen that is sized according to the dimensions (eg A4 selected = 8.5 x 11 inches and Panel will be sized to these pixel dimensions) .
Then when user clicks Print, the contents of the Panel will be drawn to a PDF file with the selected dimensions.
I am using the wPDF component set, and the TWPPDFPrinter component in particular to create the PDF.
My question:
Thanks in advance.
Upvotes: 4
Views: 3940
Reputation: 54772
To get the list of all the printer forms defined in a 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;
Upvotes: 1
Reputation: 43649
Why don't you use the default printer setup dialog?
Link the following handler to the OnAccept
event of a TFilePrintSetup
action:
procedure TForm1.FilePrintSetup1Accept(Sender: TObject);
var
Scale: Single;
begin
Scale := Printer.PageHeight / Printer.PageWidth;
DesignerPanel.Height := Round(DesignerPanel.Width * Scale);
end;
Ét voila.
Upvotes: 0
Reputation: 9965
You can get a list of paper sizes using EnumForms and Querying the local print server. see this question
Upvotes: 2