Page 1 of 1

How generate PDF as variable?

Posted: Tue Nov 22, 2022 6:29 am
by Piotr D
Hi,
how can I generate PDF without saving to a file? I need the content of PDF's as variable, while it must be base64 encoded.

Regards
Piotr

Re: How generate PDF as variable?

Posted: Tue Nov 22, 2022 7:15 am
by rdonnay
There are lots of ways to create a PDF, but they all create a file.

You can first create the PDF file then make it into a Base64 string like this:

Code: Select all

DCPRINT ON NAME "Microsoft PDF Printer" TOFILE OUTFILE 'MyPrintJob.Pdf'

.. DCPRINT commands

DCPRINT OFF

cBase64 := DC_File2Base64('MyPrintJob.Pdf')

* ------------------------------

FUNCTION DC_File2Base64( cInputFile )

LOCAL nHandle, nSize, cBuffer, cBase64

nHandle := FOpen(cInputFile)
nSize := FSeek(nHandle,0,FS_END)
cBuffer := Space(nSize)
FSeek(nHandle,0,FS_SET)
nSize := Fread(nHandle,@cBuffer,nSize)
FClose(nHandle)
IF nHandle <= 0
  cBase64 := ''
ELSE
  cBase64 := Bin2Base64(cBuffer)
ENDIF

RETURN cBase64

Re: How generate PDF as variable?

Posted: Tue Nov 22, 2022 11:49 pm
by Piotr D
Hi Roger,
thanks for you tip - this way I know. But I search any way without creating a file. I find a DynamicPDF library, who can do it, but it's too expensive only for this purpose.

Regards
Piotr