Forgot password?
 Create new account
View 171|Reply 2

用GhostScript裁剪PDF页面

[Copy link]

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2023-3-9 00:01:08 |Read mode
今天终于搞明白了.
第一步
  1. sed -i 's/CropBox/cropbox/' input.pdf
Copy the Code
把原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
Copy the Code

成功!
$type input.pdf (94.81 KB, Downloads: 30) $type output.pdf (32.81 KB, Downloads: 30)

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2023-3-30 00:49:36
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

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2023-3-30 01:32:30
打开这个PDF时GSView会报错:
$type input.pdf (29.79 KB, Downloads: 31)
参考StackOverflow
  1. "C:\Program Files\gs\gs9.52\bin\gswin64.exe" -sDEVICE=pdfwrite  -dNoOutputFonts -sOutputFile=output.pdf input.pdf
Copy the Code

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

手机版Mobile version|Leisure Math Forum

2025-4-20 22:25 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list