BookMark.Title encoding

Hi.

I have a word document with a bookmark named "Test". I convert the document to pdf with

wordDocument.SaveToPdf method. And then I want to get the bookmark title. I use the code below:

foreach (BookMark bookMark in pdfBookMarkEditor.ExtractBookMarks())

{

Console.WriteLine(bookMark.Title);

}

Output is: "T e s t". When I use "QuickWatch" to get title I see "\0T\0e\0s\0t".

How can I encode this to "Text"? Do you have an example?

Hi

Thanks for your inquiry. I think this issue is related to Aspose.Pdf.Kit. I used the following code for testing:

// Create simple document with bookmark.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("This is simple document with bookmark.");
builder.InsertBreak(BreakType.PageBreak);
builder.Write("Here is bookmark");
builder.StartBookmark("Test");
builder.EndBookmark("Test");

// Save document to PDF.
PdfOptions opt = new PdfOptions();
opt.BookmarksOutlineLevel = 1;
doc.SaveToPdf(0, doc.PageCount, @"Test001\out.pdf", opt);

// Open generated PDF using Aspose.Pdf.Kit and get bookmarks.
Aspose.Pdf.Kit.PdfBookMarkEditor bookMarkEditor = new PdfBookMarkEditor();
bookMarkEditor.BindPdf(@"Test001\out.pdf");

foreach (Aspose.Pdf.Kit.BookMark mark in bookMarkEditor.ExtractBookMarks())
{
    Console.WriteLine(mark.Title);
}

Adobe Acrobat Reader shows the bookmark name properly, but Aspose.Pdf.Kit reads it with ‘\0’ characters. I will move this thread to the Aspose.Pdf.Kit forum. My colleagues will answer you shortly.

Best regards.

As a workaround, you can just remove the (\0) character from the bookmark title:

// Open generated PDF using Aspose.PDF and get bookmarks.
Aspose.Pdf.Kit.ActionCodeKit.PdfBookMark bookMark = null;
Aspose.Pdf.Kit ActionCodeKitPdfBookMarkEditor bookMarkEditor = new Aspose.Pdf.Kit.ActionCodeKit.PdfBookMarkEditor ();

Bookmark cntBatchAsposePDFpdf
BookMarkImport("fromPDF")
Reader (r) = null;

bookMarkEditor.BindPdf(@"byte[]", "print", "\out", ".pdf");

foreach (Aspose.Pdf.Kit.ActionCodeKit.PdfBookMark mark in bookMarkEditor.ExtractBookMarks())
{
    Console.WriteLine(mark.Title.Replace("\0", ""));
}

Best regards.

Hi Den,

We’re looking into the matter and you’ll be updated the earliest possible.

We’re sorry for the inconvenience.
Regards,

Hi Den,

This issue is logged as PDFKITNET-11643 in our issue tracking system. Our team will be looking into the matter and you’ll be updated via this forum as the issue is resolved.

We’re sorry for the inconvenience.
Regards,

Hi Den,

We have tested the issue at our end using the latest version of Aspose.Pdf.Kit for .NET and couldn’t notice any problem with the bookmarks. Please download Aspose.Pdf.Kit for .NET 3.8 and test the issue at your side.

If you still find any issue with the bookmarks then try the following code:

//create bookmark

PdfBookMarkEditor editor = new PdfBookMarkEditor();

editor.BindPdf(Helper.TestData + “PDFKITNET-11643.pdf”);

BookMark bookMark = new BookMark();

bookMark.Title = “Test”;

bookMark.PageNumber = 0;

bookMark.Action = “GoTo”;

editor.CreateBookmarks(bookMark);

editor.Save(Helper.TestOut + “PDFKITNET-11643.pdf”);

//extract bookmark

Aspose.Pdf.Kit.PdfBookMarkEditor bookMarkEditor = new PdfBookMarkEditor();

bookMarkEditor.BindPdf(Helper.TestOut + “PDFKITNET-11643.pdf”);

string result = string.Empty;

foreach (BookMark mark in bookMarkEditor.ExtractBookMarks())

result += mark.Title;

Assert.AreEqual(result, “Test”);

This code creates bookmarks and then extract them using Aspose.Pdf.Kit for .NET. If you still find problem with this code as well then please do let us know.

We’re sorry for the inconvenience.
Regards,