Converting HTML to PDF using EvoPdf
We have been using ABCpdf to generate PDFs on the fly of the page currently being browsed. It has given us years of service, but now with the new version of our site I have had to find an alternative solution as my page body gets styled out of sight and then moved into position using jquery to change the left:-2000px to left:0px;. ABCpdf ignores javascript so I am getting a lovely half generated page in the PDF output.
The only product I have found out there on the interwebs that understands javascript is EvoPdf. I have downloaded the zip file of 52mb done the install – which by the way could not be easier: add reference to dll, copy another, and then call the following method:
private void ConvertURLToPDF()
{
string urlToConvert = Request["url"];
PdfConverter pdfConverter = new PdfConverter();
pdfConverter.LicenseKey = "xxxxxxx";
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait;
pdfConverter.PdfDocumentOptions.LiveUrlsEnabled = true;
pdfConverter.JavaScriptEnabled = true; //the important bit – waits for javascript
pdfConverter.ConversionDelay = 10;
pdfConverter.InterruptSlowJavaScript = false;
pdfConverter.PdfDocumentOptions.JpegCompressionEnabled = true;
pdfConverter.PdfDocumentOptions.FitWidth = true;
byte[] pdfBytes = pdfConverter.GetPdfBytesFromUrl(urlToConvert);
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Type", "application/pdf");
response.AddHeader("Content-Disposition", String.Format("attachment; filename=Output.pdf; size={0}", pdfBytes.Length.ToString()));
response.BinaryWrite(pdfBytes);
response.End();
}
The license is a little hefty, but you can trail the full version to see if it suits your needs before dusting off the credit card – the only thing is the outputed PDF will have a watermark over it until you get a license.

Developer by day, husband and dad by night and dreaming about sport inbetween.