We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Getting Page Numbers of Bookmarks from converted Word Doc

When saving a Aspose.Words document to PDF format, will the bookmarks and the bookmark names carry over into the PDF?

If so, is there a way to go through the PDF file and determine the page number that each of the bookmarks start on?

Hi,

Bookmarks are associated with headings. The page to which the bookmark points cannot be know until the pdf has been generated because the amount of content that fits in one page depends on a lot of factors like page size. So in Aspose.Pdf I don’t think it is possible. However once the pdf has been generated you can use Aspose.Pdf.Kit to get the pages which is pointed to by a bookmark.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html

I did not explain clearly. By bookmarks I did not mean the outline that is in the tree of the PDF… I was referring to the Bookmarks that get created in Word… do those go into the PDF as objects? If so does the Word bookmark name carry over into the PDF and is there a way to get the page number of that object (with Aspose.PDF or PDF.Kit)?

The concept of "bookmark" in Aspose.Pdf is totally different with that in MS Word. Bookmark in Pdf is similar with "document map" in Word. The bookmark in Word is ignored when converting into Pdf.

I am in dire need to figure something out for this.

Is there anything that can be inserted into the Aspose.Words document that will carry over into the PDF, but not be visible but allow me to retrieve it through the object model and determine the page number.

I have many documents going into one document using Words and I need to track the page numbers of each of those documents. Being the PDF is the only pagination engine available right now to view the words doc I need to find a way.

I am sorry to tell you this not supported directly. I don't know if the following solution can help you:

In my test, if I set bookmark in the Word document, the Aspose.Words will generate a ID for the text. The ID will be "paraId_1","paraId_2",...

You can display the page of the text using the paraID like the following:

Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense(@"D:\CSharp\Test\License\Aspose.Custom.lic");
Document doc = new Document(@"D:\test\testword\testid.doc");
doc.Save(@"D:\test\testword\input.xml",SaveFormat.AsposePdf);

System.DateTime begin = System.DateTime.Now;
Pdf pdf = new Pdf();
Aspose.Pdf.License lic = new Aspose.Pdf.License();
lic.SetLicense(@"D:\CSharp\Test\License\Aspose.Custom.lic");

pdf.BindXML(@"D:\test\testword\input.xml",null);

//add new text to show the para page number
Text t1 = new Text("The page number for 'paraId_1' is #$REFPAGE(paraId_1)");
pdf.Sections[0].Paragraphs.Add(t1);

pdf.Save(@"D:\test\testword\output.pdf");

I have attached a example Word document.

If you want to locate the text in Pdf like the bookmark in Word, we can't support it. You can consider adding a toc in the Word document.

i have a similiar issue but probably more likely to be done with aspose.pdf.kit.

would you please confirm that it can be done and also some sample code?

i'm maintaining an application which is using aspose.pdf, aspose.kit and aspose.word.

my question is, how can i create bookmakrs for each documents (word, excel, pdf) after they are merged into a single pdf?

i don't need to carry over the word bookmark name. but i just need to create one bookmark for each input document (muti-page docs).

thanks,

Hello Ray,

Thanks for considering Aspose.

Aspose.Pdf.Kit offers the capability to create bookmarks within an existing Pdf file. PdfContentEditor class offers the capability to create Bookmarks of specific Pages using CreateBookmarkOfPage method. It also offers the capability to create Bookmarks of all the pages using CreateBookmarks method. Even you can create a Bookmark with specific action using CreateBookmarksAction method.

The BookMark class in Aspose.Pdf.Kit provides an interface to specify various Bookmark properties which includes specifying destination page number, Action, Bookmark Level, Title and much more. For further information please visit BookMark Members.

FYI, PdfContentEditor provides the capability to export the Bookmark contents into XML file using ExportBookmarksToXML, even you can extract all the contents of Bookmark using ExtractBookMarks and also you can Extract the Bookmarks into HTML file using ExtractBookmarksToHTML.

Please take a look and in case of any further query, feel free to share.