I have a fitz.fitz.Page
object that I wanted to save as bytes
that I later want to upload to blob storage and have been unable to find out this in the fitz documentation
I do have the code to upload bytes to the blob storage though and just need help on the function store_fitz_page_as_bytes()
Mind you, I am not speaking about saving fitz.fitz.Document
object as bytes.. that's already known to me (by using the save method).
I basically want to store each page in fitz.fitz.Document
(each page will be of type fitz.fitz.Page
) as bytes.
import fitz
def store_fitz_page_as_bytes(fitz_page: fitz.fitz.Page)->bytes:
'''
need help here to convert fitz_page to bytes and return it.
-This needs to be done without any local storage
-fitz_page.select([0]) is not an option for me as I need to do this for all pages
'''
def upload_bytes_to_azure_blob(pdf_bytes):
'''
I already know this so don't really want to derail the conversation to this subject. Just mentioning this so that the forum knows my purpose
'''
#read a 200 page pdf as fitz.fitz.Document
fitz_doc = fitz.open("test.pdf")
print(type(fitz_doc))
#just get the first item from fitz_doc. It will be the first page from the 200 page pdf and will be of type fitz.fitz.Page
fitz_page = fitz_doc[0]
print(type(fitz_page))
#convert fitz_page from above to bytes
pdf_bytes = store_fitz_page_as_bytes(fitz_page)
#upload bytes to blob
upload_bytes_to_azure_blob(pdf_bytes)