I am working on a simple program that works on 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)) if not bin: break strBin = bstr(bin) binlist.append(strBin) return binlist
After manipulating the list of bytes, I would like to get back the PDF file. Is there any way I can reconstruct the PDF file starting from the list of bytes?