We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Free Text Annotation with Chinese text not showing up in downloaded PDF

Hi,

The sample code used is available at https://stackblitz.com/edit/angular-sgts1f?file=src%2Fapp.component.html,src%2Fapp.component.ts

Found couple of issues with Free text annotation when downloaded as PDF are listed below:

  1. background color is removed on downloaded PDF
  2. Chinese text in Free Text annotation is not showing up in downloaded PDF. English text is rendered correctly.

Please refer the attached video.



Attachment: freetextannotationchinesetextissue_34a3e07c.zip

5 Replies

CK Chinnamunia Karthik Chinna Thambi Syncfusion Team March 20, 2023 04:12 PM UTC

Please find the details.


background color is removed on downloaded PDF

We were able to reproduce the reported issue  Fillcolor of the freetext annotation is not preserved properly while downloading”. You can track the status of the issue also through the following link.

 

Feedback link: Fillcolor of the freetext annotation is not preserved properly on XFDF import  | Issue Feedback

Chinese text in Free Text annotation is not showing up in downloaded PDF. English text is rendered correctly.

We don’t have direct support to save the custom font style for free text annotation. So, while saving the document at the service project, we have embed the font with annotation on the download action. Kindly try this at your service project to get this issue resolved.

 

Code snippet:

 

 

     public IActionResult Download([FromBody] Dictionary<string, string> jsonObject)

    {

        //Initialize the PDF Viewer object with memory cache object

        PdfRenderer pdfviewer = new PdfRenderer(_cache);

        string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);

        string base64Data = documentBase.Split("base64,")[1];

        byte[] document1 = Convert.FromBase64String(base64Data);

        PdfLoadedDocument ldoc = new PdfLoadedDocument(document1);

        FileStream fontStream = new FileStream(GetDocumentPath("SIMSUN.ttf"), FileMode.Open);

        for (int i = 0; i < ldoc.Pages.Count; i++)

        {

            PdfLoadedPage lpage = ldoc.Pages[i] as PdfLoadedPage;

            for (int j = 0; j < lpage.Annotations.Count; j++)

            {

                PdfLoadedFreeTextAnnotation lAnnot = lpage.Annotations[j] as PdfLoadedFreeTextAnnotation;

                if (lAnnot != null)

                {

                    if (IsChineseCharacter(lAnnot.MarkUpText))

                    {

                        lAnnot.Font = new PdfTrueTypeFont(fontStream, lAnnot.Font.Size);

                        lAnnot.ComplexScript = true;

                        lAnnot.SetAppearance(true);

                    }

                }

            }

        }

        MemoryStream stream = new MemoryStream();

        ldoc.Save(stream);

        string base64string = Convert.ToBase64String((stream as MemoryStream).ToArray());

        ldoc.EnableMemoryOptimization = true;

        ldoc.Close(true);

        ldoc.EnableMemoryOptimization = true;

        ldoc.Close(true);

        stream.Dispose();

        return Content("data:application/pdf;base64," + base64string);

    }

 

 

    public static bool IsChineseCharacter(string input)

    {

        foreach (char c in input)

        {

            if (c >= '\u4e00' && c <= '\u9fff')

            {

                return true;

            }

        }

        return false;

    }

 

 

Please find the attached sample for your reference.

 

Angular sample: https://stackblitz.com/edit/angular-sgts1f-srnyrn?file=src%2Fapp.component.html,src%2Fapp.component.ts

 

Web service Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/ChineseCharacter284623670.zip

 

Steps to save the embed the Chinese character while downloading:

 

  • Run the web service sample
  • And then run the angular sample
  • Add the free text with chinese character,
  • Download the document.
  • Now, the chinese character is present in the downloaded document.


SR Sriraman replied to Chinnamunia Karthik Chinna Thambi March 21, 2023 04:41 AM UTC

  1. The feedback link you gave is issue with importing the xfdf. Will it also fix the download PDF issue?
  2. Is there any alternative? How do we know that the user is using simsun font? The user may use any font awailable in his machine which we may not have.


CK Chinnamunia Karthik Chinna Thambi Syncfusion Team March 21, 2023 08:56 AM UTC

Please find the details.


The feedback link you gave is issue with importing the xfdf. Will it also fix the download PDF issue?

 

Yes, While fixing the import issue the download issue will be fixed. We have edited the feedback title and description too.

Is there any alternative? How do we know that the user is using simsun font? The user may use any font awailable in his machine which we may not have.

We have provided the support to save the free text annotations with the built-in fonts. If you are using except the built-in fonts, then you need to embed them in the server side to view it in other viewers. It is a known limitation.



SR Sriraman replied to Chinnamunia Karthik Chinna Thambi March 21, 2023 11:21 AM UTC

Ok. In that case, instead of loading from the custom folder, how can I assign a specific font (like Arial Narrow) which already exists in Fonts directory?



SJ Sathiyathanam Jeyakumar Syncfusion Team March 22, 2023 01:51 PM UTC

In the given sample, we get font stream from the project location. Similarly, you need to get font stream from the required directory on your end.




Loader.
Live Chat Icon For mobile
Up arrow icon