Free Support Forum - aspose.com

Bookmarks appearing with underscores

We have been using aspose word and pdf for a while. We have a process where we create a word document with aspose word then convert it a pdf.

We recently upgraded to the latest version and noticed that after the upgrade all of the bookmarks that were added to the word documents now have '_' characters where there should be spaces e.g. Page 1 is appearing as "Page_1".

I have looked at the documents bookmarks before they have been converted to a pdf and they do not have these underscores.

Can you please advise me as to how i return this to the previous functionality.

We are using the below code when saving the aspose document to pdf

//Adding the bookmark
builder.StartBookmark("Page 1");
builder.EndBookmark("Page 1");


//Options set for saving the pdf
PdfSaveOptions pdfOptions = new PdfSaveOptions();
pdfOptions.BookmarksOutlineLevel = 1;
pdfOptions.SaveFormat = SaveFormat.Pdf;
pdfOptions.PreserveFormFields = true;

Kind Regards
Graeme

Hi Graeme,


Thanks for your inquiry. The problem occurs because Microsoft Word doesn’t allow you to use spaces in bookmark names. Aspose.Words replaces the spaces in these invalid Bookmark names with underscore characters. If we can help you with anything else, please feel free to ask.

Best Regards,

Hi Can i ask why this used to work before but now does not after i have upgraded Aspose? It used to allow and show me spaces in word bookmarks but after the update does not. Is this a change to Aspose or Word. I am inclined to say this is an Aspose change as it is happening on multiple versions of word.


Kind Regards
Graeme

Hi Graeme,


Thanks for the additional information. Could you please provide a little more information about the Aspose.Words’ version number for which there were no problems on your side previously? I will further look into the details of this problem and will keep informed of my findings.

Best Regards,

Hi we were on version 9.6 and we are now on version 11.5


Please let me know asap what your findings are.

Kind Regards
Graeme

Hi Graeme,


Thanks for your inquiry. I have attached a Word document (out.docx) here for your reference. This document was generated by using Aspose.Words v9.6.0 on my side. I have used the following code to produce it:

Document doc = new
Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartBookmark("Page 1");

builder.EndBookmark("Page 1");

doc.Save(@"C:\Temp\out.docx");


If you open this document with Microsoft Word and determine the name of the Bookmark, you'll still find underscores instead of spaces.

Best Regards,

I can assure you if i go back to our old version we are getting bookmarks with spaces in. However if you refer back to my first comment on this post you will see that i am outputting to a pdf and not a word document. We start off with a word document and as i stated we then save to a pdf.


We have thousands of examples of the pdf with this working in that version so an explanation would be helpful.

Kind Regards
Graeme

Hi Graeme,


Thanks for your inquiry. Yes, I understand. But, in order to reproduce this problem on my side, please generate a Word document (Preferably DOCX) and a PDF with old version of Aspose.Words where Bookmarks work fine and attach them here for our reference. Also, please share the complete code you used to generate those documents here for testing.

Best Regards,