diff --git a/src/__init__.py b/src/__init__.py index cf4e3db75..5fd1e7710 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -14,8 +14,13 @@ import zipfile -def log( text): - print( f'mupdfpy: {text}', file=sys.stdout) +def log( text, caller=1): + import inspect + frame_record = inspect.stack( context=0)[ caller] + filename = frame_record.filename + line = frame_record.lineno + function = frame_record.function + print( f'{filename}:{line}:{function}: {text}', file=sys.stdout) sys.stdout.flush() # Try to detect if we are being used with current directory set to a mupdfpy/ @@ -7524,8 +7529,8 @@ def _insert_image(self, #log( 'do_process_pixmap') # process pixmap --------------------------------- arg_pix = pixmap.this - w = arg_pix.w - h = arg_pix.h + w = arg_pix.w() + h = arg_pix.h() digest = mupdf.fz_md5_pixmap2(arg_pix) md5_py = digest temp = digests.get(md5_py, None) @@ -7538,7 +7543,7 @@ def _insert_image(self, do_have_image = 0 else: if arg_pix.alpha() == 0: - image = mupdf.fz_new_image_from_pixmap(arg_pix, mupdf.FzImage(0)) + image = mupdf.fz_new_image_from_pixmap(arg_pix, mupdf.FzImage()) else: pm = mupdf.fz_convert_pixmap( arg_pix, diff --git a/tests/test_insertimage.py b/tests/test_insertimage.py index 45f522547..8142448d4 100644 --- a/tests/test_insertimage.py +++ b/tests/test_insertimage.py @@ -25,3 +25,23 @@ def test_insert(): bbox2 = fitz.Rect(info_list[1]["bbox"]) assert bbox1 in r1 assert bbox2 in r2 + +def test_compress(): + document = fitz.open(f'{scriptdir}/resources/2.pdf') + document_new = fitz.open() + for page in document: + pixmap = page.get_pixmap( + colorspace=fitz.csRGB, + dpi=72, + annots=False, + ) + page_new = document_new.new_page(-1) + page_new.insert_image(rect=page_new.bound(), pixmap=pixmap) + document_new.save( + f'{scriptdir}/resources/2.pdf.compress.pdf', + garbage=3, + deflate=True, + deflate_images=True, + deflate_fonts=True, + pretty=True, + )