| 1 |
/** |
| 2 |
* SPDX-FileCopyrightText: (C) 2005 Dominik Seichter <[email protected]> |
| 3 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef IMAGE_EXTRACTOR_H |
| 7 |
#define IMAGE_EXTRACTOR_H |
| 8 |
|
| 9 |
#include <podofo/podofo.h> |
| 10 |
|
| 11 |
/** This class uses the PoDoFo lib to parse |
| 12 |
* a PDF file and to write all images it finds |
| 13 |
* in this PDF document to a given directory. |
| 14 |
*/ |
| 15 |
class ImageExtractor |
| 16 |
{ |
| 17 |
static constexpr unsigned MAX_PATH = 512; |
| 18 |
|
| 19 |
public: |
| 20 |
ImageExtractor(); |
| 21 |
|
| 22 |
/** |
| 23 |
* \param pnNum pointer to an integer were |
| 24 |
* the number of processed images can be stored |
| 25 |
* or null if you do not want this information. |
| 26 |
*/ |
| 27 |
void Init(const std::string_view& input, const std::string_view& output); |
| 28 |
|
| 29 |
/** |
| 30 |
* \returns the number of successfully extracted images |
| 31 |
*/ |
| 32 |
inline unsigned GetNumImagesExtracted() const; |
| 33 |
|
| 34 |
private: |
| 35 |
/** Extracts the image form the given PdfObject |
| 36 |
* which has to be an XObject with Subtype "Image" |
| 37 |
* \param obj a handle to a PDF object |
| 38 |
* \param jpeg if true extract as a jpeg, otherwise create a ppm |
| 39 |
* \returns ErrOk on success |
| 40 |
*/ |
| 41 |
void ExtractImage(const PoDoFo::PdfObject& obj, bool jpeg); |
| 42 |
|
| 43 |
/** This function checks whether a file with the |
| 44 |
* given filename does exist. |
| 45 |
* \returns true if the file exists otherwise false |
| 46 |
*/ |
| 47 |
bool FileExists(const std::string_view& filepath); |
| 48 |
|
| 49 |
private: |
| 50 |
std::string_view m_outputDirectory; |
| 51 |
unsigned m_ImageCount; |
| 52 |
unsigned m_fileCounter; |
| 53 |
char m_buffer[MAX_PATH]; |
| 54 |
}; |
| 55 |
|
| 56 |
inline unsigned ImageExtractor::GetNumImagesExtracted() const |
| 57 |
{ |
| 58 |
return m_ImageCount; |
| 59 |
} |
| 60 |
|
| 61 |
#endif // IMAGE_EXTRACTOR_H |