ghostscript裁剪pdf不正确 [英] ghostscript crop pdf not correctly

查看:100
本文介绍了ghostscript裁剪pdf不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

inputPdf

使用gswin32c.exe -o nul -sDEVICE=bbox bbox.pdf,我知道此pdf的边界框是

Use gswin32c.exe -o nul -sDEVICE=bbox bbox.pdf,I'v hnow the BoundingBox of this pdf is

%% BoundingBox:6292 6865 8108 7535

%%BoundingBox: 6292 6865 8108 7535

%% HiResBoundingBox:6292.907808 6865.505790 8107.091753 7534.493770,

%%HiResBoundingBox: 6292.907808 6865.505790 8107.091753 7534.493770,

我想获取一个包含BoundingBox中内容的pdf文件.

I want to get a pdf with the content in the BoundingBox.

我正在使用以下命令来裁剪PDF:

I am using the following command to crop a PDF:

 gswin32c -sDEVICE=pdfwrite -dFirstPage=1 -dLastPage=1 -o croped.pdf -dDEVICEWIDTHPOINTS=1815 -dDEVICEHEIGHTPOINTS=670 -dFIXEDMEDIA -c "6292 6865 translate 6292 6865 8107 7534 rectclip" -f bbox.pdf

gswin32c -dQUIET -dBATCH -dNOPAUSE -dNOPROMPT -sDEVICE=pdfwrite -dFirstPage=1 -dLastPage=1 -o croped.pdf -dDEVICEWIDTHPOINTS=1815 -dDEVICEHEIGHTPOINTS=670 -dFIXEDMEDIA -c "<</PageOffset [6292 6865]>> setpagedevice" -f bbox.pdf

我是一个空白的pdf文件.

i'v a blank pdf file.

此命令

gswin32c.exe -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=croped.pdf -c "[/CropBox [6292.907808 6865.505790 8107.091753 7534.493770] /PAGES pdfmark" -f bbox.pdf

我是原始文件.

我如何正确裁剪此pdf文件.

How can i crop this pdf correctly.

非常感谢!

推荐答案

BoundingBox对我来说可疑.

The BoundingBox looks suspicious to me.

在任何情况下,您都不能轻易使用Ghostscript进行操作,因为PDF解释器会使用PDF文件中的信息来设置媒体大小.

In any event you cannot trivially do what you are trying to do with Ghostscript, because the PDF interpreter uses the information in the PDF file to set the media size.

前两个命令行可能"起作用,但是您在错误的方向上转换了CTM.您已从左下,上,右移动原点(0,0).这将页面的内容移到了媒体之外,这就是为什么您会得到空白页面的原因.您可以尝试使用相同的值,但取反,以便原点向下和向左移动.在您引用的BoundingBox中,这是正确的方向.

The first two command lines 'might' work, but you've translated the CTM in the wrong direction. You've moved the origin (0,0) from the bottom left, up and right. That's moved the content of the page further off the media, which is why you get a blank page. You could try using the same values, but negated, so that the origin moves down and left. From the BoundingBox you quoted, that's the correct direction.

gswin32c -sDEVICE=pdfwrite -dFirstPage=1 -dLastPage=1 -o croped.pdf -dDEVICEWIDTHPOINTS=1816 -dDEVICEHEIGHTPOINTS=670 -dFIXEDMEDIA -c "-6292 -6865 translate" -f bbox.pdf

您不需要rectclip,因为内容已被裁剪到页面上.

You don't need the rectclip, because the content is already clipped to the page.

除了在处理PDF文件之前设置了CropBox,第三条命令行也将起作用,因此PDF解释程序将从PDF文件读取CropBox并覆盖您设置的CropBox.尝试在输入文件之后进行设置.

The third command line would also work, except that you've set the CropBox before processing the PDF file, so the PDF interpreter reads the CropBox from the PDF file and overwrites the one you set. Try setting it after the input file.

gswin32c.exe -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=croped.pdf bbox.pdf -c "[/CropBox [6292.907808 6865.505790 8107.091753 7534.493770] /PAGES pdfmark" -f

好的,所以第一个命令行不起作用的原因是(正如我所怀疑的),因为PDF解释器在运行PDF之前会重置图形状态,因此它只是丢弃了翻译".

OK so the reason the first command lines doesn't work is (as I suspected) because the PDF interpreter resets the graphics state before running the PDF, so it simply throws away the 'translate'.

如果您对PageOffset数组中的操作数求反,那么第二条命令行对我来说效果很好:

The second command line works perfectly well for me if you negate the operands in the array for PageOffset:

gswin32c -sDEVICE=pdfwrite -sOutputFile=\temp\out.pdf -dDEVICEWIDTHPOINTS=1815 -dDEVICEHEIGHTPOINTS=670 -dFIXEDMEDIA -c "<</PageOffset [-6292 -6865]>>setpagedevice" -f D:\Users\ken\Downloads\bbox.pdf

第三个命令行不起作用,因为它为所有页面设置了CropBox,这是默认设置,可以通过在每个页面上设置CropBox来覆盖.您的原始PDF文件包含一个CropBox(与MediaBox相同),该文件由PDF解释器保留,因此PAGES CropBox被该页面特有的CropBox覆盖.

The third command line doesn't work because it sets the CropBox for all Pages, which is a default and can be overridden by setting a CropBox on each page. Your original PDF file contains a CropBox (identical to the MediaBox) which is preserved by the PDF interpreter, so the PAGES CropBox is overridden by the CropBox specific to the page.

但是上面的命令行对我来说很好.

But the command line above worked fine for me.

这篇关于ghostscript裁剪pdf不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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