2
$\begingroup$

When Importing in Mathematica (v10.3) a pdf file containing some text, the text is "vectorialized", meaning that it does not seem to be loaded as text, and re-exporting the imported file produces a file in which the text is not selectable.

Consider for example the following code:

Export["test.pdf",
 Plot[x, {x, 0, 1}]
 ]
Export["test2.pdf",Import["test.pdf"]]

As you can test, while the text in test.pdf can be selected, the text in test2.pdf cannot, and opening it for example with Inkscape shows that it is not really exported as text.

How can I import the text in external pdf files as text?

$\endgroup$
  • $\begingroup$ From the Docs: Import["test.pdf", "TextOutlines" -> False]. $\endgroup$ – Alexey Popkov Dec 1 '15 at 13:38
  • $\begingroup$ @AlexeyPopkov somehow I missed that on the docs, thanks! $\endgroup$ – glS Dec 1 '15 at 13:44
  • $\begingroup$ @AlexeyPopkov now that was useful for me, too (never needed before, but filed for future reference). How about answering anyway? Personally, I would be in favor of reopening, as this may be useful for others. $\endgroup$ – Yves Klett Dec 1 '15 at 18:26
  • 1
    $\begingroup$ @YvesKlett I will post an answer if the question will be reopened. Actually I thought that this option is widely known (it is used in many answers on this site). But if an experienced user like you find it useful I think we should reopen the question! Also, not every PDF file can be imported correctly with this option, but it is another and quite long story... I'm voting to reopen. $\endgroup$ – Alexey Popkov Dec 1 '15 at 20:08
  • $\begingroup$ Looking forward to your answer 😊 $\endgroup$ – Yves Klett Dec 1 '15 at 20:52
3
$\begingroup$

According to the Documentation page for PDF format (under the "Options" section) there is "TextOutlines" option which controls "whether to import characters as outlines". You should set it to False for importing text as characters instead of outlines:

Import["test.pdf", "TextOutlines" -> False]

Note that this feature can work incorrectly when characters inside of a PDF file have nonstandard encoding. Due to this reason it usually incorrectly imports non-ASCII characters, for example:

ImportString[ExportString["αβγ", "PDF"], "PDF", "TextOutlines" -> False]

screenshot

At the same time I seem to remember situations when Import correctly recognized Greek letters in PDF files NOT created by Mathematica. I guess that this is encoding issue.

$\endgroup$

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.