Saving data in an external file

While previewing, you can save the data retrieved in an external file. Note that the data and headers (if specified) are saved. Information in the footer or summary bands is not saved unless you are saving as PDF or as a PSR file.

To save the data in a DataWindow object in an external file:

  1. Select File>Save Rows As from the menu bar.

    The Save As dialog box displays.

  2. Choose a format for the file from the Save As Type drop-down list.

    If you want the column headers saved in the file, select a file format that includes headers (such as Excel With Headers). When you select a with headers format, the names of the database columns (not the column labels) are also saved in the file.

    When you choose a format, PowerBuilder supplies the appropriate file extension.

    For TEXT, CSV, SQL, HTML, and DIF formats, select an encoding for the file.

    You can select ANSI/DBCS, Unicode LE (Little-Endian), Unicode BE (Big-Endian), or UTF8.

  3. Name the file and click Save.

    PowerBuilder saves all displayed rows in the file; all columns in the displayed rows are saved. Filtered rows are not saved.

    The rest of this section provides more information about saving data in PDF, HTML, and PSR formats.

    For more information about saving data as XML, see Exporting and Importing XML Data.

Saving the data as PDF

PowerBuilder provides three ways to save a DataWindow object or DataStore in Portable Document Format (PDF).

Using Ghostscript

By default, when you select File>Save Rows As and select PDF as the file type, the data is printed to a PostScript file and automatically distilled to PDF using Ghostscript. This option provides a robust solution that can save most types of DataWindow objects.

Installing Ghostscript and PostScript drivers

For licensing reasons, Ghostscript and the PostScript drivers required to use the distill method are not installed with PowerBuilder. You (and your users) must download and install them before you can use this technique. See System requirements for the distill method.

Using PDFlib

Starting from PowerBuilder 2017, an alternative method is provided to directly print data to PDF without needing to install any third-party tool or driver or make any configuration. This method relies on a light-weight software called PDFlib which is automatically installed with PowerBuilder at no cost. And the DLL file for PDFlib (PBPDF190.dll) is automatically packaged into the PowerBuilder application executable as well without requiring the developer to make any configuration or selection during the building process.

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. For more, see the section called “Using the PDFlib generator” in Application Techniques.

Using XSL-FO and Java printing

Building on the ability to save data as XML, PowerBuilder can also save the DataWindow object's data and presentation to PDF by generating XSL Formatting Objects (XSL-FO). This option provides a platform-independent solution by rendering the DataWindow using a Java process rather than the Microsoft GDI. It also offers the possibility of customizing the PDF file at the XSL-FO stage. Saving as PDF using XSL-FO is particularly useful if you want to print DataWindow objects on a UNIX operating system by using Java printing. The Ghostscript method and the PDFlib method are not supported on UNIX.

The XSL (Extensible Stylesheet Language) W3C Recommendation has two parts, XSLT and XSL-FO. XSLT provides the transformation typically used to present XML documents as HTML in a browser. XSL-FO provides extensive formatting capabilities that are not dependent on the output format.

For more information about XSL, see the latest version of the Extensible Stylesheet Language (XSL) at http://www.w3.org/TR/xsl/.

Limitations

The Ghostscript method currently does not support OLE and RichText DataWindow objects. The PDFlib method currently does not support OLE DataWindow objects. The XSL-FO method currently does not support OLE, RichText, graph, and composite DataWindow objects.

The PDFlib method currently does not support the DataWindow object background.property.

Saving as PDF using the distill method with Ghostscript

If you want to save to PDF using the distill method, you do not need to change any properties. The distill method is used by default 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.

PowerBuilder uses a PostScript printer driver specifically designed for distilling purposes to configure the PDF output. You can choose to use a different PostScript printer driver if you want to customize your PostScript settings for generating PDF. For more, see the section called “Using the Ghostscript distiller” in Application Techniques.

In the DataWindow painter

To use a custom PostScript printer driver, you must set some properties.

To save customized distilled PDF output in the DataWindow painter

  1. Select the Data Export tab in the Properties view for the DataWindow object.

  2. Select PDF from the Format to Configure drop-down list, select Distill! from the Method drop-down list, and select the Distill Custom PostScript check box.

  3. Select the Print Specifications tab and specify the name of the printer whose settings you want to use in the Printer Name box.

  4. Save the DataWindow object, then select File>Save Rows As, select PDF as the Save As Type, specify a file name, and click Save.

In a script

The properties you set in the DataWindow painter are saved with the DataWindow object and are used by default when your application runs, but for more control, specify the properties in a script before saving the DataWindow object. To specify a custom printer driver in a script, set the Export.PDF.Distill.CustomPostScript property to Yes and specify a printer with the DataWindow.Printer property:

int li_ret

dw_1.Object.DataWindow.Export.PDF.Method = Distill!
dw_1.Object.DataWindow.Printer = "\\prntsrvr\pr-6"
dw_1.Object.DataWindow.Export.PDF.Distill.CustomPostScript = "Yes"

li_ret = dw_1.SaveAs("custom.PDF", PDF!, true)

See also

the section called “Export.PDF.Method” in DataWindow Reference

