我想要一个程序,在其中我可以选择我想要的部分,然后通过像在OS X上使用CMD+N这样简单的命令将其保存为PDF文件。我希望提取的部分以PDF格式保存,而不是JPEG等其他格式。
pdftk
是一款适用于多平台的实用工具(pdftk主页)。
pdftk full-pdf.pdf cat 12-15 output outfile_p12-15.pdf
传递主PDF文件的文件名,然后告诉它只包括特定页面(在此示例中为12-15),并将其输出到一个新文件。
要安装快照版本(这是Scott Moser重新打包的旧版本PDFtk的非官方重新打包版本),请访问此链接或运行:
sudo snap install pdftk
sudo apt install pdftk-java
然后:
qpdfview
。 - TimoQPDF很棒。使用它的方法从input.pdf
中提取第1到10页,并将其保存为output.pdf
:
qpdf input.pdf --pages . 1-10 -- output.pdf
如果您想提取infile.pdf中的1到5页,但希望其余的元数据被删除,您可以运行以下命令
qpdf --empty --pages infile.pdf 1-5 -- outfile.pdf
这里是一个链接到当前的文档,提供了更多页面选择的示例。
您可以通过调用它来安装:
sudo apt-get install qpdf
QPDF是一个命令行工具和C++库,可以对PDF文件进行内容保留的转换。它支持线性化、加密和许多其他功能。它还可以用于拆分和合并文件,创建PDF文件(但您必须自己提供所有内容),以及检查文件进行研究或分析。
--pages
标志允许您从多个PDF中拼接页面。请注意,您可以在 --pages
选项中使用 .
替代输入文件来避免重复名称:qpdf --pages . 1-10 -- input.pdf output.pdf
。 - bart---pages .
。也许这是最近添加的功能? - cgmbpages
选项的语法有些奇怪。TeXnologies无法帮助,因为我没有PDF源文件。GS可能能够帮助,因为我以前使用过它来合并PDF文档,以弥补Preview.app在我的Mac上的一些不足之处,但我可能需要先进行更多的研究。我在Homebrew中也没有看到适用于Mac的pdftk。啊,我现在看到下面有一个gs的答案了! - Pysisqpdf --pages . 1-8 . 53-70 -- input.pdf output.pdf
。 - Andrew Krizhanovskyqpdf input.pdf --pages . 1 -- output.pdf
对我来说无效(版本8.0.2)。以下是对我有效的方法:qpdf input.pdf --pages input.pdf 1 -- output.pdf
。 - Kyle Gibsonqpdf
只需要8秒,而gs
则需要72秒,其他一些方法甚至需要300多秒。 - vstepaniuk--pages
命令需要自己的输入文件,并且 --
用于结束 --pages
参数。 - Tarick Welling概述
我根据@ThiagoPonte提供的教程创建了一个稍微高级一些的脚本。它的主要特点包括:
截图
代码
#!/bin/bash
#
# TITLE: PDFextract
#
# AUTHOR: (c) 2013-2015 Glutanimate (https://github.com/Glutanimate)
#
# VERSION: 0.2
#
# LICENSE: GNU GPL v3 (http://www.gnu.org/licenses/gpl.html)
#
# OVERVIEW: PDFextract is a simple PDF extraction script based on Ghostscript/qpdf/cpdf.
# It provides a simple way to extract a page range from a PDF document and is meant
# to be used as a file manager script/addon (e.g. Nautilus script).
#
# FEATURES: - simple GUI based on YAD, an advanced Zenity fork.
# - preserves _all_ attributes of your original PDF file and does not compress
# embedded images further than they are.
# - can choose from three different backends: ghostscript, qpdf, cpdf
#
# DEPENDENCIES: ghostscript/qpdf/cpdf poppler-utils yad libnotify-bin
#
# You need to install at least one of the three backends supported by this script.
#
# - ghostscript, qpdf, poppler-utils, and libnotify-bin are available via
# the standard Ubuntu repositories
# - cpdf is a commercial CLI PDF toolkit that is free for personal use.
# It can be downloaded here: https://github.com/coherentgraphics/cpdf-binaries
# - yad can be installed from the webupd8 PPA with the following command:
# sudo add-apt-repository ppa:webupd8team/y-ppa-manager && apt-get update && apt-get install yad
#
# NOTES: Here is a quick comparison of the advantages and disadvantages of each backend:
#
# speed metadata preservation content preservation license
# ghostscript: -- ++ ++ open-source
# cpdf: - ++ ++ proprietary
# qpdf: ++ + ++ open-source
#
# Results might vary depending on the document and the version of the tool in question.
#
# INSTALLATION: https://askubuntu.com/a/236415
#
# This script was inspired by Kurt Pfeifle's PDF extraction script
# (http://www.linuxjournal.com/content/tech-tip-extract-pages-pdf)
#
# Originally posted on askubuntu
# (https://askubuntu.com/a/282453)
# Variables
DOCUMENT="$1"
BACKENDSELECTION="^qpdf!ghostscript!cpdf"
# Functions
check_input(){
if [[ -z "$1" ]]; then
notify "Error: No input file selected."
exit 1
elif [[ ! "$(file -ib "$1")" == *application/pdf* ]]; then
notify "Error: Not a valid PDF file."
exit 1
fi
}
check_deps () {
for i in "$@"; do
type "$i" > /dev/null 2>&1
if [[ "$?" != "0" ]]; then
MissingDeps+="$i"
fi
done
}
ghostscriptextract(){
gs -dFirstPage="$STARTPAGE "-dLastPage="$STOPPAGE" -sOutputFile="$OUTFILE" -dSAFER -dNOPAUSE -dBATCH -dPDFSETTING=/default -sDEVICE=pdfwrite -dCompressFonts=true -c \
".setpdfwrite << /EncodeColorImages true /DownsampleMonoImages false /SubsetFonts true /ASCII85EncodePages false /DefaultRenderingIntent /Default /ColorConversionStrategy \
/LeaveColorUnchanged /MonoImageDownsampleThreshold 1.5 /ColorACSImageDict << /VSamples [ 1 1 1 1 ] /HSamples [ 1 1 1 1 ] /QFactor 0.4 /Blend 1 >> /GrayACSImageDict \
<< /VSamples [ 1 1 1 1 ] /HSamples [ 1 1 1 1 ] /QFactor 0.4 /Blend 1 >> /PreserveOverprintSettings false /MonoImageResolution 300 /MonoImageFilter /FlateEncode \
/GrayImageResolution 300 /LockDistillerParams false /EncodeGrayImages true /MaxSubsetPCT 100 /GrayImageDict << /VSamples [ 1 1 1 1 ] /HSamples [ 1 1 1 1 ] /QFactor \
0.4 /Blend 1 >> /ColorImageFilter /FlateEncode /EmbedAllFonts true /UCRandBGInfo /Remove /AutoRotatePages /PageByPage /ColorImageResolution 300 /ColorImageDict << \
/VSamples [ 1 1 1 1 ] /HSamples [ 1 1 1 1 ] /QFactor 0.4 /Blend 1 >> /CompatibilityLevel 1.7 /EncodeMonoImages true /GrayImageDownsampleThreshold 1.5 \
/AutoFilterGrayImages false /GrayImageFilter /FlateEncode /DownsampleGrayImages false /AutoFilterColorImages false /DownsampleColorImages false /CompressPages true \
/ColorImageDownsampleThreshold 1.5 /PreserveHalftoneInfo false >> setdistillerparams" -f "$DOCUMENT"
}
cpdfextract(){
cpdf "$DOCUMENT" "$STARTPAGE-$STOPPAGE" -o "$OUTFILE"
}
qpdfextract(){
qpdf --linearize "$DOCUMENT" --pages "$DOCUMENT" "$STARTPAGE-$STOPPAGE" -- "$OUTFILE"
echo "$OUTFILE"
return 0 # even benign qpdf warnings produce error codes, so we suppress them
}
notify(){
echo "$1"
notify-send -i application-pdf "PDFextract" "$1"
}
dialog_warning(){
echo "$1"
yad --center --image dialog-warning \
--title "PDFExtract Warning" \
--text "$1" \
--button="Try again:0" \
--button="Exit:1"
[[ "$?" != "0" ]] && exit 0
}
dialog_settings(){
PAGECOUNT=$(pdfinfo "$DOCUMENT" | grep Pages | sed 's/[^0-9]*//') #determine page count
SETTINGS=($(\
yad --form --width 300 --center \
--window-icon application-pdf --image application-pdf \
--separator=" " --title="PDFextract"\
--text "Please choose the page range and backend"\
--field="Start:NUM" 1[!1..$PAGECOUNT[!1]] --field="End:NUM" $PAGECOUNT[!1..$PAGECOUNT[!1]] \
--field="Backend":CB "$BACKENDSELECTION" \
--button="gtk-ok:0" --button="gtk-cancel:1"\
))
SETTINGSRET="$?"
[[ "$SETTINGSRET" != "0" ]] && exit 1
STARTPAGE=$(printf %.0f ${SETTINGS[0]}) #round numbers and store array in variables
STOPPAGE=$(printf %.0f ${SETTINGS[1]})
BACKEND="${SETTINGS[2]}"
EXTRACTOR="${BACKEND}extract"
check_deps "$BACKEND"
if [[ -n "$MissingDeps" ]]; then
dialog_warning "Error, missing dependency: $MissingDeps"
unset MissingDeps
dialog_settings
return
fi
if [[ "$STARTPAGE" -gt "$STOPPAGE" ]]; then
dialog_warning "<b> Start page higher than stop page. </b>"
dialog_settings
return
fi
OUTFILE="${DOCUMENT%.pdf} (p${STARTPAGE}-p${STOPPAGE}).pdf"
}
extract_pages(){
$EXTRACTOR
EXTRACTORRET="$?"
if [[ "$EXTRACTORRET" = "0" ]]; then
notify "Pages $STARTPAGE to $STOPPAGE succesfully extracted."
else
notify "There has been an error. Please check the CLI output."
fi
}
# Main
check_input "$1"
dialog_settings
extract_pages
安装
请按照Nautilus脚本的通用安装说明进行操作。务必仔细阅读脚本头部,以便更好地理解脚本的安装和使用方法。
sudo apt-get install pdfshuffler
使用方法
PDF Arranger可以裁剪和删除单个PDF页面。您可以使用它从文档中提取一个页面范围,甚至使用裁剪功能提取部分页面:
概述
Inkscape 是一个非常强大的开源矢量图形编辑器。它支持多种不同的格式,包括 PDF 文件。您可以使用它来提取、修改和保存 PDF 文件中的页面元素。
安装
sudo apt-get install inkscape
使用方法
1.) 使用Inkscape打开您选择的PDF文件。将出现一个导入对话框。选择要从中提取元素的页面。将其他设置保持不变:
pdfshuffler
是不够用的。原始PDF页面的数据仍然保留在文件中。如果你想从PDF文件中删除敏感数据,请不要使用这种方法。 - Rob Wpdfshuffler
现在被称为pdfarranger
。 - amoe#!/bin/bash
# this function uses 3 arguments:
# $1 is the first page of the range to extract
# $2 is the last page of the range to extract
# $3 is the input file
# output file will be named "inputfile_pXX-pYY.pdf"
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage="${1}" \
-dLastPage="${2}" \
-sOutputFile="${3%.pdf}_p${1}-p${2}.pdf" \
"${3}"
./pdfextractor.sh 4 20 myfile.pdf
4
指的是新 PDF 将从该页开始。
20
指的是新 PDF 将以该页结束。
myfile.pdf
是您想要提取部分的 PDF 文件。
输出文件将命名为 myfile_p4_p20.pdf
,保存在原始 PDF 文件所在的目录中。
更多信息请参阅:技术提示
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dFirstPage=1 -dLastPage=10 -sOutputFile=output.pdf input.pdf
- Ho1gs
比qpdf更加熟悉,文件大小也要小得多!另外,Homebrew在我的Mac上也没有提供pdftk,并且我听说它的速度也很慢。 - Pysispdfjam <input file> <page ranges> -o <output file>
例如:
pdfjam original.pdf 5-10 -o out.pdf
pdfjam original.pdf 2-
或pdfjam original.pdf -4
,具体取决于您是要从第二页到最后一页,还是仅到第四页。它将根据输入参数(所请求的页面)自动命名输出。 - Cyrillepdfjam --landscape ...
解决了横向排列的问题。 - Niklas Mertschpdfjam original.pdf 2-4,43,49-64 -o selection.pdf
。 - TheMechanicpdfseparate sample.pdf sample-%d.pdf
extracts all pages from sample.pdf, if i.e. sample.pdf has 3 pages, it
produces
sample-1.pdf, sample-2.pdf, sample-3.pdf
pdfseparate -f 1 -l 1 sample.pdf sample-1.pdf
pdftk
快多了。 - Anwarpdfseparate
+pdfunite
处理页面范围花费了3分15秒(其中gs
花费了1分11秒,而qpdf
只花费了0分8秒),并且还创建了一个更大的文件(因为每个单独页面都有元数据)- 62 MB 对比原始的37 MB(针对530页的第81页到末尾),相比之下,gs
为50 MB,而qpdf
为33 MB...请使用qpdf
代替! - vstepaniukpdftk
(sudo apt-get install pdftk
)是一个非常好用的命令行工具,用于PDF文件的操作。以下是一些pdftk
可以做的示例:
Collate scanned pages
pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf
or if odd.pdf is in reverse order:
pdftk A=even.pdf B=odd.pdf shuffle A Bend-1 output collated.pdf
Join in1.pdf and in2.pdf into a new PDF, out1.pdf
pdftk in1.pdf in2.pdf cat output out1.pdf
or (using handles):
pdftk A=in1.pdf B=in2.pdf cat A B output out1.pdf
or (using wildcards):
pdftk *.pdf cat output combined.pdf
Remove page 13 from in1.pdf to create out1.pdf
pdftk in.pdf cat 1-12 14-end output out1.pdf
or:
pdftk A=in1.pdf cat A1-12 A14-end output out1.pdf
Burst a single PDF document into pages and dump its data to
doc_data.txt
pdftk in.pdf burst
Rotate the first PDF page to 90 degrees clockwise
pdftk in.pdf cat 1east 2-end output out.pdf
Rotate an entire PDF document to 180 degrees
pdftk in.pdf cat 1-endsouth output out.pdf
pdftk A=input.pdf cat A<page_range> output output.pdf
安装 pdftk
:
sudo apt-get install pdftk
如果你想提取随机页面:
pdftk myoldfile.pdf cat 1 2 4 5 output mynewfile.pdf
如果你想提取一个范围:
pdftk myoldfile.pdf cat 1-2 4-5 output mynewfile.pdf
pdftk A=in.pdf cat A1-10 A15 A17 output out.pdf
- m8mblepdftk
(请参考https://askubuntu.com/questions/1028522/how-can-i-install-pdftk-in-ubuntu-18-04-bionic)。 - alkamidpdftk
确实是一个可以完成工作的工具,但我不建议使用它。这不是免费软件,而是一个笨重的共享软件。而且它需要JVM。一个更合理的工具是qpdf
,正如另一个答案中所建议的。 - leftaroundaboutpdftk
)是免费的,根据GPL许可证发布:https://www.pdflabs.com/docs/pdftk-license/ - Dario Seidlpdftk
,我使用了sudo apt install pdftk-java
命令。当我尝试在安装之前运行pdftk
时,它会告诉我如何安装它。我相信它还说过这样也可以:snap install pdftk
。 - Gabriel Staplesexport LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libgtk3-nocsd.so.0
。 - Hasturpdftk
在2017年成为开源软件,因此现在/再次成为GNU/Linux发行版中的标准工具。"pdftk-java是PDFtk的Java版本[6],由Marc Vinyals开发并采用GPL许可证。初始发布日期为2017年12月30日。"(维基百科)。它的简单命令行名称为pdftk
。 - CPBLpdftk A=first.pdf B=second.pdf cat A1-7 B1-5 A8 output combined.pdf
。 - Asclepius