您知道如何提取 PDF 文档的一部分并将其另存为 PDF 吗?在 OS X 上,使用预览绝对是微不足道的。我尝试了 PDF 编辑器和其他程序,但无济于事。
我想要一个程序,在其中选择我想要的部分,然后使用简单的命令(如OS X 上的CMD+)将其保存为 PDF 文件N。我希望将提取的部分保存为 PDF 而不是 JPEG 等。
小智 669
pdftk
是一个有用的多平台工具(pdftk 主页)。
pdftk full-pdf.pdf cat 12-15 output outfile_p12-15.pdf
Run Code Online (Sandbox Code Playgroud)
您传递主 pdf 的文件名,然后告诉它仅包含某些页面(在此示例中为 12-15)并将其输出到一个新文件。
Abd*_*UMI 322
很简单。使用默认的 PDF 阅读器,选择“打印到文件”,就是这样!
然后:
请注意,通过这种方式,文本将不再可搜索,而是所有文本都转换为图像:这就是“打印”的工作原理。
Ho1*_*Ho1 206
QPDF很棒。使用这种方式从中提取第 1-10 页input.pdf
并将其另存为output.pdf
:
qpdf input.pdf --pages . 1-10 -- output.pdf
Run Code Online (Sandbox Code Playgroud)
这会保留与该文件关联的所有元数据。
从手册:
如果您想要 infile.pdf 中的第 1 页到第 5 页,但您希望删除其余的元数据,则可以改为运行
qpdf --empty --pages infile.pdf 1-5 -- outfile.pdf
Run Code Online (Sandbox Code Playgroud)
您可以通过调用来安装它:
sudo apt-get install qpdf
Run Code Online (Sandbox Code Playgroud)
它是 PDF 操作的绝佳工具。它非常快,并且依赖项很少。“它可以加密和线性化文件,公开 PDF 文件的内部结构,并执行许多其他对最终用户和 PDF 开发人员有用的操作。”
QPDF 在GitHub 上的代码库。
Glu*_*ate 92
概述
我根据链接到的教程@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
Run Code Online (Sandbox Code Playgroud)
安装
请遵循Nautilus 脚本的通用安装说明。请务必仔细阅读脚本标题,因为这将有助于阐明脚本的安装和使用。
概述
PDF-Shuffler 是一个小型的 python-gtk 应用程序,它帮助用户使用交互式和直观的图形界面合并或拆分 pdf 文档以及旋转、裁剪和重新排列他们的页面。它是 python-pyPdf 的前端。
安装
sudo apt-get install pdfshuffler
Run Code Online (Sandbox Code Playgroud)
用法
PDF-Shuffler 可以裁剪和删除单个 PDF 页面。您可以使用它从文档中提取页面范围,甚至使用裁剪功能提取部分页面:
概述
Inkscape 是一个非常强大的开源矢量图形编辑器。它支持多种不同的格式,包括 PDF 文件。您可以使用它从 PDF 文件中提取、修改和保存页面元素。
安装
sudo apt-get install inkscape
Run Code Online (Sandbox Code Playgroud)
用法
1.)使用 Inkscape 打开您选择的 PDF 文件。将出现一个导入对话框。选择要从中提取元素的页面。保持其他设置不变:
2.)在 Inkscape 中单击并拖动以选择要提取的元素:
3.) 使用反转选择!并删除所选对象DELETE:
4.)通过访问裁剪文件的剩余对象文档属性与对话CTRL+ SHIFT+D并选择“适合文档图像”:
5.)从文件-->另存为对话框中将文档另存为 PDF 文件:
6.)如果裁剪文档中有位图/光栅图像,您可以在接下来出现的对话框中设置它们的 DPI:
7.)如果您按照所有步骤进行操作,您将生成一个仅包含您选择的对象的真正 PDF 文件:
Thi*_*nte 64
将其另存为 shell 脚本,例如 pdfextractor.sh:
#!/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}"
Run Code Online (Sandbox Code Playgroud)
运行类型:
./pdfextractor.sh 4 20 myfile.pdf
Run Code Online (Sandbox Code Playgroud)
4
指将启动新 pdf 的页面。
20
指的是它将以 pdf 结尾的页面。
myfile.pdf
是您要提取零件的pdf文件。
输出将myfile_p4_p20.pdf
在与原始 pdf 文件相同的目录中。
所有这些和更多信息在这里:技术提示
Ioa*_*dis 45
在任何安装了 TeX 发行版的系统中:
pdfjam <input file> <page ranges> -o <output file>
Run Code Online (Sandbox Code Playgroud)
例如:
pdfjam original.pdf 5-10 -o out.pdf
Run Code Online (Sandbox Code Playgroud)
见https://tex.stackexchange.com/a/79626/8666
jdm*_*cbr 38
有一个名为pdfseparate的命令行实用程序。
从文档:
pdfseparate 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
Run Code Online (Sandbox Code Playgroud)
或者,要从文件 sample.pdf 中选择单个页面(在本例中为第一页):
pdfseparate -f 1 -l 1 sample.pdf sample-1.pdf
Run Code Online (Sandbox Code Playgroud)
And*_*bis 20
pdftk
( 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
Run Code Online (Sandbox Code Playgroud)
在你的情况下,我会这样做:
pdftk A=input.pdf cat A<page_range> output output.pdf
Run Code Online (Sandbox Code Playgroud)
小智 12
我试图做同样的事情。您所要做的就是:
安装pdftk
:
sudo apt-get install pdftk
Run Code Online (Sandbox Code Playgroud)如果要提取随机页面:
pdftk myoldfile.pdf cat 1 2 4 5 output mynewfile.pdf
Run Code Online (Sandbox Code Playgroud)如果你想提取一个范围:
pdftk myoldfile.pdf cat 1-2 4-5 output mynewfile.pdf
Run Code Online (Sandbox Code Playgroud)请检查来源以获取更多信息。
您是否尝试过 PDF Mod?
例如,您可以.. 提取页面并将其另存为 pdf。
描述:
PDF Mod 是一个用于修改 PDF 文档的简单工具。它可以
通过拖放来旋转、提取、删除和重新排序页面。可以通过拖放合并多个文档
。您还可以
使用 PDF Mod编辑 PDF文档的标题、主题、作者和关键字。
希望这会有用。
问候。
事实证明,我可以用imagemagick
. 如果你没有它,只需安装:
sudo apt-get install imagemagick
Run Code Online (Sandbox Code Playgroud)
注 1:我用一页 pdf 试过这个(我正在学习使用imagemagick
,所以我不想比必要的麻烦)。我不知道它是否/如何处理多个页面,但您可以使用以下命令提取感兴趣的页面pdftk
:
pdftk A=myfile.pdf cat A1 output page1.pdf
Run Code Online (Sandbox Code Playgroud)
在此处指示要拆分的页码(在上面的示例中,A1
选择第一页)。
注 2:使用此程序生成的图像将是一个光栅。
使用命令打开 pdf display
,这是imagemagick
套件的一部分:
display file.pdf
Run Code Online (Sandbox Code Playgroud)
我的看起来像这样:
现在您单击窗口,旁边会弹出一个菜单。在那里,选择变换| 作物。
返回主窗口,您只需拖动指针即可选择要裁剪的区域(经典的角到角选择)。
选择时注意图像周围的手形指针
在进行下一步之前,可以优化此选择。
完成后,注意左上角出现的小矩形(见上图)。它首先显示所选区域的尺寸(例如281x218
),然后显示第一个角的坐标(例如+256+215
)。
写下所选区域的尺寸;在保存裁剪后的图像时,您将需要它。
现在,回到弹出菜单(现在是特定的“裁剪”菜单),单击按钮Crop。
最后,一旦您对裁剪结果感到满意,请单击菜单文件| 节省
导航到要保存裁剪后的 pdf 的文件夹,键入名称,单击按钮格式,在“选择图像格式类型”窗口中选择PDF并单击按钮选择。返回“浏览并选择文件”窗口,单击“保存”按钮。
保存前,imagemagick
会询问“选择页面几何形状”。在这里,您输入裁剪图像的尺寸,使用简单的字母“x”来分隔宽度和高度。
现在,您可以从命令行完美地完成所有这些操作(该命令convert
带有 option -crop
)——当然它更快,但您必须事先知道要提取的图像的坐标。检查man convert
和他们网页中的示例。
小智 6
如果您希望使用内置的 bash 命令,那么pdfseparate和pdfunite适合您。
pdfseparate sample.pdf sample-%d.pdf
# ls; sample.pdf sample-1.pdf sample-2.pdf sample-3.pdf sample-4.pdf
pdfunite sample-2.pdf sample-3.pdf output.pdf
# now you can use output.pdf
Run Code Online (Sandbox Code Playgroud)
mupdf附带的 mutool 可以做很多简单的 PDF 处理工作,但比qpdf
(以及其他一些答案)具有更优雅的语法。此外,在大型 PDF 上看起来更快:
# extract page range 20-40
mutool clean in.pdf out.pdf 20-40
# extract from all over the pdf
mutool clean in.pdf out.pdf '1, 3-4, 74-92'
Run Code Online (Sandbox Code Playgroud)
自 2018 年 5 月 11 日起在 Ubuntu 20.04 和pdftk --version
3.0.9 上进行测试(日期显示在底部man pdftk
)。
如果使用pdftk
,则以下是如何为多组页面设置格式:
pdftk in.pdf cat 13 18 33-36 39-41 52 output out.pdf
Run Code Online (Sandbox Code Playgroud)
这将捕获这些页面组,包括在内。
安装和/或更新pdftk
:
sudo apt update
sudo apt install pdftk
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
519652 次 |
最近记录: |