PDF Text Encoding

I think that this has been addressed elsewhere but I’m not finding it.

I’m trying to draw this to a PDF “0.03 μg/g” and it comes out as “0.03 w4g/g”
Is it possible to correct this with the current implementation?

Are using one the built in PDF fonts? If so they don’t understand unicode … IIRC It’s Windows Ansi… So try convert encoding on the string first, or use a unicode say font.

That is just a a guess… I use the Einhugur PDF plugin not the Xojo stuff as I need backwards compatibility, so I don’t know the Xojo implementation well, though for the built-In PDF fonts, I would have thought they would do convert encoding under the hood when needed, so that may not be it.

BTW as an analytical chemist I am curious as what those units are being used for! :wink:
-Karen

Use DynaPDF with kcpUnicode instead.

2 Likes

I’ve already written a s-ton of code using the PDFDocument class.

Xojo Staff… can I make ITF8 work?

1 Like

Hi @Chris_Halford,

We are working on that and other improvements to come to PDFDocument.

1 Like

Please give some points to this Feedback case “PDFDocument: Support Unicode Text” <https://xojo.com/issue/61678>.

For this specific case you SHOULD be able to get a µ (mu) to print with the Xojo implementation if you first convert encoding, as µ (mu) is in the WinAnsi character set.

I am using µg/mL for units using PDF standard fonts with the Einhugur PDF plugin without issue so Xojo should be able to as well.

-Karen

Nutrient composition.

Javier, does that mean I can’t make it work now?

Well I just noticed DynaPDFMBS.pageGraphics.
Somehow it renders some things out strangely, but I think I can make it work.

Hi @Chris_Halford

Please, a “bit” of patience :wink:

Screenshot 2020-11-24 at 12.02.03

2 Likes

You can make it :slight_smile:

Var pdf As New PDFDocument
Var g As Graphics = pdf.Graphics

' http://ascii-table.com/ansi-codes.php
Var s As String = "This is some test " + _
  Encodings.WindowsANSI.Chr(181) + _ ' µ = 181
  "g/gr"

g.DrawText(s, 50, 50 + g.FontAscent)

Var file As FolderItem = SpecialFolder.Desktop.Child("Ansi.pdf")

pdf.Save(file)

Or, since 2020r2, you don’t need to encode the string:

Var f As FolderItem = SpecialFolder.Desktop.Child("Test.pdf")

Var doc As New PDFDocument
Var g As Graphics = doc.Graphics

g.DrawText("This is a test: µg/gr",50,50)

doc.Save(f)
f.Open
2 Likes

So this is really strange. The string I am trying to draw comes from a SQLiteDatabase and self-reports to be UTF-8, and looks right in the Xojo debugger.
It still prints with a ?
However when I set the string with the character I want and rerun the code it comes out with “µ”

Got it… each character looks the same but has a different ascii value.
Oddly DynaPDF handles them the same.

DynaPDF can do unicode :slight_smile:

Indeed. And due to the way you’ve added the Xojo graphics compatibility I can easily put in a switch to make use of either.

Thanks.

Back to this topic… While the characters we showed above have been working (thank you), for the other half of my programming life, I need the ∆ to be able to print and it doesn’t seem to be able to.

Thoughts?

ANSI character 68 from PDFDocument.StandardFontNames.ZapfDingbats ?

If not, you can insert a bitmap, or draw 3 lines?