向Python中的PDF转换降级,发行符号
我试图通过首先将其转换为HTML,然后再转换为PDF文件来将Markdown文件转换为PDF。
这是我的代码:
from tomark import Tomark
data = {
"EC2 - Other":"1.224009E-4",
"AmazonCloudWatch":"3.3099916",
"Amazon Elastic Compute Cloud - Compute":"34.582367",
"Amazon Virtual Private Cloud":"43.2"
}
for key, value in data.items():
data.update({key:"€" + value})
transposed_list = []
for k,v in data.items():
transposed_list.append({"Service": k, "Cost": v})
print(transposed_list)
markdown = Tomark.table(transposed_list)
print(markdown)
with open(r'path_to_file', 'w') as fp:
fp.write(markdown)
pass
#doc = aw.Document("new_md2.md")
#doc.save("Output2.pdf")
from markdown import markdown, markdownFromFile
import pdfkit
input_filename = r'path_to_md_file'
output_filename = 'README.pdf'
with open(input_filename, 'r') as f:
html_text = markdown(f.read(), output_format='xhtml', extensions=['markdown.extensions.tables'])
with open('html_format.html', 'w') as f:
f.write(html_text)
print(html_text)
config = pdfkit.configuration(wkhtmltopdf=r"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe")
pdfkit.from_string(html_text, output_filename, verbose=True)
PDF的输出未识别€符号。有人知道如何解决这个问题吗? 输出看起来像这样:
I am trying to convert a Markdown file to a pdf, by firstly converting it to HTML and then to a PDF file.
This is my code:
from tomark import Tomark
data = {
"EC2 - Other":"1.224009E-4",
"AmazonCloudWatch":"3.3099916",
"Amazon Elastic Compute Cloud - Compute":"34.582367",
"Amazon Virtual Private Cloud":"43.2"
}
for key, value in data.items():
data.update({key:"€" + value})
transposed_list = []
for k,v in data.items():
transposed_list.append({"Service": k, "Cost": v})
print(transposed_list)
markdown = Tomark.table(transposed_list)
print(markdown)
with open(r'path_to_file', 'w') as fp:
fp.write(markdown)
pass
#doc = aw.Document("new_md2.md")
#doc.save("Output2.pdf")
from markdown import markdown, markdownFromFile
import pdfkit
input_filename = r'path_to_md_file'
output_filename = 'README.pdf'
with open(input_filename, 'r') as f:
html_text = markdown(f.read(), output_format='xhtml', extensions=['markdown.extensions.tables'])
with open('html_format.html', 'w') as f:
f.write(html_text)
print(html_text)
config = pdfkit.configuration(wkhtmltopdf=r"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe")
pdfkit.from_string(html_text, output_filename, verbose=True)
The output of the PDF does not recognize the € symbol. Does anyone know how to fix this?
The output looks like this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论