We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert HTML to PDF using Java | Aspose.PDF for Java | Specify Landscape orientation

Is there a way to set page orientation as Landscape PRIOR to performing the HTML to PDF conversion.

I understand you can manipulated pages after the conversion has taken place. But, the HTML to PDF conversion defaults to portrait and cuts off any page content that does not fit. So changing a post-conversion page to landscape will not contain the already cut off page content.

Searching through the forums we have found that this issue has been opened before and that internal tracking numbers were assigned:


You can please specify the Page Width/Height and other properties in HtmlLoadOptions Class in order to generate a PDF from HTML with desired orientation. Please check the below sample code snippet:

HtmlLoadOptions htmloptions = new HtmlLoadOptions(dataDir);

// set MarginInfo for margin details
htmloptions.getPageInfo().setWidth(700); // in points 72pt = 1 inch
htmloptions.getPageInfo().setHeight(1250); // in points 72pt = 1 inch
htmloptions.getPageInfo().setMargin(new MarginInfo(10,150,10,10));

// Load HTML file
Document doc = new Document(dataDir + "input.html", htmloptions);