Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
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()
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
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))
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