Nov-02-2021, 07:51 PM
Hello!
I am working on a simple program that works for PDF files. So far I’ve been able to read the PDF into a list of bytes with the following code:
I am working on a simple program that works for PDF files. So far I’ve been able to read the PDF into a list of bytes with the following code:
def bstr(n): # n in range 0-255 return ''.join([str(n >> x & 1) for x in (7,6,5,4,3,2,1,0)]) def read_binary(): f = open('source.pdf','rb') binlist = [ ] while True: bin = struct.unpack('B',f.read(1))[0] if not bin: break strBin = bstr(bin) binlist.append(strBin) return binlistAfter performing some math operations on the list of bit sequences, I would like to get back the PDF file. Is there any way I can reconstruct the PDF file starting from the list of bit sequences?