Can one export Special symbols / Cyrillic letters in plot labels when exporting graphics to PDF ?
Asked Answered
C

2

7

I am trying to export a list of graphics as separate frames in PDF format in order to then compile a vector SWF animation with the aid of external utility (such as pdf2swf). Unfortunately, some special characters (e.g. Degree sign or triple dots) are corrupted in the exported PDF files. That is also the destiny of all Russian letters. Note that Mathematica rasterises graphics in a list when it is directly exported from Mma to SWF, which yields unsatisfactory results in my case.

Is there a way to preserve those letters in exported graphics?

Single graphics can be manually edited in a graphics editors, but it is hardly possible for hundreds of frames for video. Some symbols can be preserved by the following custom function:

ExportPDF[filename_, elem_, 
  opts : OptionsPattern[{Export, Outlines -> True}]] := Module[{$elem},
  $elem = Style[elem, Background -> None];
 If[OptionValue[Outlines] == True
   , $elem = 
    First@ImportString[ExportString[$elem, "PDF"], "PDF", 
      "TextMode" -> "Outlines"]
   ];
  Export[filename, $elem, FilterRules[{opts}, Options[Export]]]
 ]

Unfortunately, it doesn't always help.

Cordi answered 16/6, 2011 at 7:46 Comment(0)
S
6

One workaround is to export to EMF instead of PDF format:

Export["C:\\1.emf", 
 Plot[Sin[x], {x, 0, Pi}, PlotLabel -> 
   "\:0420\:0443\:0441\:0441\:043a\:0438\:0435 \:0431\:0443\:043a\:0432\:044b"]]

You can further convert EMF to PDF or SWF if you wish. See here general tips on high-quality EMF export from Mathematica.

Another way that seemingly works reliably is to convert only Cyrillic text to outlines and then place it in your graphics with Inset or with Labeled:

plotLabel = 
  First@ImportString[ExportString[
    "\:0420\:0443\:0441\:0441\:043a\:0438\:0435 \:0431\:0443\:043a\:0432\:044b",
       "PDF"], "PDF"];
Labeled[Plot[Sin[x], {x, 0, Pi}], plotLabel, Top]

Or you can use the outlined text directly as PlotLabel:

Export["C:\\1.pdf", Plot[Sin[x], {x, 0, Pi}, PlotLabel -> plotLabel]]

You can generalize this method by writing a simple routine:

cyrFix = First@ImportString[ExportString[#, "PDF"], "PDF"] &

You can use it as follows:

Export["C:\\1.pdf", 
 Plot[Sin[x], {x, 0, Pi}, PlotLabel -> 
  cyrFix@"\:0420\:0443\:0441\:0441\:043a\:0438\:0435 \:0431\:0443\:043a\:0432\:044b"]]
Symptom answered 16/6, 2011 at 9:45 Comment(6)
@Alexey: Thanks. Not sure, but export to EMF seems to works because it is bitmap [at least neither CorelDraw nor Abobe Illustrator did not manage to import the exported EMF correctly], but second method really works.Cordi
@Cordi Mathematica exports 3D-graphics to EMF format as bitmaps only starting from the version 6. It still exports 2D graphics to EMF as vectors (if it is not GraphicsComplex). If you are interested in exporting 3D graphics (or GraphicsComplex) it is worth to create another specific question but I am still not experienced in this field. And about CorelDraw: have you tried to use the most resent version?Symptom
@Alexey: I noted that cyrFix"text" yields graphics which has smaller size than pure "text" if it is used as PlotLabel or AxesLabel. I've got satisfatory result after modifying your example as follows: PlotLabel -> cyrFix@Style["\:0420\:0443\:0441\:0441\:043a\:0438\:0435 \:0431\:0443\:043a\:0432\:044b",Magnification->1.5]. Also I noted that cyrFix does not fix that problem if FontFamilly->"Calibri" whereas other fonts I tried are indeed corrected by cyrfix.Cordi
@Cordi The smaller size is due to "Printout" style environment used when exporting to PDF. See this question for the solution and this answer for advanced explanation. As for the "Calibri" font I have no such problem: on my system cyrFix works well with it as well as with other fonts. If you use version 8 may be you need to add "TextMode" -> "Outlines" option to ImportString?Symptom
@Alexey: "TextMode" -> "Outlines" did not help. I fond loot fonts, which are not exported properly: Book Antiqua, Bookman Old Style, Calibri, Century Schoolbook, Minion Pro, Mistral, e.t.c. However, calibri (in conrast to Calibri) is inded fixed by cyrfix!. It means that cyrFix is case sensetive to Font name!Cordi
@Cordi What is the problem exactly? Does cyrFix not convert these fonts to outlines? I have checked all the fonts you mentioned and found a problem only with "Century Schoolbook": it is converted to outlines but looks very different from how it should.Symptom
R
0

Mathematica's PDF export does not curremtly support Cyrillic, only Roman, Greek, Japanese, and some technical symbols. If you are using a Mac you can choose File > Print > Save As PDF as a workaround.

Riparian answered 13/9, 2011 at 13:18 Comment(1)
It is possible to print to PDF on Windows too (by using a virtual PDF printer). This process in the case of Mathematica FrontEnd goes through creation of temporary high-resolution EMF file in the printer's spool.Symptom

© 2022 - 2024 — McMap. All rights reserved.