GhostScript issues with a CropBox

风流意气都作罢 提交于 2019-12-25 01:46:25

问题


I am trying to add a CropBox to a pdf with ghostscript. I use the following code:

gs -sDEVICE=pdfwrite -o output.pdf -c "[/CropBox [100.00 100.00 200.00 200.00] /PAGES pdfmark" -f input.pdf

The problem is that with some pdf's it will create a proper CropBox, but with others it fails to do anything.

The pdf's that fail already have a existing TrimBox, and after my line of code the TrimBox has been removed. But it doesn't create a correct CropBox.

I get no errors from GhostScript, it just doesn't work.

Does anybody have an idea what I'm doing wrong?


回答1:


Without seeing an example PDF file, its rather hard to tell....

Please note (repetitive lecture....) what you are doing is not 'adding a CropBox'. When you process input through Ghostscript (whatever the input is, PDF, PS, PCL, XPS...) it is completely interpreted into graphics primitives. These primitives are passed to the Ghostscript device, which decides what to do with them. In the case of rendering devices they use the graphics library to render the graphics to a bitmap. In the case of the high level devices, such as pdfwrite, the primitives are converted into suitable operations for the desired format and emitted suitably wrapped up in a a file format.

So.... The output PDF file has nothing in common with the input, except that it should appear visually the same. Some PDF metadata (ie non-marking content) is converted into pdfmark operations by the PDF interpreter, and sent to the device that way, and some high level devices will embed some part of that in their output, so the most likely situation is that the pdfmark operation you are supplying before the PDF file is interpreted is overridden by later pdfmarks generated by the PDF interpreter in response to the content of the PDF file.

The main point is that you aren't adding a CropBox to an existing PDF< you are creating a brand new PDF with a CropBox, and the content of that PDF file has nothing in common with the original file.

If you post an example PDF file you are having trouble with I can look at it, but without that I can't tell what the actual reason is.



来源:https://stackoverflow.com/questions/25505001/ghostscript-issues-with-a-cropbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!