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:
Configure the .NET Framework to run under the SYSTEM account and expose printer settings to the SYSTEM account as described in “Server-side printing”.
Make sure that the Sybase DataWindow PS profile is exposed to the SYSTEM account as described next.
On Windows 2003 Server, configure the server so that the PostScript printer driver can be installed. See “Installing a printer on Windows 2003 Server”.
Create a folder on the server in which to save the PDF files and set its permissions so that the ASP.NET application process has write access to it.
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.5\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.
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:
Select Run from the Windows Start menu.
In the Open box, type gpedit.msc
and
click OK.
In the Group Policy console, expand Computer Configuration, Administrative Templates, and Printers.
Disable “Disallow Installation of Printers Using Kernel-Mode Drivers.”
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.