Click or drag to resize

Getting Started with ExpertPdf Html To Pdf Converter

The converter API is fully documented in this developers guide. In order to use the converter library you have include the ExpertPdf.HtmlToPdf namespace in your application.

The main classes in this namespace are the PdfConverter class and the ImgConverter class which expose the methods you can use to render a PDF document or an image from a URL or a HTML string. Below is a brief description of the main classes and properties of the converter.

Sample Code

Sample code that performs basic HTML to PDF conversion:

PdfConverter pdfConverter = new PdfConverter();

pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfConverter.PdfDocumentOptions.ShowHeader = true;
pdfConverter.PdfDocumentOptions.ShowFooter = true;
pdfConverter.PdfDocumentOptions.LeftMargin = 5;
pdfConverter.PdfDocumentOptions.RightMargin = 5;
pdfConverter.PdfDocumentOptions.TopMargin = 5;
pdfConverter.PdfDocumentOptions.BottomMargin = 5;
pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;

pdfConverter.PdfDocumentOptions.ShowHeader = false;

pdfConverter.PdfFooterOptions.FooterText = "Sample footer: " + TxtURL.Text + ". You can change color, font and other options";
pdfConverter.PdfFooterOptions.FooterTextColor = Color.Blue;
pdfConverter.PdfFooterOptions.DrawFooterLine = false;
pdfConverter.PdfFooterOptions.PageNumberText = "Page";
pdfConverter.PdfFooterOptions.ShowPageNumber = true;

//pdfConverter.LicenseKey = "put your serial number here";
byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(url);

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.AddHeader("Content-Type", "binary/octet-stream");
response.AddHeader("Content-Disposition", "attachment; filename=" + downloadName + "; size=" + downloadBytes.Length.ToString());
See Also