How generate PDF as variable?

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
Piotr D
Posts: 131
Joined: Mon Jul 28, 2014 1:26 am
Location: Poznań, Poland

How generate PDF as variable?

#1 Post 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

User avatar
rdonnay
Site Admin
Posts: 4775
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How generate PDF as variable?

#2 Post 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
The eXpress train is coming - and it has more cars.

Piotr D
Posts: 131
Joined: Mon Jul 28, 2014 1:26 am
Location: Poznań, Poland

Re: How generate PDF as variable?

#3 Post 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

Post Reply