How do I embed fonts in an existing PDF?

此生再无相见时 提交于 2019-11-27 20:27:54

This may not be the answer you are looking for (since you want to get your problems solved programmatically, not by an external tool).

But you can use Ghostscript commandline to embed missing fonts in retrospect to PDFs which have not embedded them:

gs \
  -sFONTPATH=/path/to/fonts:/another/dir/with/more/fonts \
  -o output-pdf-with-embedded-fonts.pdf \
  -sDEVICE=pdfwrite \
  -dPDFSETTINGS=/prepress \
   input-pdf-where-some-fonts-are-not-embedded.pdf

One important thing is that the missing fonts are all available in one of the directories pointed to by the -sFontPath=... switch.

Besides Ghostscript, it is also possible to use Poppler and Cairo. There is a command pdftocairo from Poppler that converts PDF to PDF via pdftocairo -pdf input.pdf output.pdf. It also considers font substitutions set in a Fontconfig configuration file. This is very helpful if you do not have all fonts on your system that are referenced in a PDF file, but know which other font you have installed is a good-looking replacement. After processing, the substitution font is embedded.

I had this problem on a Mac with a PDF I was submitting to IEEE. Using Adobe Reader and Preview, I was able to get around this. I think any pdf printer might work in place of Preview if you are on a PC.

Here are the steps I took. You can individually fix each figure, or fix the whole document.

  1. Open at pdf file using Adobe Reader.

  2. Right click on image, and click “Document Properties.”

  3. Click “Fonts.” Check to see if the font isn’t embedded. Should say “Courier” or other font name.

  4. If your pdf isn’t a standard page size, click on “Description” and look at the page size. Write this down. Ex. 19.4 x 5.22 in.

  5. Open the pdf up in Preview. Go to File->Print. If using a pdf that isn’t a standard page size, click on Paper Size and choose custom. You will need to create a custom page size that is equal to the one you wrote down in step 4. Don’t forget to zero the margins to 0 for all sides. After doing that, you’ll need to set the scale of the print in the print dialog to 100%.

  6. In the lower left of the print dialog (in Preview on a Mac), click “PDF” to print the PDF to a new PDF. Select the destination and print.

  7. Open the new pdf up in Adobe Reader and verify that the fonts are now embedded.

I hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!