Hi Team, I have aspose.total license, currently developing java api for conversion of docx to pdf using aspose word, in this bookmarks are not getting added in pdf while converting.
code snippet to add book mark
PdfSaveOptions options = new PdfSaveOptions();
// Configure the outline (bookmarks) settings
BookmarksOutlineLevelCollection outlineLevels = options.getOutlineOptions().getBookmarksOutlineLevels();
outlineLevels.add("Bookmark 1", 1); // Level 1
outlineLevels.add("Bookmark 2", 2); // Level 2
outlineLevels.add("Bookmark 3", 3); // Level 3
options.setPageMode(PdfPageMode.USE_OUTLINES);
// Save the document as PDF
doc.save("output.pdf", options);
Also tried
options.setPageMode(PdfPageMode.USE_OUTLINES);
options.getOutlineOptions().setHeadingsOutlineLevels(3);
and also
options.getOutlineOptions().SetDefaultBookmarksOutlineLevels(2);
options.getOutlineOptions().SetExpandedOutlineLevels(2);
Please suggest better way to get this done.
@trivedi365
To ensure that bookmarks are added correctly during the conversion of a DOCX document to PDF using Aspose.Words for Java, you can follow these steps:
-
Set Up PdfSaveOptions: You need to configure the PdfSaveOptions
to include bookmarks. This can be done by setting the OutlineOptions
and specifying the levels of headings that should be included as bookmarks.
-
Export Header/Footer Bookmarks: If your bookmarks are located in headers or footers, make sure to set the HeaderFooterBookmarksExportMode
to include them.
Here’s an example code snippet that demonstrates how to set up the PdfSaveOptions
correctly:
import com.aspose.words.Document;
import com.aspose.words.PdfSaveOptions;
import com.aspose.words.HeaderFooterBookmarksExportMode;
public class ConvertDocxToPdf {
public static void main(String[] args) throws Exception {
// Load the document
Document doc = new Document("input.docx");
// Create PdfSaveOptions
PdfSaveOptions options = new PdfSaveOptions();
// Set the default bookmarks outline level
options.getOutlineOptions().setDefaultBookmarksOutlineLevel(1);
// Set the mode for exporting bookmarks from headers and footers
options.setHeaderFooterBookmarksExportMode(HeaderFooterBookmarksExportMode.FIRST);
// Save the document as PDF
doc.save("output.pdf", options);
}
}
Key Points:
- Default Bookmarks Outline Level: This specifies the level of headings that will be included as bookmarks in the PDF.
- Header/Footer Bookmarks Export Mode: This setting allows you to control how bookmarks in headers and footers are handled during the conversion.
Make sure that your document contains headings formatted correctly, as these will be used to create the bookmarks in the PDF. If you continue to experience issues, double-check the structure of your DOCX file to ensure that the headings are properly defined.
If you have any further questions or need additional assistance, feel free to ask!
@trivedi365 Could you please attach the problematic input and output documents here for testing? We will check the issue and provide you more information.
thanks, Issue is resolved with this set of options
1 Like