Page 1 of 1

Save HTML page to PDF

Posted: Thu Aug 29, 2013 8:48 pm
by manas_p
Problem:
WPF .Net Framework 3.5 Project using Visual Studio 2010
The Webpage was being displayed using a System.Windows.Forms.WebBrowser control
Needed to Print the Webpage to Save as PDF file.

Solution:
// Help/ideas from bullzip forums were used to arrive at this solution. Thank you
//I just got this working and posting it and the code is not production ready. Remember to add your own checks/validations/exception handling.

Added reference to the DLL in C:\Program Files\Common Files\Bullzip\PDF Printer\API\Microsoft.NET\Framework folder (I copied the v2 DLL to Project's External Lib folder)

PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue(); // Needs using System.Printing;

var pdfSettings = new PdfSettings(); //Needs using Bullzip.PdfWriter;

pdfSettings.PrinterName = "Bullzip PDF Printer"; //You can verify that default Printer is the PDF Printer before you do all from from the defaultPrintQueue
pdfSettings.SetValue("SavePath", "C:\\Users\\manas_p\\Documents\\");
pdfSettings.SetValue("Output", "C:\\Users\\manas_p\\Documents\\test.pdf");
pdfSettings.SetValue("FileName", "test.pdf"); // May be redundant

pdfSettings.SetValue("ShowSaveAS", "never");
pdfSettings.SetValue("ShowSettings", "never");
pdfSettings.SetValue("ShowProgress", "no");
pdfSettings.SetValue("ShowProgressFinished", "no");
pdfSettings.SetValue("ShowPDF", "no");
pdfSettings.SetValue("ConfirmOverwrite", "no");
pdfSettings.SetValue("RememberLastFileName", "no");


pdfSettings.SetValue("Linearize", "yes");
pdfSettings.SetValue("RememberLastFolderName", "no");
pdfSettings.SetValue("RememberLastFileName", "no");
pdfSettings.WriteSettings(true);

formWebBrowser.PrintBrowser(); // This sends the page to the default Printer

Manas