-
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
1 parent
c975dd9
commit f1e1007
Showing
18 changed files
with
456 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <odr/internal/html/pdf2htmlEX_wrapper.hpp> | ||
|
||
#include <odr/exceptions.hpp> | ||
#include <odr/file.hpp> | ||
#include <odr/html.hpp> | ||
|
||
#include <odr/internal/common/file.hpp> | ||
|
||
#include <pdf2htmlEX.h> | ||
|
||
#include <cstring> | ||
#include <odr/internal/project_info.hpp> | ||
|
||
namespace odr::internal { | ||
|
||
Html html::pdf2htmlEX_wrapper(const std::string &input_path, | ||
const std::string &output_path, | ||
const HtmlConfig &config, | ||
std::optional<std::string> &password) { | ||
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.setInputFilename(input_path); | ||
pdf2htmlEX.setDestinationDir(output_path); | ||
auto output_file_name = "document.html"; | ||
pdf2htmlEX.setOutputFilename(output_file_name); | ||
|
||
pdf2htmlEX.setDRM(false); | ||
pdf2htmlEX.setProcessOutline(false); | ||
pdf2htmlEX.setProcessAnnotation(true); | ||
|
||
if (password.has_value()) { | ||
pdf2htmlEX.setOwnerPassword(password.value()); | ||
pdf2htmlEX.setUserPassword(password.value()); | ||
} | ||
|
||
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,23 @@ | ||
#ifndef ODR_INTERNAL_PDF2HTMLEX_WRAPPER_HPP | ||
#define ODR_INTERNAL_PDF2HTMLEX_WRAPPER_HPP | ||
|
||
#include <optional> | ||
#include <string> | ||
|
||
namespace odr { | ||
class PdfFile; | ||
|
||
struct HtmlConfig; | ||
class Html; | ||
} // namespace odr | ||
|
||
namespace odr::internal::html { | ||
|
||
Html pdf2htmlEX_wrapper(const std::string &input_path, | ||
const std::string &output_path, | ||
const HtmlConfig &config, | ||
std::optional<std::string> &password); | ||
|
||
} | ||
|
||
#endif // ODR_INTERNAL_PDF2HTMLEX_WRAPPER_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,52 @@ | ||
#include <odr/exceptions.hpp> | ||
#include <odr/file.hpp> | ||
#include <odr/html.hpp> | ||
#include <odr/internal/common/file.hpp> | ||
#include <odr/internal/html/wvWare_wrapper.hpp> | ||
#include <odr/internal/project_info.hpp> | ||
#include <unistd.h> | ||
#include <wv/wv.h> | ||
|
||
namespace odr::internal::html { | ||
|
||
Html wvWare_wrapper(const std::string &input_path, | ||
const std::string &output_path, const HtmlConfig &config, | ||
std::optional<std::string> &password) { | ||
if (nullptr == g_wvDataDir) { | ||
g_wvDataDir = WVDATADIR; | ||
} | ||
|
||
auto output_file_path = output_path + "/document.html"; | ||
|
||
char *input_file_path = strdup(input_path.c_str()); | ||
char *output_dir = strdup(output_path.c_str()); | ||
|
||
g_htmlOutputFileHandle = fopen(output_file_path.c_str(), "w"); | ||
|
||
std::string pw; | ||
if (password.has_value()) { | ||
pw = password.value(); | ||
} | ||
int retVal = wvHtml_convert(input_file_path, output_dir, pw.c_str()); | ||
free(output_dir); | ||
free(input_file_path); | ||
fclose(g_htmlOutputFileHandle); | ||
g_htmlOutputFileHandle = nullptr; | ||
|
||
if (0 != retVal) { | ||
unlink(output_file_path.c_str()); | ||
|
||
switch (retVal) { | ||
case 100: // PasswordRequired | ||
case 101: // Wrong Password | ||
throw WrongPassword(); | ||
default: | ||
throw std::runtime_error("Conversion error"); | ||
} | ||
} | ||
|
||
return { | ||
FileType::legacy_word_document, config, {{"document", output_file_path}}}; | ||
} | ||
|
||
} // namespace odr::internal::html |
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,22 @@ | ||
#ifndef ODR_INTERNAL_WVWARE_WRAPPER_HPP | ||
#define ODR_INTERNAL_WVWARE_WRAPPER_HPP | ||
|
||
#include <optional> | ||
#include <string> | ||
|
||
namespace odr { | ||
class File; | ||
|
||
struct HtmlConfig; | ||
class Html; | ||
} // namespace odr | ||
|
||
namespace odr::internal::html { | ||
|
||
Html wvWare_wrapper(const std::string &input_path, | ||
const std::string &output_path, const HtmlConfig &config, | ||
std::optional<std::string> &password); | ||
|
||
} | ||
|
||
#endif // ODR_INTERNAL_WVWARE_WRAPPER_HPP |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
#ifndef ODR_INTERNAL_PROJECT_INFO_HPP | ||
#define ODR_INTERNAL_PROJECT_INFO_HPP | ||
|
||
namespace odr::internal::project_info { | ||
const char *version() noexcept; | ||
} // namespace odr::internal::project_info | ||
|
||
#cmakedefine WITH_PDF2HTMLEX 1 | ||
#cmakedefine PDF2HTMLEX_DATA_DIR "@PDF2HTMLEX_DATA_DIR@" | ||
#cmakedefine POPPLER_DATA_DIR "@POPPLER_DATA_DIR@" | ||
#cmakedefine FONTCONFIG_PATH "@FONTCONFIG_PATH@" | ||
#cmakedefine WITH_WVWARE 1 | ||
#cmakedefine WVDATADIR "@WVDATADIR@" | ||
|
||
#endif // ODR_INTERNAL_PROJECT_INFO_HPP |
Oops, something went wrong.