def test_unicode_filename(resources, outdir): target1 = outdir / '测试.pdf' target2 = outdir / '通过考试.pdf' shutil.copy(fspath(resources / 'pal-1bit-trivial.pdf'), fspath(target1)) pdf = Pdf.open(target1) pdf.save(target2) assert target2.exists()
def test_allow_overwriting_input(resources, tmp_path): orig_pdf_path = fspath(resources / 'pal-1bit-trivial.pdf') tmp_pdf_path = fspath(tmp_path / 'pal-1bit-trivial.pdf') shutil.copy(orig_pdf_path, tmp_pdf_path) with pikepdf.open(tmp_pdf_path, allow_overwriting_input=True) as pdf: with pdf.open_metadata() as meta: meta['dc:title'] = 'New Title' pdf.save('other.pdf', encryption=dict(owner="owner")) pdf.save() pdf.save(linearize=True) with pikepdf.open(tmp_pdf_path) as pdf: with pdf.open_metadata() as meta: assert meta['dc:title'] == 'New Title' with pikepdf.open(orig_pdf_path) as pdf: with pdf.open_metadata() as meta: assert 'dc:title' not in meta
def test_extract_filepath(congress, outdir): xobj, _pdf = congress pim = PdfImage(xobj) # fspath is for Python 3.5 result = pim.extract_to(fileprefix=fspath(outdir / 'image')) assert Path(result).exists() assert (outdir / 'image.jpg').exists()