1

I have a pdf file, whose text can be shown correctly in evince, but not when text are searched or copied and pasted outside the file. For example, "external transportation." is copied and pasted outside as

2D/28:93 /89:4758/9/.5:

I created the pdf file from the original version of the pdf file which works correctly, by

gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile=example.pdf original.pdf

The command is my general way to repair various problems in a pdf file (especially font problems in pdf files created on Windows).

  1. Why does the command create the problem? How shall I change the command, as a general way to fix pdf problems?
  2. How shall I repair the current version of the pdf file, so that the correct text can be searched and copied and pasted outside? The file I am actually interested in repairing was created in the same way and with additional modifications. I want to repair it, so that I can keep the modifications.

Thanks.

  • 3
    @Tim, it is up to you to determine which conversion step corrupted the pdf file ... we cannot do it for you .... in the future, please include the information, that you posted in the comment, in your question – jsotola Jun 6 at 23:25
  • 5
    Tim, consider someone who wants to help. You're saying: "I have an original file that works correctly. I do some combination of steps, combine it with other files, do some conversions, and now it's corrupted." How much effort do you expect Answerers to undergo, when you could certainly narrow the range considerably? – Jeff Schaller Jun 7 at 0:21
  • 2
    I'm no PDF expert, but is it possible to provide the original ("correct") PDF so that Answerers can re-run your commands in order to reproduce the issue? – Jeff Schaller Jun 7 at 1:31
  • 2
    I can confirm that the gs command you gave creates a PDF with the problem you describe. So why are you running that gs command? Why not just use the original file? Does that also have some issue? – terdon Jun 8 at 13:32
  • 2
6

I did some reading and some helpful posts on Stack Overflow (1, 2, 3) seem to suggest that the issue is with the specific fonts embedded in your PDF file. Your original file uses these fonts:

$ pdffonts original.pdf 
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
KPSHBO+Wingdings                     TrueType          Custom           yes yes no       5  0
KNQZHK+Arial                         TrueType          Custom           yes yes no       9  0
YLWHHJ+TimesNewRoman                 TrueType          Custom           yes yes no      13  0
HWNDJR+ArialBlack                    TrueType          Custom           yes yes no      17  0
QQRMEC+TimesNewRoman,Bold            TrueType          Custom           yes yes no      21  0

I am guessing (but don't know for sure) that the problem is most likely caused by the Wingdings font. Presumably you don't have it on your system. At least, of the fonts listed, that's the only one I can't find on mine:

$ fc-list | grep -f <(pdffonts original.pdf | grep -oP '\+\K[A-Z][a-z]+') | awk '{print $1}'
/usr/share/fonts/TTF/times.ttf:
/usr/share/fonts/TTF/arialbd.ttf:
/usr/share/fonts/TTF/ariblk.ttf:
/usr/share/fonts/TTF/arialbi.ttf:
/usr/share/fonts/TTF/ariali.ttf:
/usr/share/fonts/TTF/timesi.ttf:
/usr/share/fonts/TTF/timesbd.ttf:
/usr/share/fonts/TTF/timesbi.ttf:
/usr/share/fonts/TTF/arial.ttf:

Unfortunately, I tried downloading a Wingdings font from here, then ran:

unzip wingdings.zip 
sudo cp Wingdings\ Regular.ttf /usr/share/fonts/TTF/Wingdings.ttf
fc-cache

Which should have installed the font, but the gs command still didn't work. So perhaps gs's pdfwrite can't deal with this font at all. So I don't know if there's a way of getting gs to convert your file correctly. Perhaps simply using the original which doesn't have this problem is your only choice.

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.