首页 > 解决方案 > 非英语字符集的输出 pdf 中的 Python pdfkit 问题

问题描述

pdfkit 是否支持亚洲语言,我来自印度,所以我的问题与 python 脚本中的印地语和马拉地语有关

我正在使用 pdfkit 成功地以英语从 URL 生成 pdf,但是如果我尝试其他一些非英语语言的 URL,它会在 pdf 中生成一些垃圾字符,我的代码是

options = {
'page-size': 'Letter',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'encoding': "UTF-8",
'custom-header' : [('Accept-Encoding', 'gzip')],
'cookie': [
('cookie-name1', 'cookie-value1'),
('cookie-name2', 'cookie-value2'),
],
'no-outline': None
}
import requests
from bs4 import BeautifulSoup
from urllib import request, response, error, parse
from urllib.request import urlopen
import pdfkit
config=pdfkit.configuration(wkhtmltopdf="c:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe")
pdfkit.from_url(URL,'c:\temp\sample.pdf', configuration=config, options=options)

我尝试使用示例 URL google.co.in,但它正在打印一些垃圾字符。

我的目标网址是https://www.loksatta.com/kolhapur-news/politics-on-the-backdrop-of-the-upcoming-elections-of-the-gokul-district-central-co-operative-banks -abn-97-2195442/

你能建议和帮助吗?

谢谢

标签: pythonpython-3.x

解决方案


推荐阅读