I'd like to include a suggested file name when printing to a PDF using
I found
this answer on Stack Overflow that suggests a way to do this in Delphi, but fpc/lazarus doesn't have
.GetPrinter() or a compatible
SetPrinter() in printers.pas.
I'm not using actually the
PrintDialog when printing to PDF as my document is fixed in size so I have have no need for a dialog, I am simply setting the printer and the number of copies directly on the
Printer object then running through the same routine I use when printing to any other printer. (I do use the dialog when printing normally to allow the user to select the printer, though, so the dialog is available).
Printer.SetPrinter('Microsoft Print To PDF');
Printer.Copies:=1;
// PrintDialog1.PrintToFile:=true;
// Printer.FileName:=suggestFileName()+'.pdf';
doPrint();
Everything works except for setting a filename in the dialog that pops up for saving the generated PDF.
The two commented lines are things I initially tried to set a filename (suggestFileName() returns a string with a suggetsed file name based on various parameters form the rest of the application, doPrint() contains all of the
BeginDoc and
EndDoc stuff as well as
Printer.PaperSize.PaperName:=,
Printer.Title:= etc).
When printing normally (ie not to a PDF) I am using:
if (PrintDialog1.Execute) then doPrint();
Surely there must be a Lazarus/FPC way to acheive this if it was possible in Delphi...
Thanks,
-FM