将多页PDF转换为PNG并返回(Linux) [英] Convert multipage PDF to PNG and back (Linux)

查看:303
本文介绍了将多页PDF转换为PNG并返回(Linux)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多PDF文档要转换为PNG,在Gimp中编辑,然后保存回多页Acrobat文件。我正在填写表格并添加扫描签名,试图避免打印,签名,然后重新扫描,并能够输入我需要输入的信息。

I have a lot of PDF documents that I want to convert to PNG, edit in Gimp, and then save back to the multipage Acrobat file. I'm filling out forms and adding scanned signature, trying to avoid printing, signing, then scanning back in, with the ability to type the information I need to enter.

我一直在尝试使用Imagemagick转换为png文件,这似乎工作正常。我使用命令 convert -quality 100 -density 300x300 multipage.pdf single%d.png

(我不确定质量是否参数适合png)。

I've been trying to use Imagemagick to convert to png files, which seems to work fine. I use the command convert -quality 100 -density 300x300 multipage.pdf single%d.png
(I'm not really sure if the quality parameter is right for png).

但是我遇到了保存回PDF的问题。有些文件的页面大小错误,我已经尝试了我能找到的每个命令和程序,但总有一些奇怪的大小。分辨率似乎有所不同,因此它在某个缩放级别看起来很好,但是几页指定为大约2宽,或者它们是8.5x11但其他页面大约是35宽。我已经尝试确保Gimp的画布大小和分辨率正确,并将分辨率保存在文件中,但这似乎并不重要。

But I'm having problems with saving back to PDF. Some of the files have the wrong page size, and I've tried every command and procedure I can find, but there are always a few odd sizes. The resolution seems to vary so that it looks good at a certain zoom level, but either a few pages are specified at about 2" wide, or they are 8.5x11 but the others are about 35" wide. I've tried making sure Gimp had the canvass size and resolution correct, and to save the resolution in the file, but that doesn't seem to matter.

命令我用来保存文件是 convert -page letter -adjoin single * .png multipage.pdf 我已经尝试了其他参数,但似乎都不重要。

The command I use to save the files is convert -page letter -adjoin single*.png multipage.pdf I've tried other parameters, but none seemed to matter.

如果有人有任何想法或替代方案,我会很感激。

If anyone has any ideas or alternatives, I'd appreciate it.

推荐答案


我不确定质量参数是否适合PNG。

对于PNG输出, -quality 设置与JPEG的质量设置非常不同(它只是 0 100 )。

For PNG output, the -quality setting is very unlike JPEG's quality setting (which simply is an integer from 0 to 100).

对于PNG,它由两位数组成:

For PNG it is composed by two single digits:


  • 第一个数字(十位)(很大程度上)是zlib压缩级别,它可能来自 0 9

    (但是 0 的设置有一个特殊的含义:当你使用它时,你将获得Huffman压缩,而不是zlib压缩级别0.这通常更好......很奇怪,但却是真的。)

  • The first digit (tens) is (largely) the zlib compression level, and it may go from 0 to 9.
    (However the setting of 0 has a special meaning: when you use it you'll get Huffman compression, not zlib compression level 0. This is often better... Weird but true.)

第二个数字是 PNG数据编码过滤器类型(在压缩之前) :

The second digit is the PNG data encoding filter type (before it is compressed):


  • 0是无,

  • 1是sub,

  • 2为up,

  • 3为average,

  • 4为Paeth,

  • 5是自适应。

  • 0 is none,
  • 1 is "sub",
  • 2 is "up",
  • 3 is "average",
  • 4 is "Paeth", and
  • 5 is "adaptive".

实际上,这意味着:


  • 对于具有固定颜色序列的插图,无过滤器( -quality 00 )通常是最合适的。

  • 对于自然景观的照片,自适应过滤( -quality 05 )通常是最好的。

  • For illustrations with solid sequences of color a "none" filter (-quality 00) is typically the most appropriate.
  • For photos of natural landscapes an "adaptive" filtering (-quality 05) is generally the best.

我在保存回PDF时遇到问题。有些文件的页面大小错误,我已经尝试了我能找到的每个命令和程序[...],但是大约2英寸宽的指定页面,或者它们是8.5x11,但其他页面是关于35宽。

没有可用的PNG文件,我创建了一些具有不同尺寸的简单文件来验证不同的命令(因为我不再确定自己了)。确实,你使用过的那个:

Not having available your PNG files, I created a few simple ones with different dimensions to verify the different commands (as I wasn't sure myself any more). Indeed, the one you used:

convert -page letter -adjoin single*.png multipage.pdf

确实以(相同)字母大小创建所有PDF页面,但是我的(不同大小的)PNG样本总是放在PDF页面的左下角。(如果PNG超过PDF页面大小,它会缩小它们以使它们适合 - 但它不会扩展较小的PNG以填充可用的页面空间。)

does create all PDF pages in (same) letter size, but it places my sample of (differently sized) PNGs always on the lower left corner of the PDF page. (Should a PNG exceed the PDF page size, it does scale them down to make them fit -- but it doesn't scale up smaller PNGs to fill the available page space.)

对命令的以下修改将PNG放入每个PDF页面的中心:

The following modification to the command will place the PNGs into the center of each PDF page:

convert           \
  -page letter    \
  -adjoin         \
   single*.png    \
  -gravity center \
   multipage.pdf

如果这还不够好,你可以强制执行a(可能是非比例!)通过添加 -scale'590!x770!'参数(这将留下11 pt的边界)几乎填充字母区域每页边缘):

If this is still not good enough for you, you can enforce a (possibly non-proportional!) scaling to almost fill the letter area by adding a -scale '590!x770!' parameter (this will leave a border of 11 pt at each edge of the page):

convert              \
  -page letter       \
  -adjoin            \
   single*.png       \
  -gravity center    \
  -scale '590!x770!' \
   multipage.pdf

要省去额外的边框,请使用 -scale'612!x792!'。 - 如果您需要在保持PNG宽高比的同时仅需要向上缩放,请使用 -scale'590< x770<'

To leave away the extra border, use -scale '612!x792!'. -- Should you want only upward scaling to happen if required while keeping the aspect ratio of the PNG, use -scale '590<x770<':

convert              \
  -page letter       \
  -adjoin            \
   single*.png       \
  -gravity center    \
  -scale '590<x770<' \
   multipage.pdf 

这篇关于将多页PDF转换为PNG并返回(Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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