Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/source/tools/pdfbake.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 // Copyright (C) 2004-2024 Artifex Software, Inc. | |
| 2 // | |
| 3 // This file is part of MuPDF. | |
| 4 // | |
| 5 // MuPDF is free software: you can redistribute it and/or modify it under the | |
| 6 // terms of the GNU Affero General Public License as published by the Free | |
| 7 // Software Foundation, either version 3 of the License, or (at your option) | |
| 8 // any later version. | |
| 9 // | |
| 10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | |
| 13 // details. | |
| 14 // | |
| 15 // You should have received a copy of the GNU Affero General Public License | |
| 16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html> | |
| 17 // | |
| 18 // Alternative licensing terms are available from the licensor. | |
| 19 // For commercial licensing, see <https://www.artifex.com/> or contact | |
| 20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, | |
| 21 // CA 94129, USA, for further information. | |
| 22 | |
| 23 /* | |
| 24 * PDF baking tool: Bake interactive form and/or annotation content into static graphics. | |
| 25 */ | |
| 26 | |
| 27 #include "mupdf/fitz.h" | |
| 28 #include "mupdf/pdf.h" | |
| 29 | |
| 30 #include <stdlib.h> | |
| 31 #include <stdio.h> | |
| 32 #include <string.h> | |
| 33 | |
| 34 static int usage(void) | |
| 35 { | |
| 36 fprintf(stderr, | |
| 37 "usage: mutool bake [options] input.pdf [output.pdf]\n" | |
| 38 "\t-A\tkeep annotations\n" | |
| 39 "\t-F\tkeep forms\n" | |
| 40 "\t-O -\tcomma separated list of output options\n" | |
| 41 ); | |
| 42 return 1; | |
| 43 } | |
| 44 | |
| 45 int pdfbake_main(int argc, char **argv) | |
| 46 { | |
| 47 fz_context *ctx; | |
| 48 pdf_document *doc; | |
| 49 pdf_write_options opts = pdf_default_write_options; | |
| 50 int bake_annots = 1; | |
| 51 int bake_widgets = 1; | |
| 52 char *output = "out.pdf"; | |
| 53 char *flags = "garbage"; | |
| 54 char *input; | |
| 55 int c; | |
| 56 | |
| 57 while ((c = fz_getopt(argc, argv, "AFO:")) != -1) | |
| 58 { | |
| 59 switch (c) | |
| 60 { | |
| 61 case 'A': | |
| 62 bake_annots = 0; | |
| 63 break; | |
| 64 case 'F': | |
| 65 bake_widgets = 0; | |
| 66 break; | |
| 67 case 'O': | |
| 68 flags = fz_optarg; | |
| 69 break; | |
| 70 default: | |
| 71 return usage(); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 if (argc - fz_optind < 1) | |
| 76 return usage(); | |
| 77 | |
| 78 input = argv[fz_optind++]; | |
| 79 if (argc - fz_optind > 0) | |
| 80 output = fz_optpath(argv[fz_optind++]); | |
| 81 | |
| 82 ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED); | |
| 83 if (!ctx) | |
| 84 { | |
| 85 fprintf(stderr, "error: Cannot initialize MuPDF context.\n"); | |
| 86 exit(1); | |
| 87 } | |
| 88 | |
| 89 fz_try(ctx) | |
| 90 { | |
| 91 doc = pdf_open_document(ctx, input); | |
| 92 | |
| 93 pdf_bake_document(ctx, doc, bake_annots, bake_widgets); | |
| 94 | |
| 95 pdf_parse_write_options(ctx, &opts, flags); | |
| 96 pdf_save_document(ctx, doc, output, &opts); | |
| 97 } | |
| 98 fz_catch(ctx) | |
| 99 { | |
| 100 fz_report_error(ctx); | |
| 101 return 1; | |
| 102 } | |
| 103 | |
| 104 pdf_drop_document(ctx, doc); | |
| 105 fz_flush_warnings(ctx); | |
| 106 fz_drop_context(ctx); | |
| 107 return 0; | |
| 108 } |