the section called “Printer” in DataWindow Reference

the section called “Export.PDF.Distill.CustomPostScript” in DataWindow Reference

System requirements for the distill method

Users must have administrative privileges to create a PDF file.

To support saving as PDF using Ghostscript, you must download and install Ghostscript files on your system as described in the chapter on deploying applications and components in Application Techniques. You also need to install PostScript driver files.

If you have installed a PostScript printer on your computer, 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. You must use the version of these files that is appropriate to the operating system where the PDF file is created. You should copy the files to the %Appeon%\Shared\PowerBuilder\drivers directory.

If you have never installed a PostScript printer, use the Printers and Faxes option in the Windows control panel to install a generic PostScript printer. If the Pscript5.dll has never been installed, you may be prompted to insert the Windows install CD.

Other related files are installed in %Appeon%\Shared\PowerBuilder\drivers.

When you deploy applications that use the ability to save as PDF with the distill method, you must make sure your users have installed Ghostscript and have access to the drivers directory.

See the section called “Using the Ghostscript distiller” in Application Techniques for more information about redistributing these files.

Saving as PDF using PDFlib

If you want to save to PDF using PDFlib, you must set one or more properties before saving.

In the DataWindow painter

In the DataWindow painter, you set PDF export properties on the Data Export page in the Properties view.

To save PDF output using PDFlib in the DataWindow painter

  1. Select the Data Export tab in the Properties view for the DataWindow object.

  2. Select PDF from the Format to Configure list and select NativePDF! from the Method list.

  3. Select a standard from the PDF Conformance list.

  4. Select the paper size and orientation in two methods:

    • method 1: select the "Use These Two Settings in Print Specifications" check box, so it uses the paper size and orientation settings in the Print Specification page;

    • method 2: keep the "Use These Two Settings in Print Specifications" check box unselected, and select from the Paper Size list and the Orientation list in the current Data Export page;


  5. Save the DataWindow object, then select File>Save Rows As, select PDF as the Save As Type, specify a file name, and click Save.

In a script

In a script, set the Export.PDF.Method property to NativePDF! before saving the DataWindow object as PDF using the SaveAs method with the SaveAsType PDF!.

There are two methods to set the orientation mode and the paper size.

Method 1: set the Export.PDF.NativePDF.UsePrintSpec property to true, and then set the Print.Orientation and Print.Paper.Size properties. For example, to print the PDF file in the landscape mode, set the Print.Orientation property to 1, and to print the file size to Letter, set the Print.Paper.Size property to 1:

dw_1.Object.DataWindow.Export.PDF.NativePDF.UsePrintSpec = 'Yes'
dw_1.Object.DataWindow.Export.PDF.Method = NativePDF!
dw_1.Object.DataWindow.Export.PDF.NativePDF.PDFStandard = 1 //PDF/A-1a
dw_1.Object.DataWindow.Print.Orientation = 1 //Landscape!
dw_1.Object.DataWindow.Print.Paper.Size = 1 //1 – Letter 8 1/2 x 11 in

Method 2: set the Export.PDF.NativePDF.UsePrintSpec property to false, and then set the Export.PDF.NativePDF.CustomOrientation and Export.PDF.NativePDF.CustomSize properties. For example, to print the PDF file in the portrait mode, set the Export.PDF.NativePDF.CustomOrientation property to 2 and to print the file size to A4, set the Export.PDF.NativePDF.CustomSize property to 4:

dw_1.Modify ("DataWindow.Export.PDF.NativePDF.UsePrintSpec = No")
dw_1.Modify ("DataWindow.Export.PDF.Method = NativePDF!")
dw_1.Modify ("DataWindow.Export.PDF.NativePDF.PDFStandard = 1")
dw_1.Modify ("DataWindow.Export.PDF.NativePDF.CustomOrientation = 2")
dw_1.Modify ("DataWindow.Export.PDF.NativePDF.CustomSize = 4")

See also

See the section called “Using the PDFlib generator” in Application Techniques for how to package the custom fonts, and set PDFLib as the default PDF method.

the section called “Export.PDF.Method” in DataWindow Reference

the section called “Export.PDF.NativePDF.CustomOrientation” in DataWindow Reference

the section called “Export.PDF.NativePDF.CustomSize” in DataWindow Reference

the section called “Export.PDF.NativePDF.ImageFormat” in DataWindow Reference

the section called “Export.PDF.NativePDF.PDFStandard” in DataWindow Reference

the section called “Export.PDF.NativePDF.UsePrintSpec” in DataWindow Reference

Saving as PDF using XSL-FO

If you want to save to PDF using XSL-FO, you must set one or more properties before saving.

In the DataWindow painter

In the DataWindow painter, you set PDF export properties on the Data Export page in the Properties view.

To save PDF output using XSL-FO in the DataWindow painter

  1. Select the Data Export tab in the Properties view for the DataWindow object.

  2. Select PDF from the Format to Configure drop-down list and select XSLFOP! from the Method drop-down list.

  3. (Optional) If you want simultaneously to send the output directly to a printer using the Java printing option of the Apache FOP processor, select the Print Using XSLFOP check box.

  4. Save the DataWindow object, then select File>Save Rows As, select PDF as the Save As Type, specify a file name, and click Save.

    PowerBuilder saves the data in the DataWindow object to the file you specified. If you selected the Print Using XSLFOP check box, it also sends the PDF file to the default printer for your system.

