how to preview a pdf in python without save it on hard drive

Viewed 45

how can i start/open a pdf temporaryfile? Or is it possible to start/open a pdf wrote in memory?

Here is my code:

"""python    
import PyPDF2, tempfile, subprocess

reader = PyPDF2.PdfReader("example.pdf")
writer = PyPDF2.PdfWriter()

for p in reader.pages:
    writer.add_page(p)    

tmpf = tempfile.NamedTemporaryFile(dir=".",suffix="sample.pdf")

with open(tmpf.name,"wb") as test:
    print(tmpf.name)
    writer.write(test)
    
    subprocess.call(("xdg-open",tmpf.name))
"""
0 Answers
Related