Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 249
Igor Avatar asked Jun 16 '11 07:06

Igor


1 Answers

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"]]
like image 185
Alexey Popkov Avatar answered Sep 20 '22 22:09

Alexey Popkov