Show Word DOCX Titles as Bookmarks inside Converted PDF using Java | Set Headings Outline Levels

Hello,
in the old way, i was using this Word option (see word_create_bookmarks_from_titles.jpg)
word_create_bookmarks_from_titles.jpg (65.8 KB)

and it was generating this kind of PDF (see expected_pdf_bookmarks.jpg)
expected_pdf_bookmarks.jpg (161.2 KB)

but i cant’ succeed to make it work with Aspose lib. Is it possible ?
I tried to play with the following commented options

Document doc = new Document(inputPath);

PdfSaveOptions options = new PdfSaveOptions();
//options.getOutlineOptions().setDefaultBookmarksOutlineLevel(1);
//options.setExportDocumentStructure(true);
//options.setHeaderFooterBookmarksExportMode(HeaderFooterBookmarksExportMode.FIRST);

doc.save(outputPath, options);

but i can’t get my document titles as PDF bookmarks (see aspose_pdf.jpg)
aspose_pdf.jpg (246.7 KB)

Thank you
Michel

@mcharpentier,

Please ZIP and attach the following resources here for testing:

  • Your simplified source Word document
  • Aspose.Words for Java 21.4 generated output PDF file showing the undesired behavior
  • Your expected PDF file showing the desired output. You can create this document manually by using MS Word.

As soon as you get these pieces of information ready, we will start further investigation into your scenario and provide you code to achieve the same output in PDF by using Aspose.Words.

headings_as_bookmarks.zip (83.0 KB)

with this simplified doc, i cannot generate any PDF bookmarks based on my existing DOC headings/titles.

In Microsoft API, here is the option during PDF export :

.WdExportCreateBookmarks.wdExportCreateHeadingBookmarks

Example :

wdDoc.ExportAsFixedFormat(OutputFileName:=strOutName, ExportFormat:=Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint, Range:=Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument, From:=1, To:=1, Item:=Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateHeadingBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False)

@mcharpentier,

Please check different options of OutlineOptions Class and use the following code to get the desired PDF output:

Document doc = new Document("C:\\Temp\\headings_as_bookmarks\\source.docx");
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.getOutlineOptions().setHeadingsOutlineLevels(9);
pdfSaveOptions.getOutlineOptions().setCreateOutlinesForHeadingsInTables(true);
pdfSaveOptions.getOutlineOptions().setExpandedOutlineLevels(9);
doc.save("c:\\temp\\headings_as_bookmarks\\awjava-21.4.pdf", pdfSaveOptions);

Perfect !
This is exactly what i was looking for !
Thank you for fast and useful answer
We can close the topic