| 1 | /** |
| 2 | * SPDX-FileCopyrightText: (C) 2005 Dominik Seichter <[email protected]> |
| 3 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | #include <cstdio> |
| 7 | #include <cstdlib> |
| 8 | |
| 9 | #include "ImageConverter.h" |
| 10 | #include <podofo/podofo.h> |
| 11 | #include <podofo_config.h> |
| 12 | |
| 13 | using namespace std; |
| 14 | using namespace PoDoFo; |
| 15 | |
| 16 | static const char* s_formats[] = { |
| 17 | #ifdef PODOFO_HAVE_JPEG_LIB |
| 18 | "JPEG", |
| 19 | #endif // PODOFO_HAVE_JPEG_LIB |
| 20 | #ifdef PODOFO_HAVE_PNG_LIB |
| 21 | "PNG", |
| 22 | #endif // PODOFO_HAVE_PNG_LIB |
| 23 | #ifdef PODOFO_HAVE_TIFF_LIB |
| 24 | "TIFF", |
| 25 | #endif // PODOFO_HAVE_TIFF_LIB |
| 26 | nullptr, |
| 27 | }; |
| 28 | |
| 29 | void print_help() |
| 30 | { |
| 31 | printf("Usage: podofoimg2pdf [output.pdf] [-useimgsize] [image1 image2 image3 ...]\n\n"); |
| 32 | printf("Options:\n"); |
| 33 | printf(" -useimgsize Use the imagesize as page size, instead of A4\n"); |
| 34 | printf("\nPoDoFo Version: %s\n\n", PODOFO_VERSION_STRING); |
| 35 | printf("\n"); |
| 36 | printf("This tool will combine any number of images into a single PDF.\n"); |
| 37 | printf("This is useful to create a document from scanned images.\n"); |
| 38 | printf("Large pages will be scaled to fit the page and imags smaller\n"); |
| 39 | printf("than the defined page size, will be centered.\n"); |
| 40 | printf("\n"); |
| 41 | printf("Supported image formats:\n"); |
| 42 | |
| 43 | const char** formats = s_formats; |
| 44 | while (*formats) |
| 45 | { |
| 46 | printf("\t%s\n", *formats); |
| 47 | formats++; |
| 48 | } |
| 49 | printf("\n"); |
| 50 | } |
| 51 | |
| 52 | void Main(const cspan<string_view>& args) |
| 53 | { |
| 54 | string_view outputFilename; |
| 55 | if (args.size() < 3) |
| 56 | { |
| 57 | print_help(); |
| 58 | exit(-1); |
| 59 | } |
| 60 | |
| 61 | outputFilename = args[1]; |
| 62 | printf("Output filename: %s\n", outputFilename.data()); |
| 63 | |
| 64 | ImageConverter converter; |
| 65 | converter.SetOutputFilename(outputFilename); |
| 66 | for (unsigned i = 2; i < args.size(); i++) |
| 67 | { |
| 68 | string_view option = args[i]; |
| 69 | if (option == "-useimgsize") |
| 70 | { |
| 71 | converter.SetUseImageSize(true); |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | printf("Adding image: %s\n", args[i].data()); |
| 76 | converter.AddImage(args[i]); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | converter.Work(); |
| 81 | printf("Wrote PDF successfully: %s.\n", outputFilename.data()); |
| 82 | } |