Recent

Author Topic: how to save print job to postscript?  (Read 1289 times)

mirce.vladimirov

  • Full Member
  • ***
  • Posts: 236
how to save print job to postscript?
« on: February 26, 2021, 09:56:11 pm »
Hi ,
I'm using Lazreport under windows.
How can I save the output of my lazreport to a postscript file instead of sending it to printer?
I tried this:
Code: Pascal  [Select][+][-]
  1. printer.FileName:='c:/temp/sometest.ps';
  2.   frReport1.LoadFromFile('r1.lrf');
  3.   if frreport1.PrepareReport=true then
  4.      frreport1.PrintPreparedReport('1-9999', 1);
  5.  
  6.   ShowMessage('All done');  

But this is not good, the output file is of unknown format , it's not ps.

mirce.vladimirov

  • Full Member
  • ***
  • Posts: 236
Re: how to save print job to postscript?
« Reply #1 on: February 26, 2021, 10:48:43 pm »
There is at least some progress.

First, in the Lazreport designer in File/ReportOPtions, i changed the printer to "Microsoft Print to PDF", and then saved it.

When i runned the code (which i previously posted) i got a valid PS file (it was saved in the desired folder and system didn't prompt for location and name) , and that was great, but there was a bad news, my cyrillics is not interpreted, just places some characters blah blah blaaahhh.
And, when i am converting the PS to PDF i'm getting messages complaining about fonts, see attachment no1.jpg.

Then, again,  in the Lazreport designer in File/ReportOptions, i changed the printer to "PDFCreator", and then saved it.

Now when i runned the code, I got a valid PS file (again, it was saved in the desired folder and system didn't prompt for location and name) and my cyrillics was as it should be.
Then I converted the PS to PDF, and again, all good. And during conversion I get the messages shown in the attachment no2.jpg

Still,  If there is a way to bypass the PDFCreator and simillar it would be good.

Since windows 10 there is this "Microsoft Print to PDF" and it's good, am using it via "choose printer" and prints ok, but it would be good to use it this way, to get a PostScript file programaticaly, without prompting, I dont know what I am missing?




mirce.vladimirov

  • Full Member
  • ***
  • Posts: 236
Re: how to save print job to postscript?
« Reply #2 on: February 26, 2021, 11:24:32 pm »
More update:

When in Lazreport Designer, go to File/ReportOptions and under "Printer" choose "Default printer". 
At first, i did not pay attention to this and Lazreport used the driver of my default printer, MFP Brother L2720DW , and that's why the output file was not valid Postscript.
Just enter "Default printer" there and keep on.

Then, in the code:
Code: Pascal  [Select][+][-]
  1. i:=0;
  2.   for i:=0 to printer.Printers.Count-1 do begin
  3.        if (pos('Microsoft Print to PDF', printer.printers[i] )>0) then begin
  4.          printer.PrinterIndex:=i;
  5.      end;
  6.  
  7.   printer.FileName:='c:/temp/pstopdf/sometest.ps';  // this way it wont ask you about path to your file
  8.   frReport1.LoadFromFile('r1.lrf');
  9.   if frreport1.PrepareReport=true then
  10.      frreport1.PrintPreparedReport('1-9999', 1);  
  11.   end;

When it's done, in command prompt do
Code: Pascal  [Select][+][-]
  1. C:\temp\pstopdf>gswin32c.exe -quit -o p1.pdf -sDEVICE=pdfwrite sometest.ps

and you got your PDF, no need of other software.
There are two files needed from the PDFCreator directory : gswin32c.exe  and  gsdll32.dll , both these reside in same directory, and you need to distribute them along with your application, but that's OK i guess, since Ghostscript is free software (as far as I know, please correct me if i am wrong).

EDIT:
On my PC , there are two directories with Ghostscript and both contain the named two files gswin32c.exe  and  gsdll32.dll :
1. c:\Program Files (x86)\GPLGS
and
2. c:\Program Files\PDFCreator\Ghostscript

second one (PDFCreator's)  is the one that exports to PS correctly and converts PS to PDF correctly thru command line, use those.
« Last Edit: February 27, 2021, 11:23:54 am by mirce.vladimirov »

 

TinyPortal © 2005-2018