Determine page size when converting HTML to PDF

How would we determine or force a page size when converting multiple HTML pages to PDF?

Hi John,

Thanks for contacting support.

In order to set the page dimensions while converting HTML to PDF, please try using the following code snippet.

[C#]

// load source HTML
Document doc = new Document("c:/pdftest/Research+Report.html", new HtmlLoadOptions());

// set destination page size
doc.Pages[1].SetPageSize(400, 400);

// save resultant output as PDF
doc.Save("c:/pdftest/Research+Report.pdf");

Is there anyway to force the PDF conversion to abide by the @page { size:xxx } rule specified in the HTML?


This would be far more flexible especially in mixed orientation scenarios (where some pages are landscape and others portrait) and even more so where each page may contain content that spans multiple pages. As is, there’s no way to know which page is which…so we’re left to blindly guess which pages should have which dimensions.

Hi Greg,


Thanks for your inquiry. As stated in your other related post, currently Aspose.Pdf does not honor page orientation in HTML to PDF conversion. We have logged a ticket PDFNET-41554 for further investigation and rectification. We will keep you updated about the issue resolution progress.

Best Regards,