Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Sep 09, 2020 7:09 pm

Hello,

I'm trying to get unicode to work, I have a sample string here:
Code: Select all
page.Canvas.DrawString($"Student Attendance Report ☑", new PdfTrueTypeFont("Arial", 18f, PdfFontStyle.Regular, true, true), new PdfSolidBrush(Color.Black), 0, 180);


I am expecting to see the checkbox appear on my pdf, but with the above code, it looks wrong:
Image

If I set the last argument in PdfTrueTypeFont to false, then the checkbox doesn't appear, but the rest of the string looks fine.

MrCarrot
 
Posts: 2
Joined: Wed Sep 09, 2020 7:00 pm

Thu Sep 10, 2020 3:45 am

Hello,

Kindly note that some fonts do not support drawing the glyph "☑", you need to use a font that supports this glyph. Please refer to the following code and download the latest Spire.PDF Pack(Hot Fix) Version:6.9.0 to test.

Code: Select all
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"Sample.pdf");

            PdfPageBase page = doc.Pages[0];
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 18f, FontStyle.Regular), true);
            SizeF size = font.MeasureString("Student Attendance Report ");
            page.Canvas.DrawString($"Student Attendance Report ", font, new PdfSolidBrush(Color.Black), 0, 180);

            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Segoe UI Symbol", 18f, FontStyle.Regular), true);
            page.Canvas.DrawString($"☑",font2,new PdfSolidBrush(Color.Black), 0 + size.Width, 180);

            String result = "result-Segoe.pdf";
            //Save to file
            doc.SaveToFile(result);

            System.Diagnostics.Process.Start(result);


Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Thu Sep 10, 2020 5:49 pm

It works now thank you. Didn't realise that not all fonts have all unicode characters.

Also, what is the purpose of the useTrueType argument when making a new instance of PdfTrueTypeFont? I would have thought using the PdfTrueTypeFont class implies that you would like to use true type.

Kind Regards,
MrCarrot

MrCarrot
 
Posts: 2
Joined: Wed Sep 09, 2020 7:00 pm

Fri Sep 11, 2020 3:46 am

Hello,

Thanks for your feedback.
Regarding the “useTrueType argument” you mentioned, are you referring the to the “unicode” argument, as shown below?
Code: Select all
           
           //public PdfTrueTypeFont(System.Drawing.Font font, bool unicode);
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 18f, FontStyle.Regular), true);

Kindly note that for special characters whose Unicode value exceeds 255, you need to set "unicode" to true, otherwise the characters will not be displayed as expected.
Or if there is any misunderstanding, please feel free to let us know.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Tue Sep 29, 2020 3:57 am

Hello,

Greetings from E-iceblue.
How is your issue now? Could you please give us some feedback at your convenience?

Sincerely
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Return to Spire.PDF

cron