本文介绍了是否有任何wkhtmltopdf选项来转换html文本而不是文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近偶然发现了wkhtmltopdf,并发现它是在浏览器中从html转换为pdf的优秀工具。



典型用法(在Windows中):

  wkhtmltopdf.exe --some-option< div>某些html< b>已格式化的< / b>文字< / div> www.host.com/page_to_print.html file.pdf 

我的问题是:是否有一个选项使用< html>< head>< / head>< body>< h1>这是一个标头< / h1>< / body>< / html> 代替 www.host.com/page_to_print.html



感谢您的帮助。 / b>

解决方案

是和不是。 没有本地支持,但您可以使用Windows命令提示符管道将内容传送到wkhtmltopdf。试试这个命令:

  echo< h3>神奇小马< / h3> | wkhtmltopdf.exe  -  test.pdf 

这听起来像echo this text,output it's stdout(standard out流)到wkhtmltopdf stdin(标准流)。 wkhtmltopdf命令中的破折号 - 表示它从stdin输入而不是文件。



您可以还将HTML回显到文件中,将该文件提供给wkhtmltopdf并在脚本中删除该文件。



目前,用于文档的最佳资源是和 - 如果你通读它们,没有提及输入像这样的HTML字符串。


I recently stumbled on wkhtmltopdf and have found it to be an excellent tool for on-the-fly conversion from html to pdf in the browser.

A typical usage (in Windows) would go:

wkhtmltopdf.exe --some-option "<div>Some html <b>formatted</b> text</div>" www.host.com/page_to_print.html file.pdf

My question is: Is there an option to use <html><head></head><body><h1>This is a header</h1></body></html> in place of www.host.com/page_to_print.html?

Thanks for any help.

解决方案

Yes and no.

There is no native support, but you can pipe content into wkhtmltopdf using the windows command prompt pipe. Try this command:

echo "<h3>magical ponies</h3>" | wkhtmltopdf.exe - test.pdf

This reads like "echo this text, output it's stdout (standard out stream) to wkhtmltopdf stdin (standard in stream)". The dash - in the wkhtmltopdf command means that it takes it's input from stdin and not a file.

You could also echo HTML into a file, feed that file to wkhtmltopdf and delete that file inside a script.

Currently the best resources for documentation are http://wkhtmltopdf.org/usage/wkhtmltopdf.txt and http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf_0.10.0_rc2-doc.html - if you read through them, there is no mention of inputting a string of HTML like that.

这篇关于是否有任何wkhtmltopdf选项来转换html文本而不是文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 00:25