PDF and XSL-FO export

PowerBuilder can save the DataWindow's data and presentation as a Portable Document Format (PDF) file using three techniques. By default, PowerBuilder saves as PDF using a distiller. PowerBuilder can also save to native PDF using PDFlib, or save to PDF or XSL Formatting Objects (XSL-FO) format using the Apache XML Formatting Objects processor.

Using the Ghostscript distiller

In order for users to use the SaveAs method to save data as PDF with the distiller, they must first download and install Ghostscript on their computers as described in the procedure that follows.

The use of GPL Ghostscript is subject to the terms and conditions of the GNU General Public License (GPL). Users should be asked to read the GPL before installing GPL Ghostscript on their computers. A copy of the GPL is available on the GNU Project Web server at http://www.gnu.org/licenses/gpl.html.

The use of AFPL Ghostscript is subject to the terms and conditions of the Aladdin Free Public License (AFPL). Commercial distribution of AFPL Ghostscript generally requires a written commercial license. For more information, see the Ghostscript Web site at https://www.ghostscript.com.

To install Ghostscript:

  1. Into a temporary directory on your computer, download the self-extracting executable file for the version of Ghostscript you want from one of the sites listed on the Ghostscript Web site at https://www.ghostscript.com/download/.

    See the Release Bulletin for the version of Ghostscript that was used for testing.

  2. Run the executable file to install Ghostscript on your system.

    The default installation directory is C:\Program Files\gs. You can select a different directory and/or choose to install shortcuts to the Ghostscript console and readme file.

After installing Ghostscript, you should read the readme.htm file in the doc subdirectory in the Ghostscript installation directory to find out more about using Ghostscript and distributing it with your application.

Save Rows As fails

To save as PDF in the DataWindow painter, select File>Save Rows As and select PDF as the Save As type. If you do not install Ghostscript and use the default export properties, PowerBuilder displays a pop-up window notifying you that Save Rows As failed. If you install Ghostscript and then change the name of the directory where Ghostscript is installed, Save Rows As PDF fails silently.

Location of files

When you save a DataWindow object as PDF using the distill method, PowerBuilder searches in the following locations for an installation of GPL or AFPL Ghostscript:

  • The Windows registry

  • The relative path of the pbdwe170.dll file (typically Appeon\Shared\PowerBuilder)

  • The system PATH environment variable

If GPL or AFPL Ghostscript is installed using the Ghostscript executable file, the path is added to the Windows registry.

If the Ghostscript files are in the relative path of the pbdwe170.dll file, they must be installed in this directory structure:

dirname\pbdwe170.dll
dirname\gs\gsN.NN
dirname\gs\fonts

where dirname is the directory that contains the runtime DLLs and N.NN represents the release version number for Ghostscript.

You might not need to distribute all the fonts provided in the distribution. For information about fonts, see Fonts and font facilities supplied with Ghostscript at https://www.ghostscript.com/doc/current/Fonts.htm.

PostScript printer drivers

If your users have installed a PostScript printer on their computers, the PostScript driver files required to create PDF files, PSCRIPT5.DLL, PS5UI.DLL, and pscript.ntf, are already installed, typically in C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_1a216484\Amd64 on a 64-bit Windows 7 system. Your users must use the version of these files that is appropriate to the operating system where the PDF file is created. They should copy the files to the dirname\drivers directory.

You must also deploy the related files that are installed in Appeon\Shared\PowerBuilder\drivers. These files can be copied to or installed on users' computers. They must be located in this directory structure:

dirname\pbdwe170.dll
dirname\drivers

PostScript printer profile

Each user's computer must have a PostScript printer profile called Appeon DataWindow PS. Users can add the profile manually using the Windows Add Printer wizard in one of the following ways:

  • By selecting a printer with PS in its name (such as "Apple Color LW 12/660 PS") from the list of printers on the Install Printer Software page of the wizard, and changing the printer name to "Appeon DataWindow PS" on the Name Your Printer page.

  • (For 32-bit Windows only) By clicking the Have Disk button on the Install Printer Software page of the wizard, browsing to the Adist5.inf file (installed with PowerBuilder in the Shared\Appeon\drivers directory) or to another PostScript driver file, and on the Name Your Printer page, changing the printer name to "Appeon DataWindow PS".

