Mercurial > hgrepos > Python2 > PyMuPDF
comparison src_classic/helper-portfolio.i @ 1:1d09e1dec1d9 upstream
ADD: PyMuPDF v1.26.4: the original sdist.
It does not yet contain MuPDF. This normally will be downloaded when
building PyMuPDF.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:37:51 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 1:1d09e1dec1d9 |
|---|---|
| 1 %{ | |
| 2 /* | |
| 3 # ------------------------------------------------------------------------ | |
| 4 # Copyright 2020-2022, Harald Lieder, mailto:harald.lieder@outlook.com | |
| 5 # License: GNU AFFERO GPL 3.0, https://www.gnu.org/licenses/agpl-3.0.html | |
| 6 # | |
| 7 # Part of "PyMuPDF", a Python binding for "MuPDF" (http://mupdf.com), a | |
| 8 # lightweight PDF, XPS, and E-book viewer, renderer and toolkit which is | |
| 9 # maintained and developed by Artifex Software, Inc. https://artifex.com. | |
| 10 # ------------------------------------------------------------------------ | |
| 11 */ | |
| 12 //----------------------------------------------------------------------------- | |
| 13 // perform some cleaning if we have /EmbeddedFiles: | |
| 14 // (1) remove any /Limits if /Names exists | |
| 15 // (2) remove any empty /Collection | |
| 16 // (3) set /PageMode/UseAttachments | |
| 17 //----------------------------------------------------------------------------- | |
| 18 void JM_embedded_clean(fz_context *ctx, pdf_document *pdf) | |
| 19 { | |
| 20 pdf_obj *root = pdf_dict_get(ctx, pdf_trailer(ctx, pdf), PDF_NAME(Root)); | |
| 21 | |
| 22 // remove any empty /Collection entry | |
| 23 pdf_obj *coll = pdf_dict_get(ctx, root, PDF_NAME(Collection)); | |
| 24 if (coll && pdf_dict_len(ctx, coll) == 0) | |
| 25 pdf_dict_del(ctx, root, PDF_NAME(Collection)); | |
| 26 | |
| 27 pdf_obj *efiles = pdf_dict_getl(ctx, root, | |
| 28 PDF_NAME(Names), | |
| 29 PDF_NAME(EmbeddedFiles), | |
| 30 PDF_NAME(Names), | |
| 31 NULL); | |
| 32 if (efiles) { | |
| 33 pdf_dict_put_name(ctx, root, PDF_NAME(PageMode), "UseAttachments"); | |
| 34 } | |
| 35 return; | |
| 36 } | |
| 37 | |
| 38 //----------------------------------------------------------------------------- | |
| 39 // embed a new file in a PDF (not only /EmbeddedFiles entries) | |
| 40 //----------------------------------------------------------------------------- | |
| 41 pdf_obj *JM_embed_file(fz_context *ctx, | |
| 42 pdf_document *pdf, | |
| 43 fz_buffer *buf, | |
| 44 char *filename, | |
| 45 char *ufilename, | |
| 46 char *desc, | |
| 47 int compress) | |
| 48 { | |
| 49 size_t len = 0; | |
| 50 pdf_obj *ef, *f, *params, *val = NULL; | |
| 51 fz_buffer *buff2 = NULL; | |
| 52 fz_var(buff2); | |
| 53 fz_try(ctx) { | |
| 54 val = pdf_new_dict(ctx, pdf, 6); | |
| 55 pdf_dict_put_dict(ctx, val, PDF_NAME(CI), 4); | |
| 56 ef = pdf_dict_put_dict(ctx, val, PDF_NAME(EF), 4); | |
| 57 pdf_dict_put_text_string(ctx, val, PDF_NAME(F), filename); | |
| 58 pdf_dict_put_text_string(ctx, val, PDF_NAME(UF), ufilename); | |
| 59 pdf_dict_put_text_string(ctx, val, PDF_NAME(Desc), desc); | |
| 60 pdf_dict_put(ctx, val, PDF_NAME(Type), PDF_NAME(Filespec)); | |
| 61 buff2 = fz_new_buffer_from_copied_data(ctx, " ", 1); | |
| 62 f = pdf_add_stream(ctx, pdf, buff2, NULL, 0); | |
| 63 pdf_dict_put_drop(ctx, ef, PDF_NAME(F), f); | |
| 64 JM_update_stream(ctx, pdf, f, buf, compress); | |
| 65 len = fz_buffer_storage(ctx, buf, NULL); | |
| 66 pdf_dict_put_int(ctx, f, PDF_NAME(DL), len); | |
| 67 pdf_dict_put_int(ctx, f, PDF_NAME(Length), len); | |
| 68 params = pdf_dict_put_dict(ctx, f, PDF_NAME(Params), 4); | |
| 69 pdf_dict_put_int(ctx, params, PDF_NAME(Size), len); | |
| 70 } | |
| 71 fz_always(ctx) { | |
| 72 fz_drop_buffer(ctx, buff2); | |
| 73 } | |
| 74 fz_catch(ctx) { | |
| 75 fz_rethrow(ctx); | |
| 76 } | |
| 77 return val; | |
| 78 } | |
| 79 %} |
