zse*_*der 28 pdf-generation ghostscript
我尝试用Ghostscript拆分多页PDF,我在更多网站甚至ghostscript.com上找到了相同的解决方案,即:
gs -sDEVICE=pdfwrite -dSAFER -o outname.%d.pdf input.pdf
Run Code Online (Sandbox Code Playgroud)
但它似乎对我不起作用,因为它生成一个文件,包含所有页面,名称为outname.1.pdf.
当我添加起始页和结束页时,它工作正常,但我希望它在不知道这些参数的情况下工作.
在gs-devel存档中,我找到了一个解决方案:http:
//ghostscript.com/pipermail/gs-devel/2009-April/008310.html - 但我觉得没有这样做pdf_info
.
例如pswrite
,当我使用不同的设备但是相同的参数时,它可以正常工作,产生尽可能多的ps文件,就像我的
input.pdf所包含的那样.
使用时这是正常的pdfwrite
吗?难道我做错了什么?
Jua*_*tas 19
我发现Weimer先生对这个脚本非常有用:
#!/bin/sh
#
# pdfsplit [input.pdf] [first_page] [last_page] [output.pdf]
#
# Example: pdfsplit big_file.pdf 10 20 pages_ten_to_twenty.pdf
#
# written by: Westley Weimer, Wed Mar 19 17:58:09 EDT 2008
#
# The trick: ghostscript (gs) will do PDF splitting for you, it's just not
# obvious and the required defines are not listed in the manual page.
if [ $# -lt 4 ]
then
echo "Usage: pdfsplit input.pdf first_page last_page output.pdf"
exit 1
fi
yes | gs -dBATCH -sOutputFile="$4" -dFirstPage=$2 -dLastPage=$3 -sDEVICE=pdfwrite "$1" >& /dev/null
Run Code Online (Sandbox Code Playgroud)
起源于:http://www.cs.virginia.edu/~weimer/pdfsplit/pdfsplit
保存它pdfsplit.sh
,看到魔术发生.
PDFSAM也可以完成这项工作.适用于Windows和Mac.
Kur*_*fle 12
你看到的是"正常"行为:当前版本的Ghostscript pdfwrite
输出设备不支持此功能.在Use.htm中也记录了这一点(不可否认,模糊地说):
"请注意,所有设备可能都不支持每个文件功能的一页......"
我似乎记得在IRC上提到的一个Ghostscript开发人员,他们可能会在未来的某个版本中将这个功能添加到pdfwrite中,但它似乎需要一些主要的代码重写,这就是为什么他们还没有完成它...
更新:正如Gordon的评论已经暗示的那样,从版本9.06(2012年7月31日发布)开始,Ghostscript现在支持该问题中引用的命令行pdfwrite
.(Gordon肯定已经在9.05中发现了对此的非官方支持,或者他从预发布源代码中编译了自己的可执行文件,但尚未标记为9.06).
小智 5
#!/bin/bash
#where $1 is the input filename
ournum=`gs -q -dNODISPLAY -c "("$1") (r) file runpdfbegin pdfpagecount = quit" 2>/dev/null`
echo "Processing $ournum pages"
counter=1
while [ $counter -le $ournum ] ; do
newname=`echo $1 | sed -e s/\.pdf//g`
reallynewname=$newname-$counter.pdf
counterplus=$((counter+1))
# make the individual pdf page
yes | gs -dBATCH -sOutputFile="$reallynewname" -dFirstPage=$counter -dLastPage=$counter -sDEVICE=pdfwrite "$1" >& /dev/null
counter=$counterplus
done
Run Code Online (Sandbox Code Playgroud)
假设您安装了 Ghostscript,这里是 Windows 命令提示符的脚本(也可以使用拖放操作):
@echo off
chcp 65001
setlocal enabledelayedexpansion
rem Customize or remove this line if you already have Ghostscript folders in your system PATH
set path=C:\Program Files\gs\gs9.22\lib;C:\Program Files\gs\gs9.22\bin;%path%
:start
echo Splitting "%~n1%~x1" into standalone single pages...
cd %~d1%~p1
rem getting number of pages of PDF with GhostScript
for /f "usebackq delims=" %%a in (`gswin64c -q -dNODISPLAY -c "(%~n1%~x1) (r) file runpdfbegin pdfpagecount = quit"`) do set "numpages=%%a"
for /L %%n in (1,1,%numpages%) do (
echo Extracting page %%n of %numpages%...
set "x=00%%n"
set "x=!x:~-3!"
gswin64c.exe -dNumRenderingThreads=2 -dBATCH -dNOPAUSE -dQUIET -dFirstPage=%%n -dLastPage=%%n -sDEVICE=pdfwrite -sOutputFile="%~d1%~p1%~n1-!x!.pdf" "%1"
)
shift
if NOT x%1==x goto start
pause
Run Code Online (Sandbox Code Playgroud)
将此脚本命名为类似的名称split PDF.bat
并将其放在您的桌面上。将一个(甚至更多)多页 PDF 拖放到其上,它将为 PDF 的每一页创建一个独立的 PDF 文件-001
,-002
并在名称后附加后缀等以区分页面。
set path=...
如果您的系统 PATH 环境变量中已经有 Ghostscript 文件夹,您可能需要自定义(使用相关的 Ghostscript 版本)或删除该行。
它在带有 Ghostscript 9.22 的 Windows 10 下对我有用。查看评论以使其与 Ghostscript 9.50+ 一起使用。
享受。
归档时间: |
|
查看次数: |
30165 次 |
最近记录: |