Click or drag to resize
Pdf Library for .NET

Setting Pdf Page Properties with Html to Pdf Converter for .NET

Select.Pdf Html to Pdf Converter can be used to control how the pdf pages look like when the pdf document is generated from the conversion of a web page. The most important properties of a pdf page are:

  • Page size

  • Page orientation

  • Page margins

Page size

SelectPdf supports the following standard page sizes:

  • A0 to A10

  • B0 to B5

  • ArchA to ArchE

  • Letter, HalfLetter, Letter11x17, Note, Flsa, Ledger

To set the page size for the html to pdf conversion, the PdfPageSize property of the HtmlToPdfOptions object needs to be used. Pages with custom page sizes can also be created using Select.Pdf. A custom page size can be set using the PdfPageCustomSize property.

Page orientation

SelectPdf supports the following page orientations:

  • Portrait

  • Landscape

To set the page orientation for the html to pdf conversion, the PdfPageOrientation property of the HtmlToPdfOptions object needs to be used.

Page margins

Page margins can be set using MarginLeft, MarginRight, MarginTop, MarginBottom properties of the HtmlToPdfOptions object.

Sample Code

This sample code shows how to use Select.Pdf html to pdf converter to convert an url to pdf, also setting page size, orientation and margins.

// instantiate a html to pdf converter object
HtmlToPdf converter = new HtmlToPdf();

// set converter options
converter.Options.PdfPageSize = PdfPageSize.A4;
converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
converter.Options.MarginLeft = 10;
converter.Options.MarginRight = 10;
converter.Options.MarginTop = 20;
converter.Options.MarginBottom = 20;

// create a new pdf document converting an url
PdfDocument doc = converter.ConvertUrl(url);

// save pdf document
doc.Save(Response, false, "Sample.pdf");

// close pdf document
doc.Close();
See Also