我有一个使用 style.css 并具有颜色的 HTML 文件,例如:
<font style="background-color: red; color: white;"> FOO </font>
Run Code Online (Sandbox Code Playgroud)
如何将 Ubuntu 12.04 上的本地文件“导出”为 PDF?(外观和颜色应保持不变)。我试过例如:Ctrl+ P-> 打印到 PDF,但它没有保留颜色。我试过htmldoc这个--color选项..但它是同样的问题..
通过命令行执行此操作会很棒。
小智 40
在 LibreOffice Writer 中打开您的 html 文件,然后File在菜单下选择export to PDF. 就是这样。
如果您更喜欢命令行,请查看使用开源工具 - Linux / OS X / Windows 将 HTML 页面转换为 PDF。
该软件可以使用sudo apt-get install wkhtmltopdf.
Sam*_*ins 24
sudo apt-get install wkhtmltopdf
Run Code Online (Sandbox Code Playgroud)
这里有一个 nixCraft 教程(2017 年更新)。
最新版本是无头的(不需要 X 服务器)。
另一种可能性:phantomjs是一个神奇的无头网络浏览器,也基于 webkit html。它可以将页面导出为 PDF 等。
Pit*_*kos 14
WeasyPrint看起来很有前途。我尝试过wkhtmltopdf,虽然它以可接受的方式呈现事物,但它并没有正确呈现所有内容,并且它创建的 pdf 文件需要几秒钟才能打开!
安装
pip install weasyprint
Run Code Online (Sandbox Code Playgroud)
跑
weasyprint mypage.html out.pdf
Run Code Online (Sandbox Code Playgroud)
另外,如果您想让浏览器视图和 PDF 看起来相同,那么更改 CSS 可能会有所帮助。
/* For converting to PDF */
body {
width: 210mm; /* A4 dimension */
}
@page {
margin:0;
padding: 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
137369 次 |
| 最近记录: |