未使用ASPOSE WORD、java以pdf格式添加的目录
这里的目录可以在linux操作系统的.docx中看到,但在Windows中看不到。这两个操作系统中都没有pdf格式的TOC。我已在此链接中附上了所需的文档:未使用ASPOSE WORD、java以pdf格式添加的目录,java,pdf,ms-word,aspose,aspose.words,Java,Pdf,Ms Word,Aspose,Aspose.words,这里的目录可以在linux操作系统的.docx中看到,但在Windows中看不到。这两个操作系统中都没有pdf格式的TOC。我已在此链接中附上了所需的文档: 我注意到您的标题在文档标题中。请将这些移动到文档正文 默认情况下,这些标题不会保存在PDF中。您需要在PdfSaveOptions的实例中指定这些选项 def gDataDir; def index() { gDataDir = "/home/sithapa/gitProject/aposeWord/documents/basic
我注意到您的标题在文档标题中。请将这些移动到文档正文 默认情况下,这些标题不会保存在PDF中。您需要在PdfSaveOptions的实例中指定这些选项
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");
}
我作为开发人员传道者为Aspose工作。谢谢,您的代码可以工作,但我明确希望我的标题出现在标题中,因为我希望它们出现在以下所有页面中。标题中的标题是否可能同时以pdf和docx格式出现在TOC中。对不起,标题不在侧边书签中。这种行为在MS Word和Aspose中都是相同的。书签指向一个位置,但如果它位于页眉(每页),则不是一个位置。
// Set 2 levels of headings to appear in PDF
PdfSaveOptions so = new PdfSaveOptions();
so.getOutlineOptions().setHeadingsOutlineLevels(2);
// Specify the save options as parameter
document.save("output.pdf", so);