Forums

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for .NET (v8.x)  /  Bookmark can't support Asian font very well

Forum Thread - Bookmark can't support Asian font very well

Dear Sir/Madam:

It seems when I put some asia characters into bookmark function, bookmark stops to generate after random number of bookmarks produced.

        var bookmark = new Bookmark(string.Format("{0}中文", index++), 0, 0, parentOutline);




the code snippet as below:

      // Add a top level Outline
      Outline parentOutline = document.Outlines.Add("目录");

foreach (var chapter in chapters) {
        Console.WriteLine(chapter);

        var content=File.ReadAllText(chapter, Encoding.UTF8);
        var bookmark = new Bookmark(string.Format("{0}中文", index++), 0, 0, parentOutline);
        FormattedTextArea textarea=new FormattedTextArea(content, 0,0, pageDim.Width*0.88f, pageDim.Height*0.9f, style);

        do {
          Page page = new Page(pageDim);
          if (bookmark != null) {
            page.Elements.Add(bookmark);
            bookmark = null;
          }
          page.Elements.Add(new BackgroundImage(imageData));

          page.Elements.Add(textarea);
          document.Pages.Add(page);
          textarea = textarea.GetOverflowFormattedTextArea();
        } while (textarea != null);
       
      }

However, if I change it into

var bookmark = new Bookmark(string.Format("{0}Eng", index++), 0, 0, parentOutline);

It has no issue to generate all the bookmarks.

Could you please have a look?

by the way, all the content are no problem, just bookmarks.

Cheers.
Posted by a ceTe Software moderator
Hello,

We did testing on our end and we are able to add the bookmark text containing Asian language characters. Below is the code sample.

            Document document = new Document();
            Outline parentOutline = document.Outlines.Add("目录");
            for (int i = 0; i < 5; i++)
            {
                Page page1 = new Page();
                page1.Elements.Add(new Label("Page :" + (i + 1), 0, 0, 200, 40));
                page1.Elements.Add(new Bookmark(string.Format("{0}中文", i + 1), 0, 0, parentOutline));
                document.Pages.Add(page1);
            }
           document.Draw(@"C:\temp\MyOutlines.pdf");

If you continue getting the similar bahavior on your end then please send over the following details to support@cete.com so we can look into it further.

1.Code sample or project which uses static data to recreate the behavior.
2.Output PDF.
3.Exact version and build number of the DynamicPDF DLL file. You can get this information in DLL references properties (Version and Description fields) in Visual Studio.
4.More details on the problem you are facing.

Thanks,
ceTe Software Support Team.
Thanks for the reply:

After further investigation, I finally found what's the issue, sorry I forgot to mention I have security in the document, I didn't think security setting can cause that weird issue, so, I just overlooked it.

To replicate the issue.

if you add below two line after "Document document=new Document();", you will see the difference.Please also change i from 5 to 100.

var security = new RC4128Security();
document.Security = security;

Therefore, the final test code will be:

            Document document = new Document();
            var security = new RC4128Security(); //new code here
            document.Security = security;  //new code here
            Outline parentOutline = document.Outlines.Add("目录");
            for (int i = 0; i < 100; i++)  //change i from 5 to 100
            {
                Page page1 = new Page();
                page1.Elements.Add(new Label("Page :" + (i + 1), 0, 0, 200, 40));
                page1.Elements.Add(new Bookmark(string.Format("{0}中文", i + 1), 0, 0, parentOutline));
                document.Pages.Add(page1);
            }
           document.Draw(@"C:\temp\MyOutlines.pdf");

Now, check "MyOutlines.pdf", you will see the issue on bookmarks.

By the way, it only affects on RC40 and RC128, it seems fine on AES128 and AES256.

Hope you can fix it soon.

Cheers
Sorry, another bad news.

Please try below code:

        Document document = new Document();
        var security = new Aes128Security();
        document.Security = security; 
        Outline parentOutline = document.Outlines.Add("目录");
        for (int i = 0; i < 1500; i++)  //change i to 1500
        {
            Page page1 = new Page();
            page1.Elements.Add(new Label("Page :" + (i + 1), 0, 0, 200, 40));
            page1.Elements.Add(new Bookmark(string.Format("{0}", i + 1), 0, 0, parentOutline));
            document.Pages.Add(page1);
        }
        document.Draw(@"MyDocument.pdf");

If I use AES security, when i becomes large (such as above 1500), the program crashes.

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the boun
ds of the array.
   at zz93.di.WriteText(String text)
   at ceTe.DynamicPDF.Outline.cp(DocumentWriter A_0)
   at ceTe.DynamicPDF.Outline.a(DocumentWriter A_0)
   at ceTe.DynamicPDF.OutlineList.a(DocumentWriter A_0)
   at ceTe.DynamicPDF.Outline.a(DocumentWriter A_0)
   at ceTe.DynamicPDF.OutlineList.a(DocumentWriter A_0)
   at zz93.dm.Draw(DocumentWriter writer)
   at ceTe.DynamicPDF.IO.DocumentResourceList.a(DocumentWriter A_0)
   at zz93.dh.Draw()
   at ceTe.DynamicPDF.Document.Draw(Stream stream)
   at ceTe.DynamicPDF.Document.Draw(String filePath)

It doesn't matter if asian characters or not.

Please have a try.

Cheers
Posted by a ceTe Software moderator
Hello,

Thanks for all the information. We did testing on our end and seeing similar error and behavior while adding bookmarks and setting security. We will forward this information to our developers to look into it further. We will post it on the forum once these issues are resolved and new build files including the fix is ready to download.

Thanks,
ceTe Software Support Team.
Posted by a ceTe Software moderator
Hello,

We have released a new build that fixes this issue. You may download it from the product page if you are evaluating the product. If you have a valid license, you can download it from the customer area.


Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 7:21 AM.