Convert word to PDF with bookmarks navigation panel

Hi, I read in other posts that to convert word to PDF with a bookmarks navigation panel I need to set PdfSaveOptions.BookmarksOutlineLevel . How do I do this with the java cloud API, for example:

ApiClient apiClient = new ApiClient(/*clientId*/ "####-####-####-####-####", /*clientSecret*/ "##################", null);
WordsApi wordsApi = new WordsApi(apiClient);
byte[] requestDocument = Files.readAllBytes(Paths.get("Sample.docx").toAbsolutePath());
ConvertDocumentRequest convertRequest = new ConvertDocumentRequest(requestDocument, "pdf", null, null, null, null, null, null, null);
wordsApi.convertDocument(convertRequest);

Is it also possible to generate a TOC (table of contents) by updating the TOC field in word programatically via the cloud API prior to generating the PDF?

Thank you
Philip

@philipru

First, you need to add TOC to the Word document using the feildCode parameter value {TOC} with InsertField API method and later convert it using the SaveAs API method. Please check the Java Unit Tests for reference. Please feel free to contact us for any further assistance.

Insert Field Online in Java

Convert a Document to another Format Online with Detailed Settings in Java

Thanks for the information and examples. However, I don’t want to insert a TOC field as I already have it in the DOCX in the correct location. I just want to update it so it has the correct headings/page numbers before generating the PDF.

Many thanks
Philip

@philipru

To update the existing fields in the document, you can use the UpdateFields API method as following.

Thanks! That worked.

1 Like

3 posts were split to a new topic: Bibliography field update issue in MS Word document