SET CURRENT PRINTER(Generic PDF driver)

Hey,

A document is printed to PDF (Windows 10 driver’s): is the file ready and unlocked when it appears on the drive for the very first time or is possible that 4D is still “printing”?

<code 4D>
C_TEXT($T_Path_PDF)
$T_Path_PDF:=System folder(Desktop)+“Facture “+[FACTURE_CLIENT]Numéro_Facture+”.pdf”
SET CURRENT PRINTER(Generic PDF driver)
SET PRINT OPTION(Destination option;2;$T_Path_PDF)

</code 4D>

Hi Bertrand,

An empty file is created and then written to by the driver. So if you try to use it as soon as it appears you may find that it is incomplete.

If the driver keeps the file locked during writing, you may be able to use GET DOCUMENT PROPERTIES to check whether it is finished. I haven’t checked that so don’t know whether that would work.

Since the last line of a valid PDF file should be %%EOF, you could always check for that. Something along the lines of this.
<code 4D>
$valid:=False
$break:=False
SET BLOB SIZE($bytes;0)
SET DOCUMENT POSITION($pdf;-1;2)
Repeat
RECEIVE PACKET($pdf;$bytes;1)
Case of
: ($bytes{0}=Carriage return) | ($bytes{0}=Line feed)
SET DOCUMENT POSITION($pdf;-2;3) //next
: ($bytes{0}=Character code(“F”))
SET DOCUMENT POSITION($pdf;-6;3)
//Get %%EOF
RECEIVE PACKET($pdf;$bytes;6)
$valid:=(($bytes{0}=Carriage return) | ($bytes{0}=Line feed))
& ($bytes{1}=Character code("%"))
& ($bytes{2}=Character code("%"))
& ($bytes{3}=Character code(“E”))
& ($bytes{4}=Character code(“O”))
& ($bytes{5}=Character code(“F”))
$break:=True
Else
$break:=True
End case
Until ($break)
</code 4D>

I currently use PDFCreator for automated generation of PDFs and I am thinking of switching to the generic driver, so I’d be interested to see what you end up doing.

: Adam STORCK

I currently use PDFCreator for automated generation of PDFs and I am
thinking of switching to the generic driver, so I’d be interested to
see what you end up doing.

Thank you and stay tuned

Much easier with our pdf plugin.

Sample:
<code 4D>
$err:=TobitProXL_PDFStart ($PDFpath;$vs80_PrinterName;$vl_DriverVersion;1;1) //full path is needed
If ($err=0)
//*** set pdf options (author, info, password, copyright, etc)
PDF_SetOptions //optional
//*** use watermark or letter forms ?
PDF_LetterForms
//****** set BookMark if you like it
PDF_SetBookMark ("") //sets an optional bookmark for the first page of the next print job
//*** print something (maybe 4D Write or Write Pro)
WR_PrintArea
//*** attach extern docs ?
PDF_PrintExternDocs
//*** close job, finish the pdf and reset the printer driver
$err:=TobitProXL_Save
End if
</code 4D>

If TobitProXL_Save return the 0, then the pdf is ready. And the resulting pdf is much smaller than the generic windows 10 pdf driver.

Armin

: Armin DEEG

And the resulting pdf is much smaller than the generic windows 10 pdf
driver.

I’ve noticed that the generic driver produces bloated PDFs. We recommend that our users install something like CutePDF for general printing to PDF.