【问题标题】:Open PDF-file instead of saving it with weasyprint in pythonOpen PDF-file instead of saving it with weasyprint in python
【发布时间】:2022-12-28 00:38:08
【问题描述】:

I am creating a pdf file in python with the weasyprint package. Creation and saving it works fine but I would prefer python to simply create the PDF and open it in a viewer so that the reader can save it manually.

A sample code of the saving version is as follow:

from jinja2 import Environment, FileSystemLoader
from weasyprint import HTML


env = Environment(loader=FileSystemLoader('.'))

string = '<!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"><title>TEST</title></head><body><h2>Test</h2></body></html>'

HTML(string = string, base_url = '.').write_pdf('example.pdf')

How can I open the created PDF instead of saving it, please?

【问题讨论】:

    标签: python pdf weasyprint


    【解决方案1】:

    Do you mean that it was displayed in the browser instead of being downloaded as a file? Then it’s only related to the HTTP response headers, not at all with the PDF file itself.

    How do I force files to open in the browser instead of downloading (PDF)?

    【讨论】:

      猜你喜欢
      • 2022-12-04
      • 2022-12-27
      • 2016-11-17
      • 2022-12-28
      • 2022-12-28
      • 2022-12-01
      • 2013-09-30
      • 2023-02-20
      • 2019-12-15
      相关资源
      最近更新 更多