Hi Carol,
but the generated pdf is always portrait
I have tested the scenario and have managed to reproduce the problem that the generated PDF is portrait. For the sake of correction, I have logged a ticket PDFNET-42498 in our issue tracking system.
it only applies default margins 72 and 90 points
I have tested the scenario and have managed to reproduce the problem that generated PDF is not accepting the margin values. For the sake of correction, I have logged another ticket PDFNET-42499 in our issue tracking system.
We will further look into the details of these problem and will keep you updated within this forum thread on their status of resolution.
Moreover, you can also use setRotate method to change the page orientation. Please see following code snippet for reference
JAVA
HtmlLoadOptions htmloptions = new HtmlLoadOptions(dataDir);
htmloptions.getPageInfo().setWidth(PageSize.getA4().getWidth());
htmloptions.getPageInfo().setHeight(PageSize.getA4().getHeight());
OutputStream out = new java.io.ByteArrayOutputStream();
Document doc = new Document(dataDir + “input_test.htm”, htmloptions);
doc.getPages().get_Item(1).setRotate(Rotation.on270);
doc.processParagraphs();
doc.save(dataDir +“LandScapeOutput.pdf”);
You can use ContentsResizeParameters class to specify the parameters to be used to resize the pages(s) e.g. margins in percentage or units etc. The following code snippet shows how to resize the contents of some specific pages of the PDF file.
JAVA
HtmlLoadOptions htmloptions = new HtmlLoadOptions(dataDir);
OutputStream out = new java.io.ByteArrayOutputStream();
Document pdfDocument = new Document(dataDir + "input_test.htm", htmloptions);
//pdfDocument.getPages().get_Item(1).setRotate(Rotation.on270);
//pdfDocument.processParagraphs();
pdfDocument.save(out);
com.aspose.pdf.facades.PdfFileEditor pfe = new com.aspose.pdf.facades.PdfFileEditor();
IPdfFileEditor.ContentsResizeParameters params = PdfFileEditor.ContentsResizeParameters.pageResize(
com.aspose.pdf.PageSize.getA4().getHeight(), com.aspose.pdf.PageSize.getA4().getWidth());
for (int i = 1; i < pdfDocument.getPages().size() + 1; i++) {
params.setLeftMargin(IPdfFileEditor.ContentsResizeValue.units(200.0));
params.setRightMargin(IPdfFileEditor.ContentsResizeValue.units(200.0));
pfe.resizeContents(pdfDocument, new int[]{i}, params);
}
pdfDocument.save(dataDir+"output.pdf");
If you still face any issue or need further assistance, please feel free to contact us.
We are sorry for the inconvenience.
Best Regards,