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

Free Support Forum - aspose.com

If the Bookmarks is not exist- Export Bookmarks To XML ( The error occurred)

How to decide whether there really are bookmark involved?


Document pdfDocument = new Document(ABC.pdf);//ABC.pdf does not contain bookmarks .

if (pdfDocument.Outlines.Count>0 || pdfDocument.Outlines.First.Count > 0)//Outlines.Count | 1
{
try
{
Aspose.Pdf.Facades.PdfBookmarkEditor bookmarkEditor = new Aspose.Pdf.Facades.PdfBookmarkEditor();
bookmarkEditor.BindPdf(pdfDocument);
//Export bookmarks
bookmarkEditor.ExportBookmarksToXML(sOutpathFile);//The error occurred
}

catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
//
}

Hi Huang,


In order to get the Bookmark count, please try using following code snippet. In case I have not properly understood your requirement, please share some further details.

[C#]

//open document<o:p></o:p>

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document("c:/pdftest/ABC.pdf");

//loop through all the bookmarks

foreach (OutlineItemCollection outlineItem in pdfDocument.Outlines)

{

Console.WriteLine("Total Bookmark count " + outlineItem.Count);

}

Thank you!

I run your code!
outlineItem.Count | 0 // Why the Count is zero ?, The Attachment PDF file contains the bookmark.
outlineItem.Title | “A” //The bookmark name display correct.

Kleif:
Thank you!
I run your code!
outlineItem.Count | 0 // Why the Count is zero ?, The Attachment PDF file contains the bookmark.
outlineItem.Title | "A" //The bookmark name display correct.
Hi Huang,

Thanks for sharing the resource file.

I have tested the scenario using bookmark.pdf and I am able to notice that incorrect bookmark count is being returned. For the sake of correction, I have logged this problem as PDFNEWNET-37274 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Hi Huang,


Thanks for your patience In reference to above logged issue, we would like to update you that in loop outlineItem.Count returns count of subitems of current bookmark. In order to get bookmark count (more correct count of bookmarks of highest level), you may use:

Console.WriteLine(doc.Outlines.Count);


var doc = new Document(myDir

  • “bookmark.pdf”);<o:p></o:p>

//count of bookmarks at document level

Console.WriteLine(doc.Outlines.Count);

//loop through all the bookmarks

foreach (OutlineItemCollection outlineItem in doc.Outlines)

{

Console.WriteLine("Total child Bookmark count " + outlineItem.Count);

Console.WriteLine("Bookmark title " + outlineItem.Title);

}


Please feel free to contact us for any further assistance.


Best Regards,

The issues you have found earlier (filed as PDFNEWNET-37274) have been fixed in Aspose.Pdf for .NET 9.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.