MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_3863

Function test_3863

tests/test_annots.py:391–436  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

389 pdf.save(path) # Check the output PDF that the annotation is correctly drawn
390
391def test_3863():
392 path_in = os.path.normpath(f'{__file__}/../../tests/resources/test_3863.pdf')
393 path_out = os.path.normpath(f'{__file__}/../../tests/test_3863.pdf.pdf')
394
395 # Create redacted PDF.
396 print(f'Loading {path_in=}.')
397 with pymupdf.open(path_in) as document:
398
399 for num, page in enumerate(document):
400 print(f"Page {num + 1} - {page.rect}:")
401
402 for image in page.get_images(full=True):
403 print(f" - Image: {image}")
404
405 redact_rect = page.rect
406
407 if page.rotation in (90, 270):
408 redact_rect = pymupdf.Rect(0, 0, page.rect.height, page.rect.width)
409
410 page.add_redact_annot(redact_rect)
411 page.apply_redactions(images=pymupdf.PDF_REDACT_IMAGE_NONE)
412
413 print(f'Writing to {path_out=}.')
414 document.save(path_out)
415
416 with pymupdf.open(path_out) as document:
417 assert len(document) == 8
418
419 # Create PNG for each page of redacted PDF.
420 for num, page in enumerate(document):
421 path_png = f'{path_out}.{num}.png'
422 pixmap = page.get_pixmap()
423 print(f'Writing to {path_png=}.')
424 pixmap.save(path_png)
425 # Compare with expected png.
426
427 print(f'Comparing page PNGs with expected PNGs.')
428 for num, _ in enumerate(document):
429 path_png = f'{path_out}.{num}.png'
430 path_png_expected = f'{path_in}.pdf.{num}.png'
431 print(f'{path_png=}.')
432 print(f'{path_png_expected=}.')
433 rms = gentle_compare.pixmaps_rms(path_png, path_png_expected, ' ')
434 # We get small differences in sysinstall tests, where some
435 # thirdparty libraries can differ.
436 assert rms < 1
437
438def test_3758():
439 # This test requires input file that is not public, so is usually not

Callers

nothing calls this directly

Calls 5

get_imagesMethod · 0.80
add_redact_annotMethod · 0.80
apply_redactionsMethod · 0.80
saveMethod · 0.45
get_pixmapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…