diff options
-rw-r--r-- | PolyglotFile/polyglotszippdf.py | 9 | ||||
-rwxr-xr-x | truepolyglot | 12 |
2 files changed, 16 insertions, 5 deletions
diff --git a/PolyglotFile/polyglotszippdf.py b/PolyglotFile/polyglotszippdf.py index 0796946..eadf5d0 100644 --- a/PolyglotFile/polyglotszippdf.py +++ b/PolyglotFile/polyglotszippdf.py @@ -28,8 +28,9 @@ from PdfFileTransformer import Pdf class PolyglotSZipPdf(PolyglotPdfZip): - def __init__(self, Pdf, Zip): + def __init__(self, Pdf, Zip, acrobat_compatibility): super().__init__(Pdf, Zip) + self.acrobat_compatibility = acrobat_compatibility def get_rebuild_zip_first_part_size(self): @@ -82,7 +83,11 @@ class PolyglotSZipPdf(PolyglotPdfZip): new_pdf.file_offset = offset pdf_buffer = new_pdf.get_build_buffer() j2 = pdf_buffer[k2_stream_offset + size_k2_stream:] - new_zip.add_data_to_file(b'', j2, True) + + if self.acrobat_compatibility: + new_zip.add_data_to_file(b'\x00', j2, True) + else: + new_zip.add_data_to_file(b'', j2, True) return new_zip.buffer diff --git a/truepolyglot b/truepolyglot index 2ff9269..4b4075f 100755 --- a/truepolyglot +++ b/truepolyglot @@ -19,7 +19,7 @@ def main(): ' The format is strictly a ZIP.' + ' Archive is modified.') usage_str = '%(prog)s format [options] output-file' - epilog_str = 'TruePolyglot v1.3' + epilog_str = 'TruePolyglot v1.4.1' frm = argparse.RawTextHelpFormatter parser = argparse.ArgumentParser(description=description_str, epilog=epilog_str, @@ -33,8 +33,12 @@ def main(): help='PDF input file') parser.add_argument('--zipfile', dest='zipfile', help='ZIP input file') + parser.add_argument('--acrobat-compatibility', + dest='acrobat_compatibility', + help='Add a byte at start for Acrobat Reader compatibility with szippdf format', + action='store_true') parser.add_argument('--verbose', dest='verbose', - help='Verbosity level (default: debug)', + help='Verbosity level (default: info)', default="info", choices=["none", "error", "info", "debug"]) parser.add_argument('output_file', nargs='+', @@ -43,6 +47,8 @@ def main(): args = parser.parse_args() formats = ["pdfzip", "zippdf", "szippdf"] + if args.acrobat_compatibility and args.format[0] != "szippdf": + parser.error('--acrobat-compatibility is for szippdf only') if args.format[0] in formats: if args.pdffile is None: parser.error('pdffile is required') @@ -65,7 +71,7 @@ def main(): if args.format[0] == "zippdf": a = PolyglotZipPdf(p, z) if args.format[0] == "szippdf": - a = PolyglotSZipPdf(p, z) + a = PolyglotSZipPdf(p, z, args.acrobat_compatibility) a.generate() a.write(args.output_file[0]) |