简体   繁体   中英

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

}

Here the Table of contents is seen in .docx in a linux OS but not seen in Windows. TOC in pdf format is not seen in both OS.I have attached the required documents in this link: enter link description here

I noted that your headings are in the document header. Please move these to the document body.

These headings are not saved in the PDF by default. You need to specify these in an instance of 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);

标题位于文档标题中

I work for Aspose as Developer Evangelist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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