如何更改PDF的页面方向? (需要Ghostscript或PostScript解决方案) [英] How to change page orientation of PDF? (Ghostscript or PostScript solution needed)

查看:543
本文介绍了如何更改PDF的页面方向? (需要Ghostscript或PostScript解决方案)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出PDF文档,如何更改单个页面的方向?

Given a PDF document, how do I change individual page orientation?

我正在使用最新版本的Ghostscript.

I'm using latest version of Ghostscript.

推荐答案

为什么 要求 使用Ghostscript?是否可以使用在命令行上运行的另一个免费,开放源代码软件工具,例如pdftk?

无论如何,这是如何使用Ghostscript旋转页面.但是,这可能无法满足您的意图,因为您不能仅针对单个页面强行.它依赖于内部的Ghostscript算法,该算法会尝试自动旋转页面,具体取决于PDF内文本的流向:
* -dAutoRotatePages=/None-保留每页的方向;
* -dAutoRotatePages=/All-根据一种多数决定"来轮换所有页面(或不旋转);
* -dAutoRotatePages=/PageByPage-分别自动旋转页面.

Anyway, here is how to rotate pages with Ghostscript. However, this may not work for your intentions, because you cannot force a certain orientation for an individual page only. It relies on an internal Ghostscript algorithm that tries to rotate pages automatically, depending on the flow of text inside the PDFs:
* -dAutoRotatePages=/None -- retains orientation of each page;
* -dAutoRotatePages=/All -- rotates all pages (or none) depending on a kind of "majority decision";
* -dAutoRotatePages=/PageByPage -- auto-rotates pages individually.

将其中之一添加到您正在使用的Ghostscript命令行中.

Add one of these to the Ghostscript commandline you're using.

如果页面上没有 文本(或者如果将自动页面旋转设置为/None),则Ghostscript使用setpagedevice设置.您可以使用-c开关在Ghostscript命令行上传递这样的setpagedevice参数,如下所示:
* -c "<</Orientation 3>> setpagedevice"-设置 landscape 方向;
* -c "<</Orientation 0>> setpagedevice"-设置人像方向;
* -c "<</Orientation 2>> setpagedevice"-设置倒置方向;
* -c "<</Orientation 1>> setpagedevice"-设置海景方向.

If there is no text on a page (or if there is an automatic page rotation set to /None), then Ghostscript uses the setpagedevice settings. You can pass such setpagedevice parameters on the Ghostscript commandline using the -c switch like this:
* -c "<</Orientation 3>> setpagedevice" -- sets landscape orientation;
* -c "<</Orientation 0>> setpagedevice" -- sets portrait orientation;
* -c "<</Orientation 2>> setpagedevice" -- sets upside down orientation;
* -c "<</Orientation 1>> setpagedevice" -- sets seascape orientation.

提取页面时,可能需要为每个页面设置方向.我认为将它们合并回统一文档中不会起作用(我从未测试过).

Probably you need to set the orientation for each page when extracting the pages. I don't think it would work when merging them back to the unified document (I have never tested this).

在任何情况下,我都建议您也查看pdftk(Windows也可用).这是一个命令行工具,可以旋转PDF中的页面等等.比起Ghostscript而言,它更容易实现您指定的目的,并且速度也快得多.特别是,它可以旋转PDF文档中的各个页面,而其他页面保持不变. 示例:

In any case, I'd recommend to look at pdftk too (which is also available for Windows). It is a commandline tool that can rotate pages from PDFs, and much more. Easier to use than Ghostscript for your stated purpose, and much faster as well. Especially, it can rotate individual pages inside a PDF document, leaving the other pages untouched. Example:

pdftk A=in.pdf           \
  cat A1-3 A4west A5-end \
  output out.pdf

此命令将输出第1、2和3页以及第5、6,...页,最后一次不旋转,但会将第4页旋转90度(因此,页眉朝向西"). (但是,请注意,此命令可能会导致意外结果,具体取决于输入页面的原始方向:您应该通过运行pdfinfo -l 1000 input.pdf来检查输入PDF的所有页面的方向,然后检查其值rot输出的内容:如果您看到与0不同的值,例如90180270,则这些页面已经被预旋转...)

This command will output pages 1, 2 and 3 as well as pages 5, 6, ... last un-rotated, but will rotate page 4 by 90 degrees (so the page header faces to the "west"). (However, be aware that this command can lead to unexpected results, depending on the original orientation of your input pages: You should check the orientation of all pages of your input PDF by running pdfinfo -l 1000 input.pdf and then check for the value of the rot output: if you see values different from 0, like 90, 180 and 270, these pages are already pre-rotated...)

有关更多详细信息,请参见此处: http://www.accesspdf.com/pdftk/.

See here for more details: http://www.accesspdf.com/pdftk/ .

这篇关于如何更改PDF的页面方向? (需要Ghostscript或PostScript解决方案)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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