update a stream object compress stream when beneficial
(doc, obj, buffer_, compress)
| 21903 | |
| 21904 | |
| 21905 | def JM_update_stream(doc, obj, buffer_, compress): |
| 21906 | ''' |
| 21907 | update a stream object |
| 21908 | compress stream when beneficial |
| 21909 | ''' |
| 21910 | if compress: |
| 21911 | length, _ = mupdf.fz_buffer_storage(buffer_) |
| 21912 | if length > 30: # ignore small stuff |
| 21913 | buffer_compressed = JM_compress_buffer(buffer_) |
| 21914 | assert isinstance(buffer_compressed, mupdf.FzBuffer) |
| 21915 | if buffer_compressed.m_internal: |
| 21916 | length_compressed, _ = mupdf.fz_buffer_storage(buffer_compressed) |
| 21917 | if length_compressed < length: # was it worth the effort? |
| 21918 | mupdf.pdf_dict_put( |
| 21919 | obj, |
| 21920 | mupdf.PDF_ENUM_NAME_Filter, |
| 21921 | mupdf.PDF_ENUM_NAME_FlateDecode, |
| 21922 | ) |
| 21923 | mupdf.pdf_update_stream(doc, obj, buffer_compressed, 1) |
| 21924 | return |
| 21925 | |
| 21926 | mupdf.pdf_update_stream(doc, obj, buffer_, 0) |
| 21927 | |
| 21928 | |
| 21929 | def JM_xobject_from_page(pdfout, fsrcpage, xref, gmap): |
no test coverage detected
searching dependent graphs…