In a script

In a script, set the Export.PDF.Method property to XSLFOP! before saving the DataWindow object as PDF using the SaveAs method with the SaveAsType PDF!. To send the PDF file directly to the default printer, set the Export.PDF.XSLFOP.Print property to 1 or Yes before saving:

int li_ret
dw_1.Modify("DataWindow.Export.PDF.Method = XSLFOP! ")
dw_1.Modify("DataWindow.Export.PDF.xslfop.print = '1'")
li_ret = dw_1.SaveAs("printed.pdf", PDF!, true)

See also

the section called “Export.PDF.Method” in DataWindow Reference

the section called “Export.PDF.XSLFOP.Print” in DataWindow Reference

Saving as XSL-FO

You can also save a DataWindow object as XSL-FO, then use the processor of your choice to convert the XSL-FO string to the format you want, applying your own customizations to the conversion. Processors such as the Apache XSL Formatting Objects processor (FOP) can convert XSL-FO documents into several output formats including PDF, PCL, and AWT.

In the DataWindow painter, select File>Save Rows As and select XSL-FO as the file type. In a script, you can use the SaveAs method with the SaveAsType XSLFO!.

For a DataWindow named dwemp, the following command lines show the FOP syntax for producing a PDF, a print preview rendered on screen (-awt), and printable output rendered and sent to a printer (-print):

Fop dwemp.fo dwemp.pdf
            Fop dwemp.fo -awt
            Fop dwemp.fo -print

For more information about using FOP, see the FOP page of the Apache XML Project Web site at http://xmlgraphics.apache.org/fop/.

System requirements for XSL-FO

The Apache XSL Formatting Objects processor (FOP) and the Oracle JDK are installed with PowerBuilder to support saving as XSL-FO, saving as PDF using XSL-FO, and Java printing. Both are installed in the %Appeon%\Shared\PowerBuilder directory.

When you deploy applications that use XSL-FO or Java printing, your users must have the FOP directory and the Java Runtime Environment installed on their computers. For more information, see Deploying Applications and Components in Application Techniques.

On Windows DBCS platforms, you also need to install a file that supports DBCS characters to the Windows font directory, for example, C:\WINDOWS\fonts. To use these fonts, the userconfig.xml file in the FOP conf directory must be modified to give the full path name of the files you use, for example:

<font metrics-file="C:\Program%20Files\Appeon\Shared\PowerBuilder\fop-0.20.4\conf\cyberbit.xml" kerning="yes" embed-file="C:\WINNT\Fonts\Cyberbit.ttf">

For more information about configuring fonts, see the Apache Web site at http://xmlgraphics.apache.org/fop/.

Saving the data in HTML Table format

HTML Table format is one of the formats in which you can choose to save data. When you save in HTML Table format, PowerBuilder saves a style sheet along with the data. If you use this format, you can open the saved file in a browser such as Internet Explorer. Once you have the file in HTML Table format, you can continue to enhance the file in HTML.

About the results

Some presentation styles translate better into HTML than others. The Tabular, Group, Freeform, Crosstab, and Grid presentation styles produce good results. The Composite, RichText, OLE 2.0, and Graph presentation styles and nested reports produce HTML tables based on the result set (data) only and not on the presentation style. DataWindows with overlapping controls in them might not produce the results you want.

To save a report as an HTML table

  1. Open a DataWindow object.

  2. Open the Preview view if it is not already open.

  3. Select File>Save Rows As from the menu bar.

  4. Choose the HTML Table format for the file from the Save As Type drop-down list.

  5. Name the file.

    PowerBuilder creates a file using the name you supplied and the extension htm.

  6. Open a Web browser.

  7. Use the browser's file open command to open the HTML file.

    For more information about working with DataWindow objects and HTML, see Using DataWindow Objects in DataWindow Programmers Guide.

Working with PSR files

A PSR file is a special file with the extension PSR created by PowerBuilder, InfoMaker, or DataWindow Designer.

Windows and PSR files

When PowerBuilder is installed, the PSR file type is registered with Windows.

A PSR file contains a DataWindow definition (source and object) as well as the data contained in the DataWindow object when the PSR file was created.

PSR file

About reports

A report is the same as a nonupdatable DataWindow object. For more information, see Reports versus DataWindow objects.

You can use a PSR file to save a complete report (report design and data). This can be especially important if you need to keep a snapshot of data taken against a database that changes frequently.

PowerBuilder creates a PSR file when you save data in the Powersoft report file format. See Saving data in an external file. PSR files are used primarily by InfoMaker, a reporting tool. When an InfoMaker user opens a PSR file, InfoMaker displays the report in the Report painter. If InfoMaker is not already running, opening a PSR file automatically starts InfoMaker.

To open a PSR file in PowerBuilder, open any DataWindow object, then select File>Open File and select the PSR file.