测试.docx (18.8 KB)
如测试文档所示,需要通过aspose 生成如上所示的文档格式,对于奇数页的页边距和偶数页的页边距如何处理?奇数页左宽右窄,偶数页左窄右宽。
@wangyan 在这种情况下使用 Margins.Mirrored:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Enable different headers and footers for odd and even pages
builder.getPageSetup().setDifferentFirstPageHeaderFooter(false);
builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
// Create the headers for odd pages
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.write("Header for Odd Pages");
// Create the headers for even pages
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.write("Header for Even Pages");
// Add content to the document
builder.moveToSection(0);
for (int i = 1; i <= 5; i++) {
builder.insertBreak(BreakType.PAGE_BREAK);
builder.write("Page " + i);
}
// Set mirrored margins
PageSetup pageSetup = doc.getSections().get(0).getPageSetup();
pageSetup.setMargins(Margins.MIRRORED);
pageSetup.setLeftMargin(100);
doc.save("output.docx");
请检查: