我想将HTML文件转换为PDF
示例输入
看起来不错,可以在我的浏览器中看到内容。
代码
import pdfkit # convert html to pdf
pdfkit.from_file('income_contract_01.html', 'res.pdf')
问题
我希望看到res.pdf中的数据。但是我却看到了一个空文件:
无文本
但是相同的行数
使用的环境和版本:
python 3.9
pdfkit versiion 1.0.0
wkhtmltopdf is the newest version (0.12.2.4-1)
OS
views.py
def download_as_pdf(request):
# some stuff/function call to get updated(with data and JS) template and render it
return render(request, temp)
def download(request):
import pdfkit
pdfkit.from_url('/download/', 'out.pdf', options={'ignore-load-errors'
我安装了pdfkit,甚至还安装了wkhtmltopdf,但是每次我尝试创建pdf时都会出现以下错误。
PDFKit::NoExecutableError
No wkhtmltopdf executable found at bundler: command not found: which
Install missing gem executables with `bundle install`
>> Please install wkhtmltopdf - https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF
我有一个rails应用程序,在一个点上,我们有一个下载的PDF。然而,我一直遇到的问题是在pdf文件的页脚中添加页码。我在一个名为report_pdf_service.rb的文件中生成PDF文件,基本上这个文件所做的就是调用一个pdf方法,这个方法调用其他转换成html的方法。
def pdf(admin_fields = false)
html << footer
html << page_count
html << '</body></html>'
PDFKit.new(html).to_pdf
e
我想做一个脚本,可以下载一个网站作为PDF。用户应该能够输入网址(https://stackoverflow.com/)和下载到的文件路径(c:\Bob\ PDF )。 这是我到目前为止的代码: import requests
import pdfkit
url = input("Please enter the url of the file you want to download.")
pdf = pdfkit.from_url(url, "file.pdf")
path = input("Please enter the file path
目前,我正在为FastAPI和文件服务而挣扎。
在我的项目中,我有以下工作流。客户端发送包含必要有效负载的有效负载,以便从第三方提供程序下载文件。
我需要向后端发送一个有效负载,这是必要的,而且由于创建了一个资源(下载的文件),我假设POST将是这个端点的方法,但让我给您展示一个示例。
from fastapi import FastAPI, Form
from fastapi.responses import FileResponse
import os
app = FastAPI()
@app.post("/download_file")
async def do
这个问题可能是以前提出的,但他们没有答案。我尝试使用pdfkit库创建一个具有阿拉伯语支持的pdf文件。因此,首先我从下载了一个预先构建的pdfkit版本(假设它在浏览器中工作)。
然后,我编写了这段代码,用于添加阿拉伯字体(类似于)。
const doc = new PDFDocument;
var text_arabic = "مرحبا مَرْحَبًا";
// Using a TrueType font (.ttf)
doc.font('./trado.ttf') // --> this line gives the error.
我试图使用pdfkit python库将HTML转换为pdf。我跟踪了来自的文档。
目前,我正试图将纯文本转换成PDF格式,而不是整个html文档。一切都很好,但是我看到的不是文字,而是在生成的PDF中看到的框。这是我的密码。
import pdfkit
config = pdfkit.configuration(wkhtmltopdf='/usr/local/bin/wkhtmltopdf/wkhtmltox/bin/wkhtmltopdf')
content = 'This is a paragraph which I am trying to convert to
当我使用下面的代码时,我得到了上面的错误。
var pdf = new PDFDocument({
autoFirstPage: false
});
pdf.fontSize(10);
var table = new PdfTable(pdf, {
bottomMargin: 30,
});
for (var l = 0; l < attendance.length; l++) {
pdf
.text("Employee Name : "+attendance[l].empl
我正尝试在Flask中使用pdfkit生成PDF。pdfkit在本地运行良好,但当我在Google App Engine中使用它时,它会引发以下错误。
Traceback (most recent call last):
File "C:\Python27\flaskapp\flask\app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python27\flaskapp\flask\app.py", line 1360, in full