Recent

Author Topic: Printing pdf file with Printers unit produces ps file instead  (Read 4746 times)

jalphonse

  • New Member
  • *
  • Posts: 10
Hello,

I work with Lazarus 1.6 for Windows 7.
I wish to print into a pdf file, using the installed Adobe printer.

For some reason, my program creates a Postscript file instead of the expected pdf file.
This is my trial pocedure:
PrintDialog1.Options:=[poPrintToFile];
if PrintDialog1.Execute then with Printer do
begin
  BeginDoc;
  Canvas.Font.Name := 'Courier New';
  Canvas.TextOut(100, 100, 'Hello Lazarus!');
  EndDoc;
end;

Thanks,
jalphonse

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: Printing pdf file with Printers unit produces ps file instead
« Reply #1 on: May 02, 2016, 09:25:10 pm »
Maybe you should not call PrintDialog1.Options:=[poPrintToFile];?
Did you also check if Printer.PrinterIndex really matches your selected printer?

jalphonse

  • New Member
  • *
  • Posts: 10
Re: Printing pdf file with Printers unit produces ps file instead
« Reply #2 on: May 02, 2016, 11:15:14 pm »
Maybe you should not call PrintDialog1.Options:=[poPrintToFile];?
Did you also check if Printer.PrinterIndex really matches your selected printer?

If I do not call PrintDialog1.Options:=[poPrintToFile], no file is created.
I checked PrinterIndex (=3) and PrinterName (=Adobe PDF). This seems correct to me.

jalphonse

  • New Member
  • *
  • Posts: 10
Re: Printing pdf file with Printers unit produces ps file instead
« Reply #3 on: May 15, 2016, 04:59:39 pm »
...
using the installed Adobe printer (...) For some reason, my program creates a Postscript file instead of the expected pdf file.
...

I eventually found the answer myself:
FileName has to be empty and Title set to the name of the output file (e.g. Printer.Filename:=''; Printer.Title:='file'). This is mandatory in order to create a pdf file using the Adobe PDF printer.

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: Printing pdf file with Printers unit produces ps file instead
« Reply #4 on: May 18, 2016, 05:40:07 pm »
If I do not call PrintDialog1.Options:=[poPrintToFile], no file is created.

A PDF printer should IMHO always produce a PDF file, that's why I've suggested this.
However, I don't know Adobe PDF printer, been using another PDF printers.
Important is that your fix works for you.
 

jalphonse

  • New Member
  • *
  • Posts: 10
Re: Printing pdf file with Printers unit produces ps file instead
« Reply #5 on: May 20, 2016, 11:47:49 am »
A PDF printer should IMHO always produce a PDF file, that's why I've suggested this.
I agree with you.
I have no idea about why under certain parameters I get a postscript file. However, looking into the Properties of the Adobe PDF printer, several fields indeed refer to Postscript options.

To be more specific, here is the result of the various combinations of  Printer.Filename and Printer.Title:
Filename empty + Title non empty: ok, pdf file generated, name of file corresponds to Title
Filename non empty + Title empty: opens a window asking for file name, postscript file generated
Filename empty + Title empty: no file generated
Filename non empty + Title non empty: opens a window asking for file name followed by postscript error

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Printing pdf file with Printers unit produces ps file instead
« Reply #6 on: May 20, 2016, 11:57:51 am »
When you're using poPrintToFile, isn't the whole Adobe PDF-creation procedure then bypassed? Adobe PDF printer uses a Postscript driver to create a file (itself) and in the process after that the file is converted to a PDF. (That's also how other PDF-printers work)

What happens if you leave Filename empty + Title non empty and remove the poPrintToFile? If the PDF-file then also correctly created? In that case you should never use poPrintToFile yourself because you instruct the Postscript driver to skip the post-process part and just output its raw content to file (and that's just postscript-code).

jalphonse

  • New Member
  • *
  • Posts: 10
Re: Printing pdf file with Printers unit produces ps file instead
« Reply #7 on: May 20, 2016, 04:30:51 pm »
When you're using poPrintToFile, isn't the whole Adobe PDF-creation procedure then bypassed? Adobe PDF printer uses a Postscript driver to create a file (itself) and in the process after that the file is converted to a PDF. (That's also how other PDF-printers work)

What happens if you leave Filename empty + Title non empty and remove the poPrintToFile? If the PDF-file then also correctly created? In that case you should never use poPrintToFile yourself because you instruct the Postscript driver to skip the post-process part and just output its raw content to file (and that's just postscript-code).

Thanks for the information about the pdf printers.

The poPrintToFile itself is not a problem: it only displays the checkbox "Print to file", unchecked. If I check it, then the "whole Adobe PDF-creation procedure then bypassed" as you explain.

 

TinyPortal © 2005-2018