1 Commits
1.4 ... 1.4.1

Author SHA1 Message Date
ben
7e962d60ad Add acrobat reader compatibility for szipdf format 2018-09-28 22:55:53 +02:00
2 changed files with 16 additions and 5 deletions

View File

@@ -28,8 +28,9 @@ from PdfFileTransformer import Pdf
class PolyglotSZipPdf(PolyglotPdfZip): class PolyglotSZipPdf(PolyglotPdfZip):
def __init__(self, Pdf, Zip): def __init__(self, Pdf, Zip, acrobat_compatibility):
super().__init__(Pdf, Zip) super().__init__(Pdf, Zip)
self.acrobat_compatibility = acrobat_compatibility
def get_rebuild_zip_first_part_size(self): def get_rebuild_zip_first_part_size(self):
@@ -82,7 +83,11 @@ class PolyglotSZipPdf(PolyglotPdfZip):
new_pdf.file_offset = offset new_pdf.file_offset = offset
pdf_buffer = new_pdf.get_build_buffer() pdf_buffer = new_pdf.get_build_buffer()
j2 = pdf_buffer[k2_stream_offset + size_k2_stream:] 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 return new_zip.buffer

View File

@@ -19,7 +19,7 @@ def main():
' The format is strictly a ZIP.' + ' The format is strictly a ZIP.' +
' Archive is modified.') ' Archive is modified.')
usage_str = '%(prog)s format [options] output-file' usage_str = '%(prog)s format [options] output-file'
epilog_str = 'TruePolyglot v1.3' epilog_str = 'TruePolyglot v1.4.1'
frm = argparse.RawTextHelpFormatter frm = argparse.RawTextHelpFormatter
parser = argparse.ArgumentParser(description=description_str, parser = argparse.ArgumentParser(description=description_str,
epilog=epilog_str, epilog=epilog_str,
@@ -33,8 +33,12 @@ def main():
help='PDF input file') help='PDF input file')
parser.add_argument('--zipfile', dest='zipfile', parser.add_argument('--zipfile', dest='zipfile',
help='ZIP input file') 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', parser.add_argument('--verbose', dest='verbose',
help='Verbosity level (default: debug)', help='Verbosity level (default: info)',
default="info", default="info",
choices=["none", "error", "info", "debug"]) choices=["none", "error", "info", "debug"])
parser.add_argument('output_file', nargs='+', parser.add_argument('output_file', nargs='+',
@@ -43,6 +47,8 @@ def main():
args = parser.parse_args() args = parser.parse_args()
formats = ["pdfzip", "zippdf", "szippdf"] 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.format[0] in formats:
if args.pdffile is None: if args.pdffile is None:
parser.error('pdffile is required') parser.error('pdffile is required')
@@ -65,7 +71,7 @@ def main():
if args.format[0] == "zippdf": if args.format[0] == "zippdf":
a = PolyglotZipPdf(p, z) a = PolyglotZipPdf(p, z)
if args.format[0] == "szippdf": if args.format[0] == "szippdf":
a = PolyglotSZipPdf(p, z) a = PolyglotSZipPdf(p, z, args.acrobat_compatibility)
a.generate() a.generate()
a.write(args.output_file[0]) a.write(args.output_file[0])