是否有可用于将整个页面转换为图像的软件?
pdftoppm input.pdf outputname -png
outputname-01.png
输出PDF中的每一页,其中01
是页面的索引。
pdftoppm input.pdf outputname -png -f {page} -singlefile
{page}
更改为页码。索引从1开始,所以-f 1
表示第一页。-l
(最后一页)指定一个数字,例如-f 1 -l 30
表示从第1页到第30页。.png
将自动添加到outputname
,因此无需包含扩展名。另外,-singlefile
会删除上述提到的-01
后缀,因为输出已知只有一个文件。-rx {resolution}
和-ry {resolution}
。例如:pdftoppm input.pdf outputname -png -rx 300 -ry 300
pdftoppm -png *.pdf 前缀
- user47206-r 300
比单独指定x和y分辨率要简单一些。 - mlcpdftohtml
(列在pdftoppm
手册的末尾)对我的使用情况更有效;谢谢你的提示 :-) - Abbafeipdftocairo -png page.pdf page.png
- turdus-merulabrew install poppler
。 - Pavel Vlasovpdftoppm myfile.pdf myfile -png && zip myfile.cbz myfile-*.png; rm myfile-*.png
。这将在与"myfile.pdf"相同的目录中生成一个名为"myfile.cbz"的文件。 - IBBoardFILE=无扩展名的文件名; pdftoppm $FILE.pdf $FILE -png && zip $FILE.cbz $FILE-*.png; rm $FILE-*.png
。这将在与"无扩展名的文件名.pdf"相同的目录中生成一个"无扩展名的文件名.cbz"文件。 - IBBoard-r 300
等来指定分辨率,以及 JPEG 压缩(质量)级别。请参阅我的完整答案和示例:https://askubuntu.com/questions/150100/extracting-embedded-images-from-a-pdf/1187844#1187844 - Gabriel Staplespdftoppm
。 - Zoltánpdftoppm
将背景设置为白色,并使用convert
将其设置为透明,但是即使我在policy.xml
中增加内存限制,convert
在处理大型PDF时仍然存在问题。 - Roahcairo
比ppm
更容易出现bug。 - Yai0Phah-cropbox
选项导出的页面与我预期的一样,如果您不喜欢初始结果,请尝试使用此选项。 - Denilson Sá Maiasudo apt update
,然后运行sudo apt install poppler-utils
。 - Avatar-scale-to 300
。这将生成一个最大高度为 300 像素的 PNG 图像。参数 -r
表示“图像的粗糙程度”,而 -scale-to
则表示图像的整体尺寸(一侧)。详见链接:https://askubuntu.com/a/1179820/238253 - Avatarconvert -trim
来去除空白,因为-cropbox对我不起作用。 - SurpriseDogpdftoppm
已经默认安装在Ubuntu 23.04上! - Dan Doe安装imagemagick。
在PDF所在的终端中执行以下命令:
转换整个文档:
convert -density 150 input.pdf -quality 90 output.png
转换单独一页:
convert -density 150 input.pdf[666] -quality 90 output.png
具体来说:
可以选择PNG、JPG或(几乎)任何其他图像格式。
-density xxx
将DPI设置为 xxx
(常见的是150和300)。
-quality xxx
将PNG、JPG和MIFF文件格式的压缩设置为 xxx
(100表示无压缩)。
[666]
仅将第667页转换为PNG(从零开始编号,因此[0]
是第一页)。
所有其他选项(如修剪、灰度等)都可以在Image Magic的网站上查看。
gs -q NOPROMPT ...-sDEVICE=pngalpha -r150x150 -sOutputFile=/var/tmp/Yf%d -f/var/tmp/L -f/var/tmp/Fic1
如果你收到了convert: no images defined output.png
这样的消息,那意味着你没有安装ghostscript... - rogerdpack-density 500 -quality 100
,与_pdftoppm_相比,我仍然得到了较差的图像质量。 - frozen-flameconvert output-0.png output-1.png output-2.png output.pdf
。详情请参考:https://itsfoss.com/convert-multiple-images-pdf-ubuntu-1304/。 - Gabriel Staplesconvert-im6.q16: not authorized 'test.pdf' @ error/constitute.c/ReadImage/412.
- Joschuaconvert-im6.q16: no images defined 'output.png' @ error/convert.c/ConvertImageCommand/3258
。我知道@rogerdpack已经提到过这个问题,但是我已经安装了Ghostscript,我可以使用gs
。 - hsandt/etc/ImageMagick-7/policy.xml
文件并从<policy domain="coder" rights="none" pattern="{PS,PS2,PS3,EPS,PDF,XPS}" />
中移除PDF
来启用。 - Jezor-background white -alpha off
来去除透明度。 - Martin Thoma当前被接受的答案能够完成任务,但生成的输出文件较大且质量有所损失。
这个回答中提供的方法在这里生成的输出文件与输入文件大小相当,并且不会有质量损失。
TLDR - 使用pdfimages
命令: pdfimages -j 输入.pdf 输出
引用链接中的回答:
It's not clear what you mean by "quality loss". That could mean a lot of different things. Could you post some samples to illustrate? Perhaps cut the same section out of the poor quality and good quality versions (as a PNG to avoid further quality loss).
Perhaps you need to use
-density
to do the conversion at a higher dpi:convert -density 300 file.pdf page_%04d.jpg
(You can prepend
-units PixelsPerInch
or-units PixelsPerCentimeter
if necessary. My copy defaults to ppi.)Update: As you pointed out,
gscan2pdf
(the way you're using it) is just a wrapper forpdfimages
(from poppler).pdfimages
does not do the same thing thatconvert
does when given a PDF as input.
convert
takes the PDF, renders it at some resolution, and uses the resulting bitmap as the source image.
pdfimages
looks through the PDF for embedded bitmap images and exports each one to a file. It simply ignores any text or vector drawing commands in the PDF.As a result, if what you have is a PDF that's just a wrapper around a series of bitmaps,
pdfimages
will do a much better job of extracting them, because it gets you the raw data at its original size. You probably also want to use the-j
option topdfimages
, because a PDF can contain raw JPEG data. By default,pdfimages
converts everything to PNM format, and converting JPEG > PPM > JPEG is a lossy process.So, try
pdfimages -j file.pdf page
You may or may not need to follow that with a
convert
to.jpg
step (depending on what bitmap format the PDF was using).I tried this command on a PDF that I had made myself from a sequence of JPEG images. The extracted JPEGs were byte-for-byte identical to the source images. You can't get higher quality than that.
pdfimages
工具提取它们即可。pdfimages my-file.pdf prefix
pdftk
命令与convert
命令(如上所述described above)进行连接,示例如下:pdftk document.pdf cat 12 output - | convert - document-page-12.png
convert -d 300 foo.pdf bar.png
gm convert foo.pdf[11] out.png
将获取PDF的第12页。-f N -singlefile
,其中N是从1开始的页码,例如pdftoppm -f 12 -singlefile foo.pdf out
可以得到相同的结果。它似乎总是在输出文件名后面添加“.png”,没有办法停止这个行为。gs -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=png16m -dFirstPage=1 -dLastPage=1 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=output.png input.pdf
mutool convert -o file.png file.pdf
- user3413723pdftocairo file.pdf -png
- Anthony Ebert