Can I Create a PDFDoc in Python Using the File Object Directly?

Question:

Can I Create a PDFDoc in Python Using the File Object Directly?

Answer:

Unfortunately, you cannot pass a file object directly, but you should be able to pass a bytearray data from a file object. The code snippet below shows you how to do this:

For Python 2.7.x

with open(‘myfile.pdf’, ‘rb’) as in_file:
contents = bytearray(in_file.read())
doc = PDFDoc(contents, len(contents))
page_count = doc.GetPageCount()
doc.Close()

1 Like