[英]Convert html to pdf using prawn in ruby on rails
I am working on a Rails project and I need to convert the HTML page to a PDF page but it's writing HTML as it is on a pdf page. PDF 頁面不像網頁那樣顯示。 如何從 HTML 文件生成正確的 PDF?
Prawn::Document.generate("test.pdf") do
filepath = ${filepath}"file.html"
data = File.read(filepath);
text data
end
prawn
並不是真正的 HTML 到 PDF 生成器 - 請參閱https://github.com/prawnpdf/prawn#should-you-use-prawn
您需要使用其他工具,例如wicked_pdf
- 請參閱https://github.com/mileszs/wicked_pdf#super-advanced-usage
在您的情況下,要引用README
,您將需要類似
# create a pdf file from a html file without converting it to string
# Path must be absolute path
pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.