From 35cb416563fb9c072caaf9de14af62d6fd26896a Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Wed, 16 May 2018 23:24:57 -0700 Subject: [PATCH] pipeline: remove fitz-based attempt to repair table of contents Prior to unsplit, if we were rebuilding the PDF we'd lose the table of contents. With unsplit we keep the original file and patch the table of contents as necessary, adn that works fine. This remaining bit of code from PyMuPDF actually damages the table of contents and removing it fixes the test suite. G'bye. --- src/ocrmypdf/pipeline.py | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/ocrmypdf/pipeline.py b/src/ocrmypdf/pipeline.py index c72b34ba..00a480ce 100644 --- a/src/ocrmypdf/pipeline.py +++ b/src/ocrmypdf/pipeline.py @@ -770,7 +770,16 @@ def metadata_fixup( ) if options.output_type.startswith('pdfa'): - _do_merge_ghostscript([layers_file, ps], output_file, log, context) + input_pdfinfo = context.get_pdfinfo() + ghostscript.generate_pdfa( + pdf_version=input_pdfinfo.min_version, + pdf_pages=[layers_file, ps], + output_file=output_file, + compression=options.pdfa_image_compression, + log=log, + threads=options.jobs or 1, + pdfa_part=options.output_type[-1] # is pdfa-1, pdfa-2, or pdfa-3 + ) else: metadata = pikepdf.open(metadata_file) pdfmark = get_pdfmark(metadata, options) @@ -779,30 +788,6 @@ def metadata_fixup( pdf.save(output_file) -def _do_merge_ghostscript( - pdf_pages, - output_file, - log, - context): - options = context.get_options() - input_pdfinfo = context.get_pdfinfo() - - ghostscript.generate_pdfa( - pdf_version=input_pdfinfo.min_version, - pdf_pages=pdf_pages, - output_file=output_file + '_toc.pdf', - compression=options.pdfa_image_compression, - log=log, - threads=options.jobs or 1, - pdfa_part=options.output_type[-1]) # is pdfa-1, pdfa-2, or pdfa-3 - if fitz: - doc = fitz.Document(output_file + '_toc.pdf') - doc.setToC(input_pdfinfo.table_of_contents) - doc.save(output_file, clean=False) - else: - os.replace(output_file + '_toc.pdf', output_file) - - def optimize_pdf( input_file, output_file,