For how to set properties for the distiller method, see the section called “Saving as PDF using the distill method with Ghostscript” in Users Guide.

Using the PDFlib generator

No drivers need to be deployed in order to use the PDFlib generator to save DataWindow data as a PDF file.

The DLL file for PDFlib (PBPDF170.dll) is automatically packaged into the PowerBuilder application executable without requiring the developer to make any configuration or selection during the building process.

By using the PDFlib generator, the DataWindow is first saved to EMF. Depending on the size of the DataWindow and also the specified page size, there may be multiple EMFs. For example, if a DataWindow has 8 columns that cannot fit in a page, maybe the first 3 columns are in page #1, and the other 5 columns in page #2; if the DataWindow has more data, and the data will go to page #3 (and page #4), page #5 (and page #6), and so on. The EMF files will then be converted and combined into one PDF. The EMF files are memory-based and will be deleted from memory after the successful generation of the PDF file.

Packaging custom fonts

If your DataWindow objects uses many custom fonts, and these custom fonts are not supported well by the operating system and Adobe Reader, you can consider packaging these custom fonts with your application. Note that using custom fonts will increase the generated PDF file size.

By default, these custom fonts are not packaged with the application. To package custom fonts for PDF generation with the application:

  • In the PowerBuilder IDE, add the following to the [Data Window] section of your pb.ini that PowerBuilder uses for initialization.

    [Data Window]
    NativePDF_IncludeCustomFont=1

    The default location of pb.ini for PowerBuilder 2017 R3 on Windows 7/8.1/10 is C:\Users\<username>\AppData\Local\Appeon\PowerBuilder 17.0.

  • For a deployed application, create a text file named pb.ini with the text above and deploy it with your application executable.

Setting PDFLib as the default PDF method

In order to help PowerBuilder developers conveniently use the PDFLib generation method (NativePDF!), you can set this method as the default PDF method (instead of the distill method) when you select Save Rows As from the File menu in the DataWindow painter and select PDF as the file type, or when you use the SaveAs method with PDF! as the file type.

To set the NativePDF! method as the default PDF method:

  • In the PowerBuilder IDE, add the following to the [Data Window] section of your pb.ini that PowerBuilder uses for initialization.

    [Data Window]
    NativePDF_Valid=1

    The default value is 0, which means the method selected in the DataWindow Properties window is used or the distill method is used when no method is selected in the DataWindow Properties window. When set to 1, the NativePDF! method is used for all DataWindows, ignoring the setting in the DataWindow Properties window, this reduces the workload of manually changing the scripts or setting the PDF method in the Properties window for the DataWindows one by one.

  • For a deployed application, create a text file named pb.ini with the text above and deploy it with your application executable.

For how to set properties for the PDFLib method, see the section called “Saving as PDF using PDFlib” in Users Guide.

Using the Apache FO processor

If your application uses the Apache processor to save as PDF or XSL-FO, you must deploy the fop-0.20.4 directory and the Java Runtime Environment (JRE) with your application.

They must be deployed in the same directory as the PowerBuilder runtime files. For example, if you deploy your application and pbvm170.dll and the other PowerBuilder runtime files in a directory called MyApplication, the Apache processor must be deployed in MyApplication/fop-0.20.4, and the JRE in MyApplication/jre. However, you do not need to place a copy of the JRE in this location if the full JDK is installed on the target computer and is in the classpath.

The following JAR files must be in the user's classpath:

fop-0.20.4\build\fop.jar
fop-0.20.4\lib\batik.jar
fop-0.20.4\lib\xalan-2.3.1.jar
fop-0.20.4\lib\xercesImpl-2.1.0.jar
fop-0.20.4\lib\xml-apis.jar
fop-0.20.4\lib\avalon-framework-cvs-20020315.jar

For more information about the JRE, see Java support.

On Windows DBCS platforms, you also need to deploy a file that supports DBCS characters to the Windows font directory on the target computer, for example, C:\WINDOWS\fonts. For more information about configuring fonts, see the Apache Web site at http://xmlgraphics.apache.org/fop/1.1/fonts.html.

For how to set properties for the XSL-FO method, see the section called “Saving as PDF using XSL-FO” in Users Guide.