def gDataDir;
def index() {
gDataDir = "/home/sithapa/gitProject/aposeWord/documents/basics/";
topResultsTest();
}
def topResultsTest(){
Document main_src = new Document(gDataDir + "cover_page_toc.docx");
Document src3 = new Document(gDataDir + "our_testing_template.docx");
def String[] fields = ["Heading1","Subtitle1","Subtitle2"];
def Object[] values = ['This is a Heading','this is a subtitle1','\nthis is a subtitle2'];
src3.getMailMerge().execute(fields, values);
//Appending
main_src.appendDocument(src3, ImportFormatMode.KEEP_SOURCE_FORMATTING);
//Update the table of contents.
main_src.updateFields();
main_src.updatePageLayout();
main_src.save(gDataDir + "final_output.docx");
saveAsPDF(main_src)
}
def saveAsPDF(main_src){
//Document src = new Document(gDataDir + "final_output.docx");
//main_src.save(gDataDir + "simpleOpenSaveAsPDF_output.pdf", SaveFormat.PDF);
main_src.save(gDataDir + "Document.Doc2PdfSave Out.pdf");
}
此处的目录在 linux 操作系统中的 .docx 中可见,但在 Windows 中不可见。在两个操作系统中都没有看到 pdf 格式的 TOC。我已在此链接中附加了所需的文件: 在此处输入链接描述