Closed cmh234 closed 1 year ago
I found a solution
To save your altered PDF to memory in an object that can be passed around (instead of writing to a file), simply create an empty instance of io.BytesIO:
from io import BytesIO
new_bytes_object = BytesIO() Then, use fillpdfs.write_fillable_pdf(BytesIO(byte_value), new_bytes_object, {'name': 'my name'}, flatten=False) Before you attempt to read from new_bytes_object, don't forget to seek(0) back to the beginning, or rewind it. Otherwise, the object seems empty.
new_bytes_object.seek(0) s3.put_object(Body=new_bytes_object, Bucket=bucket, Key=key2, ContentType='application/pdf')
This works because io.BytesIO objects act like a file object, also known as a file-like object. It and related classes like io.StringIO behave like files in memory
Retrieved from: https://stackoverflow.com/questions/68985391/writing-a-python-pdfrw-pdfreader-object-to-an-array-of-bytes-filestream
Hi I can read the PDF from AWS S3 like this.
How do I get to output byte data that I can put on AWS?
fillpdfs.write_fillable_pdf(BytesIO(byte_value), output_pdf_path, {'name': 'my name'}, flatten=False)