0

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?

okost
  • 181
  • 9

1 Answers1

-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)?

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 28 '22 at 09:22