12
$\begingroup$

I am using Mathematica 9.0.0.0 under German Windows 32bit. I am on trying to export and import German text to PDF and re-import it. It seems that there is a confusion about the character encoding. It obviously differs between Export and Import. However, nothing related to the encoding is described in the PDF documentation, nor does specifying CharacterEncoding in PDF import and export seem to make any difference.

ImportString[ExportString[
  "This is a string. Aber was ist mit äöü, ß und ÄÖÜ? Also x\.b2 und \y\.b3 measured in µm",
  "PDF"]]

I wonder if there is a work-around which doesn't require a complete re-mapping. PDF export is slow, and doing it character by character will probably take hours.

$\endgroup$
2
  • 3
    $\begingroup$ I got most of it to work now. The String itself has to be coded using UTF-8 as in CharacterEncoding -> "UTF-8" inside the Style function. The \.b2 and \.b3 don't work yet. Maybe one day someone will find out how to make these work, too. $\endgroup$ Commented Apr 1, 2013 at 10:59
  • 3
    $\begingroup$ Ok, the FontFamily matters, too: This finally works! Style["This is a string. Aber was ist mit äöü, ß und ÄÖÜ? Also x\.b2 \ und y\.b3 measured in \[Micro]m", FontFamily -> "Arial", CharacterEncoding -> "ASCII"] $\endgroup$ Commented Apr 1, 2013 at 11:20

1 Answer 1

7
$\begingroup$

So PDF Import accepts a CharacterEncoding option, but it seems to ignore it. Exporting in UTF-8 or in ASCII gives the best results, with the former supporting the Euro symbol € and the latter supporting the ² and ³ symbols. Life is all about choice I guess.

The String itself has to be encoded using Style, and the FontFamily matters, too:

ImportString[
  ExportString[
    Style["This is a string. Aber was ist mit äöü, ß und ÄÖÜ? Also x\.b2 und y\.b3 measured in \[Micro]m",
    FontFamily -> "Arial", CharacterEncoding -> "ASCII"],
  "PDF"]
]

Note that, on import, you can give the option "TextMode" -> "Outlines" which results in FilledCurve entities being used instead of text entities. This is then highly portable and probably the safest way to ensure the correct appearance across systems at the expense of memory of course.

I have also been able to convert the filled curves to 3D outlines. This looks pretty cool and probably qualifies as a "neat example". I will post this separately and provide a link here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.