embed a new file in a PDF (not only /EmbeddedFiles entries)
(
pdf,
buf,
filename,
ufilename,
desc,
compress,
)
| 19214 | |
| 19215 | |
| 19216 | def JM_embed_file( |
| 19217 | pdf, |
| 19218 | buf, |
| 19219 | filename, |
| 19220 | ufilename, |
| 19221 | desc, |
| 19222 | compress, |
| 19223 | ): |
| 19224 | ''' |
| 19225 | embed a new file in a PDF (not only /EmbeddedFiles entries) |
| 19226 | ''' |
| 19227 | len_ = 0 |
| 19228 | val = mupdf.pdf_new_dict(pdf, 6) |
| 19229 | mupdf.pdf_dict_put_dict(val, PDF_NAME('CI'), 4) |
| 19230 | ef = mupdf.pdf_dict_put_dict(val, PDF_NAME('EF'), 4) |
| 19231 | mupdf.pdf_dict_put_text_string(val, PDF_NAME('F'), filename) |
| 19232 | mupdf.pdf_dict_put_text_string(val, PDF_NAME('UF'), ufilename) |
| 19233 | mupdf.pdf_dict_put_text_string(val, PDF_NAME('Desc'), desc) |
| 19234 | mupdf.pdf_dict_put(val, PDF_NAME('Type'), PDF_NAME('Filespec')) |
| 19235 | bs = b' ' |
| 19236 | f = mupdf.pdf_add_stream( |
| 19237 | pdf, |
| 19238 | #mupdf.fz_fz_new_buffer_from_copied_data(bs), |
| 19239 | mupdf.fz_new_buffer_from_copied_data(bs), |
| 19240 | mupdf.PdfObj(), |
| 19241 | 0, |
| 19242 | ) |
| 19243 | mupdf.pdf_dict_put(ef, PDF_NAME('F'), f) |
| 19244 | JM_update_stream(pdf, f, buf, compress) |
| 19245 | len_, _ = mupdf.fz_buffer_storage(buf) |
| 19246 | mupdf.pdf_dict_put_int(f, PDF_NAME('DL'), len_) |
| 19247 | mupdf.pdf_dict_put_int(f, PDF_NAME('Length'), len_) |
| 19248 | params = mupdf.pdf_dict_put_dict(f, PDF_NAME('Params'), 4) |
| 19249 | mupdf.pdf_dict_put_int(params, PDF_NAME('Size'), len_) |
| 19250 | return val |
| 19251 | |
| 19252 | |
| 19253 | def JM_embedded_clean(pdf): |
no test coverage detected
searching dependent graphs…