File tree Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 14
14
import zipfile
15
15
16
16
17
- def log( text):
18
- print( f'mupdfpy: {text}', file=sys.stdout)
17
+ def log( text, caller=1):
18
+ import inspect
19
+ frame_record = inspect.stack( context=0)[ caller]
20
+ filename = frame_record.filename
21
+ line = frame_record.lineno
22
+ function = frame_record.function
23
+ print( f'{filename}:{line}:{function}: {text}', file=sys.stdout)
19
24
sys.stdout.flush()
20
25
21
26
# Try to detect if we are being used with current directory set to a mupdfpy/
@@ -7524,8 +7529,8 @@ def _insert_image(self,
7524
7529
#log( 'do_process_pixmap')
7525
7530
# process pixmap ---------------------------------
7526
7531
arg_pix = pixmap.this
7527
- w = arg_pix.w
7528
- h = arg_pix.h
7532
+ w = arg_pix.w()
7533
+ h = arg_pix.h()
7529
7534
digest = mupdf.fz_md5_pixmap2(arg_pix)
7530
7535
md5_py = digest
7531
7536
temp = digests.get(md5_py, None)
@@ -7538,7 +7543,7 @@ def _insert_image(self,
7538
7543
do_have_image = 0
7539
7544
else:
7540
7545
if arg_pix.alpha() == 0:
7541
- image = mupdf.fz_new_image_from_pixmap(arg_pix, mupdf.FzImage(0 ))
7546
+ image = mupdf.fz_new_image_from_pixmap(arg_pix, mupdf.FzImage())
7542
7547
else:
7543
7548
pm = mupdf.fz_convert_pixmap(
7544
7549
arg_pix,
Original file line number Diff line number Diff line change @@ -25,3 +25,23 @@ def test_insert():
25
25
bbox2 = fitz .Rect (info_list [1 ]["bbox" ])
26
26
assert bbox1 in r1
27
27
assert bbox2 in r2
28
+
29
+ def test_compress ():
30
+ document = fitz .open (f'{ scriptdir } /resources/2.pdf' )
31
+ document_new = fitz .open ()
32
+ for page in document :
33
+ pixmap = page .get_pixmap (
34
+ colorspace = fitz .csRGB ,
35
+ dpi = 72 ,
36
+ annots = False ,
37
+ )
38
+ page_new = document_new .new_page (- 1 )
39
+ page_new .insert_image (rect = page_new .bound (), pixmap = pixmap )
40
+ document_new .save (
41
+ f'{ scriptdir } /resources/2.pdf.compress.pdf' ,
42
+ garbage = 3 ,
43
+ deflate = True ,
44
+ deflate_images = True ,
45
+ deflate_fonts = True ,
46
+ pretty = True ,
47
+ )
You can’t perform that action at this time.
0 commit comments