简体   繁体   English

使用 imagemagick 无损旋转 PDF 文件

[英]Lossless rotation of PDF files with imagemagick

I want to rotate a 351K PDF named 08-file.pdf using CLI tools.我想使用 CLI 工具旋转名为08-file.pdf的 351K PDF。 I've tried imagemagick :我试过imagemagick

convert 08-file.pdf -rotate 90 08-file-rotated.pdf

But the original quality:但原始质量:

在此处输入图片说明

Suffered serious degradation:遭受严重退化:

在此处输入图片说明

I've tried adding the -density 300x300 argument , but the outcome was a 2.5M file, nearly one order of magnitude larger than the original, which is a huge waste. 我已经尝试添加-density 300x300参数,但结果是一个 2.5M 的文件,比原始文件大近一个数量级,这是一种巨大的浪费。

Any idea how to losslessly rotate a PDF file using imagemagick?知道如何使用 imagemagick 无损旋转 PDF 文件吗?

11/I always had bad results in converting/altering pdf file with imagemagik/convert (bad resolution, or huge file). 11/我在使用 imagemagik/convert 转换/更改 pdf 文件时总是有不好的结果(分辨率差或文件大)。 Playing with options -compress -density -quality was always frustrating and a waste of time (but i am no expert).使用选项-compress -density -quality总是令人沮丧和浪费时间(但我不是专家)。

Proposal 1: pdftk建议1:pdftk

So I would recommend pdftk (you may need to install it via apt-get install)所以我会推荐pdftk (你可能需要通过 apt-get install 安装它)

Try :尝试:

pdftk  08-file.pdf cat 1-endright output 08-file-rotated.pdf

For old version of pdftk (v<3) rotation was indicated only by one letter: N: 0, E: 90, S: 180, W: 270, L: -90, R: +90, D: +180.对于旧版本的 pdftk (v<3) 旋转仅由一个字母表示:N:0,E:90,S:180,W:270,L:-90,R:+90,D:+180。 The same command was:相同的命令是:

pdftk  08-file.pdf cat 1-endR output 08-file-rotated.pdf

From another post on this site, I have a brief an explanation of the syntax从本网站的另一篇文章中,我对语法进行了简要说明

pdftk input.pdf cat 1-endsouth output output.pdf
#     \_______/     \___/\___/        \________/
#     input file    range  |          output file
#                         direction

You can see also https://linux.die.net/man/1/pdftk你也可以看到https://linux.die.net/man/1/pdftk

Edit 2020 : 2020年编辑

Proposal 2: qpdf建议2:qpdf

I have found another alternative which is equivalent: qpdf , easier to remember and more powerful我找到了另一种等效的替代方法: qpdf ,更容易记住且功能更强大

see QPDF manual参见QPDF 手册

#Syntax (you can rotate only some pages of the document -- see the manual --
qpdf --rotate=[+|-]angle[:page-range]

# Example
qpdf in.pdf out.pdf --rotate=+180

Please use -compress lossless option:请使用-compress lossless选项:

convert -rotate 90 -compress lossless 08-file.pdf 08-file-rotated.pdf

From the documentation: https://www.imagemagick.org/script/command-line-options.php#compress从文档: https : //www.imagemagick.org/script/command-line-options.php#compress

Lossless refers to lossless JPEG, which is only available if the JPEG library has been patched to support it. Lossless 是指无损 JPEG,只有在 JPEG 库已被修补以支持它时才可用。

Another option is to use the following command:另一种选择是使用以下命令:

jhead -cmd "jpegtran -progressive -perfect -rotate 270 &i > &o" Image-0001.jpeg jhead -cmd "jpegtran -progressive -perfect -rotate 270 &i > &o" Image-0001.jpeg

It will write output to a temporary file and when it succeeds it will overwrite the original file:它将输出写入临时文件,成功后将覆盖原始文件:

Cmd:jpegtran -progressive -perfect -rotate 270 "Image-0001.jpeg" > "h1xQ6q" Cmd:jpegtran -progressive -perfect -rotate 270 "Image-0001.jpeg" > "h1xQ6q"

Modified: Image-0001.jpeg修改:Image-0001.jpeg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM