Hello!
I'm working with code that implements an in-memory file-like object. I've been working through several examples from Stackoverflow and a few Python/Django development blogs that give the following example, or something similar to it, using Python 2.7 and PyPDF.
from pyPdf import PdfFileWriter, PdfFileReader
import StringIO
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
buffer = StringIO.StringIO()
# create a new PDF with Reportlab
c = canvas.Canvas(packet, pagesize=letter)
c.drawString(100,100, "Hello world")
c.save()
#move to the beginning of the StringIO buffer
buffer.seek(0)
new_pdf = PdfFileReader(buffer)
My implementation requires me to use PyPDF2 and Python 3.4.x. Given similar code, I receive the exception:
TypeError: string argument expected, got 'bytes'Using:
from io import StringIO
from reportlab.pdfgen import canvas
buffer = StringIO()
c = canvas.Canvas(buffer)
c.drawString(100, 100, "Hello world")
c.save()Python 3.4.1 on Windows 7 64-bit, Reportlab 3.1.8 installed via pip.
Can anyone help me get through the
Canvas.save() call? What am I doing wrong here?