I have a pdf file somewhere. This pdf is being send to the destination in equal amount of bytes (apart from the last chunk).
Let's say this pdf file is being read in like this in python:
with open(filename, 'rb') as file:
chunk = file.read(3000)
while chunk:
#the sending method here
await asyncio.sleep(0.5)
chunk = file.read(3000)
the question is: Can I construct a partial PDF file in the destination, while the leftover part of the document is being sent?
I tried it with pypdfium2 / PyPDF2, but they throw errors until the whole PDF file is arrived:
full_pdf = b''
def process(self, message):
self.full_pdf += message
partial = io.BytesIO(self.full_pdf)
try:
pdf=pypdfium2.PdfDocument(partial)
print(len(pdf))
except Exception as e:
print("error", e)
basically I'd like to get the pages of the document, even if it's not the whole document currently.
pypdfium2.raw). Take a look atpdfium/public/fpdf_dataavail.hif you're interested. Making use of these APIs will require some deeper knowledge of c/python/ctypes, though.