找回密码
 快速注册
搜索
查看: 69|回复: 2

用GhostScript裁剪PDF页面

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-9 00:01 |阅读模式
今天终于搞明白了.
第一步
  1. sed -i 's/CropBox/cropbox/' input.pdf
复制代码
把原pdf的CropBox值弄掉(且保持字符数不变)见stackoverflow.com/questions/5797841
answer to Cropping a PDF using Ghostscript 9.01 says that command line argument /CropBox is ignored if it's already defined in the file. Workaround is to preprocess the file and change case, e.g. /crOPbOX so the internal setting is ignored.


第二步 用gsview32.exe (Windows) / gv (Linux) 打开PDF [默认单位1 pt = 1/72 in]
左下角坐标xmin ymin = 114 293右上角坐标xmax ymax = 329 496
phpBDkOKM[1].png phpBDkOKM[1].png

第三步 添加边框值 [xmin ymin xmax ymax] 不用转换单位(因为gsview是GhostScript配套阅读器)
  1. gs -o output.pdf -sDEVICE=pdfwrite -c "[/CropBox [114 293 329 496] /PAGES pdfmark" -f input.pdf
复制代码

成功!
$type input.pdf (94.81 KB, 下载次数: 0) $type output.pdf (32.81 KB, 下载次数: 0)

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-3-30 00:49
ghostgum可以下载GSView 5 但与最新版GhostScript不兼容!
但最新版本GSView 6不知在哪里才能下载. wisc提供的链接gsview.com/显示
Artifex is announcing end of life for GSView 6.0. Support will no longer be available.

GSView官方不再支持.
根据StackOverflow需要Ghostscript version 9.52
官方GitHub找到了下载地址gs952w64.exe

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-3-30 01:32
打开这个PDF时GSView会报错:
$type input.pdf (29.79 KB, 下载次数: 1)
参考StackOverflow
  1. "C:\Program Files\gs\gs9.52\bin\gswin64.exe" -sDEVICE=pdfwrite  -dNoOutputFonts -sOutputFile=output.pdf input.pdf
复制代码

把字体换成图形, 就能用GSView打开了:
$type output.pdf (154.23 KB, 下载次数: 3)
但是文件变大

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 15:38

Powered by Discuz!

× 快速回复 返回顶部 返回列表