更新时间:2023-01-08 15:51:36浏览次数:894+次
有没有想过如何在Linux终端上下载PDF文件的网页?本文将帮助您使用Percollate命令行工具将在线网页下载为格式精美的PDF文件。内容有在Linux系统下安装Percollate,以及使用Percollate以PDF格式下载在线网页。
在Linux系统下安装Percollate
Percollate需要在本地系统上安装Node.js版本8或更高版本,因为它使用新的(ish)JavaScript语法。可参考https://www.hmxthome.com/linux/4930.html里面的内容。
安装Node.js后,您可以使用yarn或npm继续全局安装percollate。
对于npm,使用:
sudo npm install -g percollate@latest
对于yarn,使用:
sudo yarn global add percollate
通过运行以下命令检查已安装的版本:
$ percollate --version
2.2.0
有关帮助页面,请使用:
$ percollate --help
用法:percollate <command> [options] url [url]...
命令:
pdf-将网页捆绑为pdf文件
epub-将网页捆绑为epub文件。
html-将网页捆绑为html文件。
详细的选项如下图所示:
如何在Linux上更新Percollate
要使软件包保持最新,可以运行:
$ sudo npm install -g percollate@latest
或:
$ sudo yarn global upgrade --latest percollate
yarn global v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Rebuilding all packages...
success Saved lockfile.
success Saved 0 new dependencies.
Done in 1.72s.
使用Percollate以PDF格式下载网页
可用的基本命令包括:
percollate pdf:将一个或多个网页打包成pdf。
percollate epub:将一个或多个网页打包到epub中。
percollate html:将一个或多个网页捆绑到html文件中。
可用选项包括:
-o, –output–生成束的路径,如果省略,则输出文件名从网页的标题派生。
–individual–将每个网页导出为单个文件。
–template–自定义HTML模板的路径。
–style–自定义CSS的路径。
–css:可以从命令行传递的其他css样式,以覆盖默认/自定义样式表样式。
1、参见以下示例:
将单个网页转换为PDF:
percollate pdf --output file filename.pdf https://example.com
要将多个网页捆绑到一个PDF中,请将它们指定为命令的单独参数:
percollate pdf --output filename.pdf https://example.com/page1 https://example.com/page2
您可以使用常见的Unix命令,并将URL列表保存在以换行符分隔的文本文件中:
cat urls.txt | xargs percollate pdf --output filename.pdf
要同时将多个网页转换为单个PDF文件,请使用–individual标志:
percollate pdf --individual --output some.pdf https://example.com/page1 https://example.com/page2
2、设置自定义页面大小/边距:
默认页面大小为A5(纵向)。但是您可以使用--css选项使用任何支持的css大小覆盖它:
percollate pdf --output some.pdf --css "@page { size: A3 landscape }" http://example.com
类似地,您可以使用以下定义:
自定义页边距:@page { margin: 0 }
基本字体大小:html { font-size: 10pt }
或默认/自定义样式表中定义的任何其他样式。
相关资讯