| 1 | /** |
| 2 | * SPDX-FileCopyrightText: (C) 2008 Dominik Seichter <[email protected]> |
| 3 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | #include <cstdlib> |
| 8 | #include <cstdio> |
| 9 | |
| 10 | #include <podofo/podofo.h> |
| 11 | |
| 12 | using namespace std; |
| 13 | using namespace PoDoFo; |
| 14 | |
| 15 | void print_help() |
| 16 | { |
| 17 | printf("Usage: podofotxtextract [inputfile]\n\n"); |
| 18 | printf("\nPoDoFo Version: %s\n\n", PODOFO_VERSION_STRING); |
| 19 | } |
| 20 | |
| 21 | void Main(const cspan<string_view>& args) |
| 22 | { |
| 23 | string_view input; |
| 24 | if (args.size() != 2) |
| 25 | { |
| 26 | print_help(); |
| 27 | exit(-1); |
| 28 | } |
| 29 | |
| 30 | input = args[1]; |
| 31 | |
| 32 | PdfMemDocument doc; |
| 33 | doc.Load(input); |
| 34 | auto& pages = doc.GetPages(); |
| 35 | for (unsigned i = 0; i < pages.GetCount(); i++) |
| 36 | { |
| 37 | auto& page = pages.GetPageAt(i); |
| 38 | |
| 39 | vector<PdfTextEntry> entries; |
| 40 | page.ExtractTextTo(entries); |
| 41 | |
| 42 | for (auto& entry : entries) |
| 43 | printf("(%.3f,%.3f) %s \n", entry.X, entry.Y, entry.Text.data()); |
| 44 | } |
| 45 | } |