正确将pdf转换为ps,反之亦然 [英] Converting correctly pdf to ps and vice-versa

查看:159
本文介绍了正确将pdf转换为ps,反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用"pdftops"将.pdf文件转换为.ps文件,然后使用"ps2pdf"进行反向处理(poppler-utils).问题是,从.ps文件创建.pdf文件时,文本看起来不错,但是当我尝试复制文本时,字符非常奇怪(就像它们已损坏).我在其他文件上使用了很长时间,效果很好. 我还尝试了"pdftohtml -xml"来创建一个.xml文件,并且文本没有问题(正确提取了字符).

  1. 与转换有关的问题是什么?也许如果我使用"pdftops"和"ps2pdf",是否需要更改某些选项?
  2. 如果我创建.xml输出,是否可以从.xml文件创建.pdf文件?

"pdffonts original.pdf"的输出

"roundtripped.pdf"的输出

解决方案

我只是介绍PS-> PDF转换...(我假设您的 vice-versa 短语不是并不是要指向相同文件[PDF-> PS-> PDF]的往返" 转换,而是 any 转换的一般方向PS文件,对吗?)

首先,很可能您的ps2pdf只是一个shellscript,它在内部使用带有一些默认参数的Ghostscript命令来完成实际工作. ps2pdf易于使用. Ghostscript有更多选择,但学习起来更加困难. ps2pdf如果使用了Ghostscript,它将带走很多潜在的控制权. (您可以使用ps2pdf调整一些参数-但现在您已经可以运行真正的Ghostscript命令了……)

第二,在不完全知道PS输入文件的条件如何的情况下,很难向您提供好的建议:您的PS是否嵌入了它使用的字体?它们是哪种字体?等等

第三,在过去的几年中,Ghostscript获得了许多额外的功能和控制,并且在输出PDF时消除了一些错误或弱点.那么,是您系统上安装的Ghostscript的版本吗?(请记住,ps2pdf调用Ghostscript,如果没有本地安装的gs可执行文件,它将无法工作.)

您可能无法从PDF复制文本的一个可能原因可能是最终使用并嵌入到PDF文件中的字体类型(和编码). 您能告诉我们哪些字体详细信息?(尝试pdffonts your.pdf找出- pdffonts 也是您提到的Poppler实用程序的一部分.)

您可以尝试使用此(完整的)Ghostscript命令进行PS-> PDF转换,并检查将您带到何处:

gs \
  -o output.pdf \
  -sDEVICE=pdfwrite \
  -dPDFSETTINGS=/prepress \
  -dHaveTrueTypes=true \
  -dEmbedAllFonts=true \
  -dSubsetFonts=false \
  -c ".setpdfwrite <</NeverEmbed [ ]>> setdistillerparams" \
  -f input.ps

I'm using "pdftops" to convert .pdf files to .ps files and then "ps2pdf" for the reverse process (poppler-utils). The problem is that when creating the .pdf files from the .ps files, the text looks ok, but when i try to copy it, the characters are very strange (it's like they are corrupted). I used these tools on other files for a long time and it worked fine. I also tried "pdftohtml -xml" to create an .xml file, and the text is ok (the characters are extracted correctly).

  1. What problem could it be regarding the conversion? Maybe if I use "pdftops" and "ps2pdf" are there some options that need to be changed?
  2. If I create the .xml output, is there a way to create a .pdf file from the .xml file ?

EDIT: Output for "pdffonts original.pdf"

Output for "roundtripped.pdf"

解决方案

I'm just covering the PS->PDF conversion... (I'm assuming your phrase of vice-versa isn't meant to point to a 'round-trip' conversion of the very same file [PDF->PS->PDF], but the general direction of conversion for any PS file. Is that correct?)

First of all, most likely your ps2pdf is only a shellscript, which internally uses a Ghostscript command with some default parameters to do the real work. ps2pdf is much easier to use. Ghostscript has many more options, but it is more difficult to learn. ps2pdf it takes away a lot of potential control you could have if you used Ghostscript. (You can tweak a few parameters with ps2pdf -- but then you are already so much closer to run the real Ghostscript command already...)

Second, without exactly knowing how exactly your PS input file is conditioned, it is difficult to give you good advice: Does your PS have embedded the fonts it uses? Which type of fonts are they? etc.

Thirdly, Ghostscript gained a lot of additional power and control, and had a few bugs or weak spots removed over the last few years when it comes to outputing PDF. So, which is the version of Ghostscript installed on your system? (Remember, ps2pdf calls Ghostscript, it will not work without a locally installed gs executable.)

One likely cause for your inability to copy text from the PDF could be the font type (and encoding) that ended up being used and embedded in your PDF file. Which font details can you tell us about your resulting PDFs? (Try pdffonts your.pdf to find out -- pdffonts is also part of the Poppler utils you mentioned.)

You may try this (full) Ghostscript command for PS->PDF conversion and check where it takes you:

gs \
  -o output.pdf \
  -sDEVICE=pdfwrite \
  -dPDFSETTINGS=/prepress \
  -dHaveTrueTypes=true \
  -dEmbedAllFonts=true \
  -dSubsetFonts=false \
  -c ".setpdfwrite <</NeverEmbed [ ]>> setdistillerparams" \
  -f input.ps

这篇关于正确将pdf转换为ps,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