-
Notifications
You must be signed in to change notification settings - Fork 0
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
12 changed files
with
994 additions
and
654 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Declaring Constants during Compilation | ||
|
||
```bash | ||
|
||
set(IMAGE_FOLDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/images") | ||
set(INPUT_OPEN_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/images/screenshot.png") | ||
|
||
|
||
target_compile_definitions(${TEST_EXECUTABLE} | ||
PRIVATE IMAGE_FOLDER_PATH="${IMAGE_FOLDER_PATH}" | ||
PRIVATE INPUT_OPEN_TEST_PATH="${INPUT_OPEN_TEST_PATH}" | ||
) | ||
|
||
const auto *const imgFolder = IMAGE_FOLDER_PATH; | ||
|
||
const std::string imgFolder = IMAGE_FOLDER_PATH; | ||
|
||
``` | ||
|
||
```cpp | ||
namespace { | ||
const auto *const inputOpenTest = INPUT_OPEN_TEST_PATH; | ||
|
||
const std::string cmake_var = std::string(VAR) + "/somefile.txt"; | ||
|
||
} // namespace | ||
``` |
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,35 @@ | ||
|
||
#include <leptonica/allheaders.h> | ||
#include <llvm/Support/raw_ostream.h> | ||
#include <tesseract/baseapi.h> | ||
#include <tesseract/renderer.h> | ||
|
||
void createPDF(const std::string &input_path, | ||
const std::string &output_path, | ||
const char *tessdata_path, | ||
bool text_only = false) { | ||
// const char *datapath = "/opt/homebrew/opt/tesseract/share/tessdata"; | ||
|
||
auto *api = new tesseract::TessBaseAPI(); | ||
if (api->Init(tessdata_path, "eng") != 0) { | ||
llvm::errs() << "Error: Could not initialize Tesseract OCR API." << '\n'; | ||
llvm::errs() << "Tessdata path: " << tessdata_path << '\n'; | ||
delete api; // Don't forget to delete api in case of failure | ||
return; | ||
} | ||
|
||
auto *renderer = new tesseract::TessPDFRenderer(output_path.c_str(), tessdata_path, text_only); | ||
|
||
bool succeed = api->ProcessPages(input_path.c_str(), nullptr, 0, renderer); | ||
if (!succeed) { | ||
llvm::errs() << "Error: Failed to process pages." << '\n'; | ||
llvm::errs() << "Input file: " << input_path << '\n'; | ||
llvm::errs() << "Output file: " << output_path << '\n'; | ||
} else { | ||
llvm::outs() << "PDF creation succeeded." << '\n'; | ||
} | ||
|
||
api->End(); | ||
delete api; | ||
delete renderer; | ||
} |
Oops, something went wrong.