ToC and Bookmarks in PDF export work in one pdf but not the other

I have a problem that I have been trying to understand for a long while and I am very confused as to why it’s not working as it should.

I have a macro where I want to export the current document as a PDF. There are two Functions that get called depending on the mode of operation. Both use the same bit of code to export the PDF. Only one has working bookmarks and ToC’s in the PDF, the other one does not work at all (they are present in the PDF file, but the links do not work)

Here is the PDF export bit that I use in both functions.

	args2(0).Name = "URL"
	args2(0).Value = fullPdfFilePathName
	args2(1).Name = "FilterName"
	args2(1).Value = "writer_pdf_Export"
	args2(2).Name = "ExportBookmarks"
	args2(2).Value = True
	args2(3).Name = "UseTaggedPDF"	'Use document headings
	args2(3).Value = True
	dispatcher.executeDispatch(document, ".uno:ExportDirectToPDF", "", 0, args2())

As both functions use this same bit of code, I even tried using a separate sub for the PDF export part, but that still resulted in non-working bookmarks and ToC.

I have saved the code as text files in the attached zip file rather than paste it here. The extra bit is PDFDoc.txt. I’ve also included a Test.odt file and three PDF’s. The manual export works fine as does the version from SaveFinalFile.txt. The non working pdf file is from SaveActiveFile.txt

The only thing I can think of is maybe how the file is referenced, but I’m clutching at straws here.

Files.zip (141.5 KB)

may be this post can help you

Two considerations about your code:

  • To concatenate text it is better to use the ampersand symbol (&) although you can use the plus sign (+) as macros may confuse it with a mathematical sum.

  • when you lock the screen, lockScreen(True) make sure to unlock it in error checking.
    If an error occurs, it may be blocked and the user cannot continue