I am using aspose-words-17.3.0-jdk16.jar to create a pdf file. When I set the margins to .5 the images are off center. I have tried with aspose word and with aspose pdf and I get the same results. Please see below. test1.pdf shows result with 0.5 margins. result-wanted.pdf was created with default margins. What can I do to fix this issue?
Margin created with aspose.pdf
public void convert() {
Document document = new Document(new FileInputStream("aspose.html"));
DocumentBuilder builder = new DocumentBuilder(document);
PdfSaveOptions opts = new PdfSaveOptions();
opts.setExportDocumentStructure(true);
opts.getOutlineOptions().setDefaultBookmarksOutlineLevel(1);
document.updatePageLayout();
document.save("test.pdf", opts);
com.aspose.pdf.Document pdfdoc = new com.aspose.pdf.Document("test.pdf");
pdfdoc.getPageInfo().setMargin(new MarginInfo(
ConvertUtil.inchToPoint(0.5),
ConvertUtil.inchToPoint(0.5),
ConvertUtil.inchToPoint(0.5),
ConvertUtil.inchToPoint(0.5)));
}
pdfdoc.setDisplayDocTitle(true);
pdfdoc.save("test.pdf");
}
Margin created with aspose.words
public void convert() {
Document document = new Document(new FileInputStream("aspose.html"));
DocumentBuilder builder = new DocumentBuilder(document);
PdfSaveOptions opts = new PdfSaveOptions();
opts.setExportDocumentStructure(true);
opts.getOutlineOptions().setDefaultBookmarksOutlineLevel(1);
for (Section section : document.getSections()) {
section.getPageSetup().setTopMargin(ConvertUtil.inchToPoint(0.5));
section.getPageSetup().setRightMargin(ConvertUtil.inchToPoint(0.5));
section.getPageSetup().setBottomMargin(ConvertUtil.inchToPoint(0.5));
section.getPageSetup().setLeftMargin(ConvertUtil.inchToPoint(0.5));
}
document.updatePageLayout();
document.save("test.pdf", opts);
}