diff options
author | ben | 2018-09-29 00:12:49 +0200 |
---|---|---|
committer | ben | 2018-09-29 00:12:49 +0200 |
commit | caaaaafeb09165971b49a948bab1ec2189031319 (patch) | |
tree | a08af0e16bd2f21319f3f158f9e6c46395705003 /PolyglotFile | |
parent | 7e962d60ad8f4eaf9defa1cc017d61a8ada4dc47 (diff) | |
download | truepolyglot-caaaaafeb09165971b49a948bab1ec2189031319.tar.gz truepolyglot-caaaaafeb09165971b49a948bab1ec2189031319.tar.bz2 truepolyglot-caaaaafeb09165971b49a948bab1ec2189031319.tar.xz |
Add pdfraw format, v1.5
Diffstat (limited to 'PolyglotFile')
-rw-r--r-- | PolyglotFile/__init__.py | 1 | ||||
-rw-r--r-- | PolyglotFile/polyglotpdfraw.py | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/PolyglotFile/__init__.py b/PolyglotFile/__init__.py index 4261a1a..6800028 100644 --- a/PolyglotFile/__init__.py +++ b/PolyglotFile/__init__.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from .polyglotpdfzip import PolyglotPdfZip +from .polyglotpdfraw import PolyglotPdfRaw from .polyglotzippdf import PolyglotZipPdf from .polyglotszippdf import PolyglotSZipPdf diff --git a/PolyglotFile/polyglotpdfraw.py b/PolyglotFile/polyglotpdfraw.py new file mode 100644 index 0000000..c524788 --- /dev/null +++ b/PolyglotFile/polyglotpdfraw.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- + +import logging + +''' + |-------------------------------| - + |--------- PDF Header ----------K1 | J1 + |-------------------------------| - + |----- PDF OBJ 1 = RAW Data ----K2 | + |-------------------------------| - + |---- Original PDF Ojbects -----K3 | J2 + |-------------------------------| - + |---------- Xref Table ---------| | + |-------------------------------K5 | + |----------- Trailer -----------| | + |-------------------------------| | +''' + + +class PolyglotPdfRaw(): + from PdfFileTransformer import Pdf + + def __init__(self, Pdf, Raw_filename): + self.buffer = bytearray() + self.pdf = Pdf + self.raw_filename = Raw_filename + self.buffer = bytearray() + + def generate(self): + raw_buffer = bytearray() + with open(self.raw_filename, "rb") as f: + raw_buffer = f.read() + k2_stream = raw_buffer + self.pdf.insert_new_obj_stream_at_start(k2_stream) + self.buffer = self.pdf.get_build_buffer() + + def write(self, filename): + fd = open(filename, "wb") + fd.write(self.buffer) + fd.close() |