【问题标题】:Table of contents not added in pdf format using ASPOSE WORD , java未使用 ASPOSE WORD 、 java 以 pdf 格式添加的目录
【发布时间】:2015-04-16 22:55:41
【问题描述】:
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。我已在此链接中附加了所需的文件: enter link description here

【问题讨论】:

    标签: java pdf ms-word aspose aspose.words


    【解决方案1】:

    我注意到您的标题在文档标题中。请将这些移至文档正文。

    默认情况下,这些标题不会保存在 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 工作,担任开发人员宣传员。

    【讨论】:

    • 谢谢,您的代码有效,但我明确希望我的标题在 Header 中,因为我希望它们出现在以下所有页面中。标题中的标题是否有可能同时出现在 pdf 和 docx 中的 TOC 中。
    • 抱歉,标题不在侧书签中。这种行为在 MS Word 和 Aspose 中是相同的。书签指向一个位置,但如果它出现在页眉(每一页)中,那就不是一个位置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多