How To Save To PDF Using GhostScript In PowerBuilder

How To Save To PDF Using GhostScript In PowerBuilder

Many PowerBuilder developers have had this question in many forums and I thought it best to document the process we follow to save to PDF using GhostScript in PowerBuilder applications. You can follow these steps and it works perfectly. We have many reports that we allow users to save as PDF and have had no issues or concerns.

Power builder can save the report as PDF file with the help of PDF creator software.

For PDF file creation the data window report first transfers the data to postscript with the help of postscript printer driver. After that with the help of ghost script, post script is converted to PDF.

 

Installation Steps: Process of converting to Postscript.

For this process there should be a Postscript printer driver installed in the system. We can install Sybase PostScript printer from the Power builder driver files.

Steps for installing Sybase PS printer ( For windows 32 Bit system)

Control Panel – Add printer – Select Port as File – Click button “Have from Disk” – Select the “ADIST5” setup install file (This can be obtained from the C:\Program Files\Sybase\Shared\PowerBuilder\drivers\ folder)

After the Postscript printer installation, it is required to keep the printer name as “Sybase DataWindow PS”. While creating the postscript, powerbuilder is looking for the postscript printer driver having printer name as “Sybase DataWindow PS” so make sure you name it right.

Note : If we don’t want to use this default printer in the “save as” process, we need to explicitly code in the powerbuilder as

dw_current.object.datawindow.export.pdf.method = 1

dw_current.object.datawindow.export.pdf.distill.custompostscript = “1”

dw_current.object.datawindow.export.pdf.xslfop.print = “0”

l_save = dw_current.saveas(“”, PDF!, False)

 

Steps for installing Sybase PS printer ( For windows 64 Bit system)

The postscript printer driver installation files  present in the powerbuilder folder is not supporting 64 bit system. In this case we can install any other postscript printer driver in that system as follows:

Device and Printer : Add Printer : Select Local Printer : Select Port( As File):  Select any of the post script printer driver while installation(Eg : HP Color LaserJet 2800 Series PS post script printer driver can be identified as PS extension).

Here also change the printer name to “Sybase DataWindow PS” after installation.

Steps for installing Sybase PS printer (For Windows Surface 64 Bit system)

 

Add this to your System – Environment Variables – Path variable

C:\Program Files\gs\gs9.20\bin (let this be the first entry in the path variable)

Add the PDF Printer:

Device and Printer : Add Printer : Select Local Printer : Select Port( As File) : Select any of the post script printer driver while installation(Eg : HP Color LaserJet 2500 PS Class Driver)

Post script printer driver can be identified as PS extension.

Change the printer name to “Sybase DataWindow PS” after installation.

 

Screenshots on Surface:

Programs & Features:

Environment Variable:

Printers:

 

Process of converting Postscript to PDF

This can be achieved with the help of the ghostscript installed in the system.

We can install the ghostscript with version 7.05 or later.

Download & Install GhostScript: Use this link : Download Here

The installation process will create a new entry in system registry and system initialization path.

If initialization path is not set automatically, PDF conversion process will work fine. But while saving the PDF file, default PDF file type will not come automatically. Because this is setting through powerbuilder code after checking the entry in the system variables.

If it is not happened automatically we need to add the ghostscript bin folder entry in the initialization file path. While editing the system variable as, PATH = C:\Program Files\gs\gs7.05\bin;

Un Installation of Ghostsscript

While uninstalling the ghost script, it is not clearing the system path and Program folder. If we wan’t we can remove the folder entry from C:\ProgramFile\gs and also from the environment variable. But this manual removal is not a mandatory thing.

 

About pbgeeks 11 Articles
PBGeeks is a website for PowerBuilder Professionals to come together and explore the new features being released in PB. Participate in the Forum and exchange your thoughts with the other PB Gurus. Job seekers can find plenty of most recent jobs all around the world in the Jobs Listing section. Employers can post their job openings to be made available to the entire PB community.