繁体   English   中英

未使用ASPOSE WORD,java以pdf格式添加目录

[英]Table of contents not added in pdf format using ASPOSE WORD , java

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没有在这两个OS.I看到这个链接附上所需文件: 在此输入链接的描述

我注意到您的标题在文档标题中。 请将它们移到文档正文中。

这些标题默认情况下不保存在PDF中。 您需要在PdfSaveOptions实例中指定它们。

// 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);

标题位于文档标题中

我为Aspose工作,担任开发人员推广人员。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM