向Python中的PDF转换降级,发行符号

发布于 2025-01-27 08:16:16 字数 1351 浏览 3 评论 0原文

我试图通过首先将其转换为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:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文