12
$\begingroup$

I'm trying to export a plot with some added notes which happen to be in Russian.

Using Mathematica 8.04 and WinXP I evaluate

Export["smt.pdf", "Текст на русском", CharacterEncoding -> "WindowsCyrillic"]

Which gives nonsense as output. Is there a way to solve this?

$\endgroup$
  • 2
    $\begingroup$ Possibly related: Mathematica exports to PDF 1.4, which doesn't deal with certain kinds of OpenType fonts (scroll to bottom of the linked answer). $\endgroup$ – Verbeia May 17 '12 at 6:34
  • 1
    $\begingroup$ Works for me on Win7 mma8.0.1 Screenshot $\endgroup$ – Ajasja May 17 '12 at 6:57
  • 1
    $\begingroup$ @user829438 That was just a simple way to demonstrate that it works. Export and ExportString produce the same data---Export will write a readable PDF on my machine (WinXP, Mathematica 8.0.4, like yours). Test Export["test.pdf", "Текст на русском"] again (precisely as I wrote it, don't include CharacterEncoding), and if it still doesn't give you a readable output (try opening with Adobe Reader, that's what I used), then I have one more guess: set the system language to US English, reboot (just in case), and try again. I know it affects some things, e.g. parsing dates. $\endgroup$ – Szabolcs May 17 '12 at 9:06
  • 1
    $\begingroup$ So that solves it, thanks. @Szabolcs, would you post it as a solution or is this problem to local? $\endgroup$ – iav May 17 '12 at 11:59
  • 1
    $\begingroup$ @Szabolcs Brilliant! It works, but precisely, we must change the "Language for applications which do not support Unicode" to US English. I should say that after changing this option my computer now runs only in "Safe mode" and changing this option to its default walue does not help (ordinary run of Windows produces blue screen). I use Mathematica 8.0.4 on Windows XP SP3. Now I will reinstall Windows since I cannot load it in the usual way... $\endgroup$ – Alexey Popkov Jul 30 '12 at 14:26
8
$\begingroup$

It seems that the problem can be solved by setting explicit value of the CharacterEncoding global FE option (checked with MMa 8.0.4 and 9.0.0):

SetOptions[$FrontEnd, CharacterEncoding -> "UTF8"];
Export["test.pdf", "кириллический текст"]

An equivalent way (without changing the global FE settings):

Export["test.pdf", 
 Style["кириллический текст", CharacterEncoding -> "UTF8"]]

Instead of "UTF8" one may set "UTF-8" or "ASCII" with the same effect. The drawback of this approach is that all non-English letters are outlined.


Update

Starting from version 10 (checked with versions 10.4.1 and 11.1.1) Cyrillic text is exported correctly with default setting without converting glyphs into outlines:

Export["test.pdf", "кириллический текст"] // SystemOpen

Here is how exported file looks when opened by Adobe Acrobat 11 (I intentionally selected the first word to show that it isn't outlined):

screenshot

Moreover, text can be copied from Acrobat and correctly pasted into Notepad.

But importing such PDF as "Plaintext" still fails:

Import["test.pdf", "Plaintext"]
% // ToCharacterCode

output

 {1, 2, 3, 2, 4, 4, 2, 5, 6, 7, 1, 2, 8, 32, 9, 6, 1, 7, 9}

P.S. In versions 10 and 11 CharacterEncoding is not recognized as a valid FrontEnd option.

$\endgroup$
  • $\begingroup$ Alexey, I tried to save (just with the SaveAs menu item) a notebook file with some Russian text cells for my Russian co-authors as a pdf but failed. Could you please kindly comment, if there is the difference in the programmatic and menu exporting. Should I probably just fix CharacterEncoding prior to making file in order to later SaveAs a pdf? I have Mma 11.1.1.0 and Win7. $\endgroup$ – Alexei Boulbitch Aug 28 '17 at 6:49
  • $\begingroup$ @AlexeiBoulbitch Yes, there were many reports on this site that menu exporting produces different results (usually with much lower quality) than Export. So Export is always the preferred method. Printing to a virtual PDF printer is another option, and it usually allows to workaround problems with non-English letters (and usually it produces graphics with much better quality than menu exporting, but still not as good as Export). $\endgroup$ – Alexey Popkov Aug 28 '17 at 6:57
  • $\begingroup$ @AlexeiBoulbitch I just tried to Save As... a Notebook with some Russian text as PDF and got a correct PDF (Mathematica 11.1.1 on Win7 x64). There is a possibility that you use some non-standard fonts with which Mathematica has troubles. If so, try exporting with default fonts. $\endgroup$ – Alexey Popkov Aug 28 '17 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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