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

7 views
Skip to first unread message

Vincent Ycasas

unread,
Sep 23, 2013, 6:07:00 PM9/23/13
to pdfne...@googlegroups.com
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()
Reply all
Reply to author
Forward
0 new messages