Saving as PDF

If you want your application to save a DataWindow object in PDF format, the Web server (not the client) must satisfy the requirements for Ghostscript and PostScript drivers described in “Saving data in PDF format”.

You must also:

Exposing the Sybase DataWindow PS profile to the SYSTEM account

Saving as PDF requires a PostScript printer profile called Sybase DataWindow PS. This profile is added to your development computer automatically when you save a DataWindow’s rows to a PDF file in the DataWindow painter.

You can also add the profile manually using the Windows Add Printer wizard. In the wizard, click the Have Disk button and browse to the Adist5.inf file installed in the DataWindow .NET 2.0\drivers directory, or to another PostScript driver file. You can download PostScript driver files from several locations, including the Adobe Web site.

The Sybase DataWindow PS profile must be exposed to the SYSTEM account as described in “Exposing printer settings to the SYSTEM account”. If this profile does not display in the Devices, PrinterPorts, and Windows subkeys in HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion, copy the string values from the HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion key.

Installing a printer on Windows 2003 Server

On Windows 2003 Server, a default Group Policy disallows installation of printers that use kernel-mode drivers, and as a result the driver used by the Sybase DataWindow PS profile is not installed. Kernel-mode drivers have access to system-wide memory, and poorly written drivers can cause system failures. To allow installation of kernel-mode drivers, follow these steps:

  1. Select Run from the Windows Start menu.

  2. In the Open box, type gpedit.msc and click OK.

  3. In the Group Policy console, expand Computer Configuration, Administrative Templates, and Printers.

  4. Disable “Disallow Installation of Printers Using Kernel-Mode Drivers.”

Example

If you have completed these configuration steps, you can use code like the following to generate the PDF from the current DataWindow on the page and open the PDF file on the client computer.

Put the following C# code behind a LinkButton with a label such as “Printer-friendly version.” The code generates a unique file name in a subdirectory called pdfs of the Web application. The unique name is used as the filename argument of the SaveAs method.

String pdfFileName;
String pdfUrl;
String uniqueName;

uniqueName = System.Guid.NewGuid().ToString() + ".pdf";
pdfUrl = "pdfs/" +  uniqueName;
pdfFileName = Page.MapPath("") + "\\pdfs\\" + >   uniqueName;

dw.SaveAs(pdfFileName,
   Sybase.DataWindow.FileSaveAsType.Pdf);

HtmlGenericControl body;
body = FindControl("body") as HtmlGenericControl;
body.Attributes.Clear();

body.Attributes.Add("onLoad", "pdfWindow=window.open
   ('" + HttpUtility.UrlEncode(pdfUrl) + 
   "', 'pdf', 'dependent');pdfWindow.focus();");

body.Attributes.AddAttributes(new
   HtmlTextWriter(Response.Output));

You can find a sample application that uses a different technique on the Sybase CodeXchange Web site.