Beispiel #1
0
def test_metadata_fixup_warning(resources, outdir, caplog):
    options = get_parser().parse_args(
        args=['--output-type', 'pdfa-2', 'graph.pdf', 'out.pdf']
    )

    copyfile(resources / 'graph.pdf', outdir / 'graph.pdf')

    context = PdfContext(
        options, outdir, outdir / 'graph.pdf', None, get_plugin_manager([])
    )
    metadata_fixup(working_file=outdir / 'graph.pdf', context=context)
    for record in caplog.records:
        assert record.levelname != 'WARNING'

    # Now add some metadata that will not be copyable
    graph = pikepdf.open(outdir / 'graph.pdf')
    with graph.open_metadata() as meta:
        meta['prism2:publicationName'] = 'OCRmyPDF Test'
    graph.save(outdir / 'graph_mod.pdf')

    context = PdfContext(
        options, outdir, outdir / 'graph_mod.pdf', None, get_plugin_manager([])
    )
    metadata_fixup(working_file=outdir / 'graph.pdf', context=context)
    assert any(record.levelname == 'WARNING' for record in caplog.records)
Beispiel #2
0
def post_process(pdf_file, context: PdfContext, executor: Executor):
    pdf_out = pdf_file
    if context.options.output_type.startswith('pdfa'):
        ps_stub_out = generate_postscript_stub(context)
        pdf_out = convert_to_pdfa(pdf_out, ps_stub_out, context)

    pdf_out = metadata_fixup(pdf_out, context)
    return optimize_pdf(pdf_out, context, executor)
Beispiel #3
0
def test_metadata_fixup_warning(resources, outdir, caplog):
    from ocrmypdf._pipeline import metadata_fixup

    input_files = [
        str(outdir / 'graph.repaired.pdf'),
        str(outdir / 'layers.rendered.pdf'),
        str(outdir / 'pdfa.pdf'),  # It is okay that this is not a PDF/A
    ]
    for f in input_files:
        copyfile(resources / 'graph.pdf', f)

    log = logging.getLogger()
    context = MagicMock()
    metadata_fixup(
        input_files_groups=input_files,
        output_file=outdir / 'out.pdf',
        log=log,
        context=context,
    )
    for record in caplog.records:
        assert record.levelname != 'WARNING'

    # Now add some metadata that will not be copyable
    with pikepdf.open(outdir / 'graph.repaired.pdf') as graph:
        with graph.open_metadata() as meta:
            meta['prism2:publicationName'] = 'OCRmyPDF Test'
        graph.save(outdir / 'graph.repaired.modified.pdf')
    move(outdir / 'graph.repaired.modified.pdf', outdir / 'graph.repaired.pdf')

    log = logging.getLogger()
    context = MagicMock()
    metadata_fixup(
        input_files_groups=input_files,
        output_file=outdir / 'out.pdf',
        log=log,
        context=context,
    )
    assert any(record.levelname == 'WARNING' for record in caplog.records)
Beispiel #4
0
def test_metadata_fixup_warning(resources, outdir, caplog):
    from ocrmypdf._pipeline import metadata_fixup

    input_files = [
        str(outdir / 'graph.repaired.pdf'),
        str(outdir / 'layers.rendered.pdf'),
        str(outdir / 'pdfa.pdf'),  # It is okay that this is not a PDF/A
    ]
    for f in input_files:
        copyfile(resources / 'graph.pdf', f)

    log = logging.getLogger()
    context = MagicMock()
    metadata_fixup(
        input_files_groups=input_files,
        output_file=outdir / 'out.pdf',
        log=log,
        context=context,
    )
    for record in caplog.records:
        assert record.levelname != 'WARNING'

    # Now add some metadata that will not be copyable
    graph = pikepdf.open(outdir / 'graph.repaired.pdf')
    with graph.open_metadata() as meta:
        meta['prism2:publicationName'] = 'OCRmyPDF Test'
    graph.save(outdir / 'graph.repaired.pdf')

    log = logging.getLogger()
    context = MagicMock()
    metadata_fixup(
        input_files_groups=input_files,
        output_file=outdir / 'out.pdf',
        log=log,
        context=context,
    )
    assert any(record.levelname == 'WARNING' for record in caplog.records)
Beispiel #5
0
def test_metadata_fixup_warning(resources, outdir):
    from ocrmypdf._pipeline import metadata_fixup

    input_files = [
        str(outdir / 'graph.repaired.pdf'),
        str(outdir / 'layers.rendered.pdf'),
        str(outdir / 'pdfa.pdf'),  # It is okay that this is not a PDF/A
    ]
    for f in input_files:
        copyfile(resources / 'graph.pdf', f)

    log = MagicMock()
    context = MagicMock()
    metadata_fixup(
        input_files_groups=input_files,
        output_file=outdir / 'out.pdf',
        log=log,
        context=context,
    )
    log.warning.assert_not_called()

    # Now add some metadata that will not be copyable
    graph = pikepdf.open(outdir / 'graph.repaired.pdf')
    with graph.open_metadata() as meta:
        meta['prism2:publicationName'] = 'OCRmyPDF Test'
    graph.save(outdir / 'graph.repaired.pdf')

    log = MagicMock()
    context = MagicMock()
    metadata_fixup(
        input_files_groups=input_files,
        output_file=outdir / 'out.pdf',
        log=log,
        context=context,
    )
    log.warning.assert_called_once()