我可以从命令行打印html文件(带图像,css)吗?

时间:2008-11-13 09:06:54

标签: html linux command-line scripting printing

我想用脚本中的图像打印样式化的html页面。任何人都可以建议一个开源解决方案吗?

我正在使用linux(Ubuntu 8.04),但也会对其他操作系统的解决方案感兴趣。

4 个答案:

答案 0 :(得分:9)

你可以尝试html2ps,它是用Perl编写的,所以我猜它会在任何运行Perl的操作系统上运行。它支持CSS和图像。它并没有像你想象的那样好。

在Debian / Ubuntu sudo aptitude install html2ps中使用,然后将输出通过管道输出到lpr进行打印:

html2ps \
    http://stackoverflow.com/questions/286583 \
    |lpr

或者将输出传递给ps2pdf以转换为pdf文件:

html2ps \
    http://stackoverflow.com/questions/286583 \
    |ps2pdf - stackoverflow.pdf

答案 1 :(得分:4)

你有很多选择:html2ps,html2pdf,一个巨大的列表:http://www.hypernews.org/HyperNews/get/www/html/converters.html

但我个人建议使用htmldoc它跟postcript,PDF并且是最新的(最新版本是< 2周前。你需要使用像wget或elinks这样的工具来实际下载HTML文件及其组件。

答案 2 :(得分:0)

如果您的安装上有kde,那么您可以启动konqueror并使用dcop或dbus向其发送命令。这意味着你必须运行x,这可能不适合你。

答案 3 :(得分:-1)

我不确定此代码是否适用于mono,但它至少应该适用于Windows和“真正的”.NET Framework: http://pietschsoft.com/post/2008/07/C-Generate-WebPage-Thumbmail-Screenshot-Image.aspx