How to use the pikepdf.ObjectStreamMode function in pikepdf

To help you get started, we’ve selected a few pikepdf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pikepdf / pikepdf / tests / test_pdf.py View on Github external
def test_object_stream_mode_generated(trivial, outdir):
    trivial.save(
        outdir / '1.pdf',
        fix_metadata_version=True,
        object_stream_mode=pikepdf.ObjectStreamMode.generate,
    )
    assert b'/ObjStm' in (outdir / '1.pdf').read_bytes()

    trivial.save(
        outdir / '2.pdf',
        fix_metadata_version=False,
        object_stream_mode=pikepdf.ObjectStreamMode.generate,
    )
    assert b'/ObjStm' in (outdir / '2.pdf').read_bytes()
github pikepdf / pikepdf / tests / test_pdf.py View on Github external
def test_object_stream_mode_generated(trivial, outdir):
    trivial.save(
        outdir / '1.pdf',
        fix_metadata_version=True,
        object_stream_mode=pikepdf.ObjectStreamMode.generate,
    )
    assert b'/ObjStm' in (outdir / '1.pdf').read_bytes()

    trivial.save(
        outdir / '2.pdf',
        fix_metadata_version=False,
        object_stream_mode=pikepdf.ObjectStreamMode.generate,
    )
    assert b'/ObjStm' in (outdir / '2.pdf').read_bytes()
github jbarlow83 / OCRmyPDF / src / ocrmypdf / _pipeline.py View on Github external
context.log.debug(
                    "The following metadata fields were not copied: %r", not_copied
                )
            else:
                context.log.error(
                    "Some input metadata could not be copied."
                    "You may wish to examine the output PDF's XMP metadata."
                )
                context.log.info(
                    "The following metadata fields were not copied: %r", not_copied
                )
    pdf.save(
        output_file,
        compress_streams=True,
        preserve_pdfa=True,
        object_stream_mode=pikepdf.ObjectStreamMode.generate,
        linearize=(  # Don't linearize if optimize() will be linearizing too
            should_linearize(working_file, context) if options.optimize == 0 else False
        ),
    )
    original.close()
    pdf.close()
    return output_file
github jbarlow83 / OCRmyPDF / src / ocrmypdf / optimize.py View on Github external
jpeg_quality=0,  # Use default
        png_quality=0,
        jb2lossy=False,
    )

    with TemporaryDirectory() as td:
        context = PDFContext(options, td, infile, None)
        tmpout = Path(td) / 'out.pdf'
        optimize(
            infile,
            tmpout,
            context,
            dict(
                compress_streams=True,
                preserve_pdfa=True,
                object_stream_mode=pikepdf.ObjectStreamMode.generate,
            ),
        )
        copy(fspath(tmpout), fspath(outfile))
github jbarlow83 / OCRmyPDF / src / ocrmypdf / _pipeline_simple.py View on Github external
meta_original = original.open_metadata()
        not_copied = set(meta_original.keys()) - set(meta.keys())
        if not_copied:
            context.log.warning(
                "Some input metadata could not be copied because it is not "
                "permitted in PDF/A. You may wish to examine the output "
                "PDF's XMP metadata."
            )
            context.log.debug(
                "The following metadata fields were not copied: %r", not_copied
            )

    pdf.save(
        output_file,
        compress_streams=True,
        object_stream_mode=pikepdf.ObjectStreamMode.generate,
    )
    return output_file