using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HiQPdf;
namespace EnVisage.Code
{
public class PDFExporter
{
#region fields and properties
private HtmlToPdf htmlToPdf;
public int BrowserWidth
{
get
{
return htmlToPdf.BrowserWidth;
}
set
{
htmlToPdf.BrowserWidth = value;
}
}
#endregion
#region public methods
///
/// Public constructor. Initializes PDF Converter
///
public PDFExporter()
{
htmlToPdf = new HtmlToPdf();
htmlToPdf.SerialNumber = AppSettingsManager.HiQPdfSerialNumber;
htmlToPdf.BrowserWidth = AppSettingsManager.HiQPdfBrowserWidth;
htmlToPdf.Document.PageSize = PdfPageSize.A4;
htmlToPdf.Document.PageOrientation = PdfPageOrientation.Landscape;
htmlToPdf.Document.PdfStandard = PdfStandard.Pdf;
htmlToPdf.Document.Margins = new PdfMargins(5);
htmlToPdf.Document.FontEmbedding = true;
}
///
/// Waits delaySeconds seconds and then parses the page at url authorized by given cookies collection and returns a byte array to be saved to file
///
public byte[] ExportPage(string url, int delaySeconds, bool usePrintStylesheet, HttpCookieCollection cookies)
{
byte[] pdfBuffer = null;
htmlToPdf.TriggerMode = ConversionTriggerMode.WaitTime;
htmlToPdf.WaitBeforeConvert = delaySeconds;
if (usePrintStylesheet)
htmlToPdf.MediaType = "print";
foreach (string key in cookies.Keys)
{
htmlToPdf.HttpCookies.AddCookie(cookies[key].Name, cookies[key].Value);
}
pdfBuffer = htmlToPdf.ConvertUrlToMemory(url);
return pdfBuffer;
}
#endregion
}
}