Hello, good, I have the following code in Python that prints the number of pages and the data of a PDF, however, this only works if I call the PDF with a directory on my PC. What I want it to do is open the PDF for me using only the Bytes or Base64 string I provide without having to write a new PDF on my pc .
PDFBase64="JVBERi0xLjUNCiW1tbW1..."
Decodificado=base64.b64decode(PDFBase64)
documento=fitz.open(Decodificado)
print("Número de páginas: ",documento.page_count)
print("Datos: ",documento.metadata)```
Documentation I relied on: https://pymupdf.readthedocs.io/en/latest/document.html#Document
To tell pymupdf that we want to load the file from memory, we use the stream argument, whose documentation translated by me and google translate says:
Which, as we can see, accepts objects of type byte. We don't even need a stream.
In this sample code, we load a pdf from the internet (in byte form) and save it to disk, thus proving that the content was successfully retrieved (requires the requests library)
Final note: Sometimes the documentation answers our questions. It's always a good idea to review it before asking someone else. You could find the answer much more quickly and autonomously. To give you an idea of how useful it is, I never used this module and I was able to give you an answer c: