-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
175 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <odr/internal/html/pdf_poppler_file.hpp> | ||
|
||
#include <odr/exceptions.hpp> | ||
#include <odr/file.hpp> | ||
#include <odr/html.hpp> | ||
|
||
#include <odr/internal/common/file.hpp> | ||
#include <odr/internal/pdf_poppler/poppler_pdf_file.hpp> | ||
#include <odr/internal/project_info.hpp> | ||
|
||
#include <pdf2htmlEX.h> | ||
|
||
#include <cstring> | ||
|
||
namespace odr::internal { | ||
|
||
Html html::translate_pdf_poppler_file(const PopplerPdfFile &pdf_file, | ||
const std::string &output_path, | ||
const HtmlConfig &config) { | ||
static const char *fontconfig_path = getenv("FONTCONFIG_PATH"); | ||
if (nullptr == fontconfig_path) { | ||
// Storage is allocated and after successful putenv, it will never be freed. | ||
// This is the way of putenv. | ||
char *storage = strdup("FONTCONFIG_PATH=" FONTCONFIG_PATH); | ||
if (0 != putenv(storage)) { | ||
free(storage); | ||
} | ||
fontconfig_path = getenv("FONTCONFIG_PATH"); | ||
} | ||
|
||
pdf2htmlEX::pdf2htmlEX pdf2htmlEX; | ||
pdf2htmlEX.setDataDir(PDF2HTMLEX_DATA_DIR); | ||
pdf2htmlEX.setPopplerDataDir(POPPLER_DATA_DIR); | ||
|
||
pdf2htmlEX.setDestinationDir(output_path); | ||
auto output_file_name = "document.html"; | ||
pdf2htmlEX.setOutputFilename(output_file_name); | ||
|
||
pdf2htmlEX.setDRM(false); | ||
pdf2htmlEX.setProcessOutline(false); | ||
pdf2htmlEX.setProcessAnnotation(true); | ||
|
||
try { | ||
pdf2htmlEX.convert(); | ||
} catch (const pdf2htmlEX::EncryptionPasswordException &e) { | ||
throw WrongPassword(); | ||
} catch (const pdf2htmlEX::DocumentCopyProtectedException &e) { | ||
throw std::runtime_error("document is copy protected"); | ||
} catch (const pdf2htmlEX::ConversionFailedException &e) { | ||
throw std::runtime_error(std::string("conversion error ") + e.what()); | ||
} | ||
|
||
return {FileType::portable_document_format, | ||
config, | ||
{{"document", output_path + "/" + output_file_name}}}; | ||
} | ||
|
||
} // namespace odr::internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef ODR_INTERNAL_HTML_PDF_POPPLER_FILE_HPP | ||
#define ODR_INTERNAL_HTML_PDF_POPPLER_FILE_HPP | ||
|
||
#include <string> | ||
|
||
namespace odr { | ||
class PopplerPdfFile; | ||
|
||
struct HtmlConfig; | ||
class Html; | ||
} // namespace odr | ||
|
||
namespace odr::internal::html { | ||
|
||
Html translate_pdf_poppler_file(const PopplerPdfFile &pdf_file, | ||
const std::string &output_path, | ||
const HtmlConfig &config); | ||
|
||
} | ||
|
||
#endif // ODR_INTERNAL_HTML_PDF_POPPLER_FILE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <odr/internal/pdf_poppler/poppler_pdf_file.hpp> | ||
|
||
#include <odr/internal/common/path.hpp> | ||
|
||
#include <poppler/PDFDocFactory.h> | ||
#include <poppler/goo/GooString.h> | ||
|
||
namespace odr::internal::poppler_pdf { | ||
|
||
PopplerPdfFile::PopplerPdfFile(std::shared_ptr<common::DiskFile> file) | ||
: m_file{std::move(file)} { | ||
GooString file_path(file->disk_path()->string().c_str()); | ||
m_pdf_doc = std::unique_ptr<PDFDoc>(PDFDocFactory().createPDFDoc(file_path)); | ||
} | ||
|
||
FileCategory PopplerPdfFile::file_category() const noexcept { | ||
return FileCategory::document; | ||
} | ||
|
||
std::shared_ptr<abstract::File> PopplerPdfFile::file() const noexcept { | ||
return m_file; | ||
} | ||
|
||
FileType PopplerPdfFile::file_type() const noexcept { | ||
return FileType::portable_document_format; | ||
} | ||
|
||
FileMeta PopplerPdfFile::file_meta() const noexcept { return {}; } | ||
|
||
DecoderEngine PopplerPdfFile::decoder_engine() const noexcept { | ||
return DecoderEngine::poppler; | ||
} | ||
|
||
const PDFDoc &PopplerPdfFile::pdf_doc() const { return *m_pdf_doc; } | ||
|
||
} // namespace odr::internal::poppler_pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef ODR_INTERNAL_POPPLER_PDF_FILE_HPP | ||
#define ODR_INTERNAL_POPPLER_PDF_FILE_HPP | ||
|
||
#include <odr/internal/common/file.hpp> | ||
|
||
class PDFDoc; | ||
|
||
namespace odr::internal::poppler_pdf { | ||
|
||
class PopplerPdfFile : public abstract::DecodedFile { | ||
public: | ||
explicit PopplerPdfFile(std::shared_ptr<common::DiskFile> file); | ||
|
||
[[nodiscard]] std::shared_ptr<abstract::File> file() const noexcept final; | ||
|
||
[[nodiscard]] FileType file_type() const noexcept final; | ||
[[nodiscard]] FileCategory file_category() const noexcept final; | ||
[[nodiscard]] FileMeta file_meta() const noexcept final; | ||
[[nodiscard]] DecoderEngine decoder_engine() const noexcept final; | ||
|
||
[[nodiscard]] const PDFDoc &pdf_doc() const; | ||
|
||
private: | ||
std::shared_ptr<abstract::File> m_file; | ||
std::unique_ptr<PDFDoc> m_pdf_doc; | ||
}; | ||
|
||
} // namespace odr::internal::poppler_pdf | ||
|
||
#endif // ODR_INTERNAL_POPPLER_PDF_FILE_HPP |