Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions All/All_Datalogics_64Bit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AddDigitalSignatureCMS", ".
EndProject
Project("{1D787362-28C9-4460-9606-840F3B484350}") = "AddDigitalSignatureRFC3161", "..\Security\AddDigitalSignatureRFC3161\AddDigitalSignatureRFC3161.vcxproj", "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OCRImage", "..\OCR\OCRImage\OCRImage.vcxproj", "{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -491,6 +493,10 @@ Global
{1D787362-28C9-4460-9606-840F3B484350}.Debug|x64.Build.0 = Debug|x64
{1D787362-28C9-4460-9606-840F3B484350}.Release|x64.ActiveCfg = Release|x64
{1D787362-28C9-4460-9606-840F3B484350}.Release|x64.Build.0 = Release|x64
{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}.Debug|x64.ActiveCfg = Debug|x64
{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}.Debug|x64.Build.0 = Debug|x64
{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}.Release|x64.ActiveCfg = Release|x64
{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 6 additions & 0 deletions All/All_Datalogics_ARM64.sln
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AddDigitalSignatureCMS", ".
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AddDigitalSignatureRFC3161", "..\Security\AddDigitalSignatureRFC3161\AddDigitalSignatureRFC3161.vcxproj", "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OCRImage", "..\OCR\OCRImage\OCRImage.vcxproj", "{CFABC1FE-3F70-47E9-A911-EA085E6D127A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Expand Down Expand Up @@ -485,6 +487,10 @@ Global
{1D787362-28C9-4460-9606-840F3B484350}.Debug|ARM64.Build.0 = Debug|ARM64
{1D787362-28C9-4460-9606-840F3B484350}.Release|ARM64.ActiveCfg = Release|ARM64
{1D787362-28C9-4460-9606-840F3B484350}.Release|ARM64.Build.0 = Release|ARM64
{CFABC1FE-3F70-47E9-A911-EA085E6D127A}.Debug|ARM64.ActiveCfg = Debug|ARM64
{CFABC1FE-3F70-47E9-A911-EA085E6D127A}.Debug|ARM64.Build.0 = Debug|ARM64
{CFABC1FE-3F70-47E9-A911-EA085E6D127A}.Release|ARM64.ActiveCfg = Release|ARM64
{CFABC1FE-3F70-47E9-A911-EA085E6D127A}.Release|ARM64.Build.0 = Release|ARM64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions All/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ SAMPLES = Annotations/CreateAnnotations \
Images/RenderPage \
InformationExtraction/CountColorsInDoc \
InformationExtraction/ExtractDocumentInfo \
OCR/OCRImage \
Printing/PostScriptInjection \
Security/AddDigitalSignatureCMS \
Security/AddDigitalSignatureRFC3161 \
Expand Down
3 changes: 2 additions & 1 deletion All/build_run_all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,14 @@ SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% ContentExtraction\ExtractAttachments"
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% ContentExtraction\ExtractFonts"
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% InformationExtraction\CountColorsInDoc"
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% InformationExtraction\ExtractDocumentInfo"
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% OCR\OCRImage"
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% FileSystem\AlternateFileSystem"

REM *** The total number of DL samples. This must be accurate!
IF NOT "%ARCH%"=="ARM64" (
SET /A "NUM_DL_SAMPLES=73"
) ELSE (
SET /A "NUM_DL_SAMPLES=74"
SET /A "NUM_DL_SAMPLES=75"
)


Expand Down
1 change: 1 addition & 0 deletions All/build_run_all_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ declare -a DL_SAMPLE_LIST=( \
"Images/OutputPreview" \
"InformationExtraction/CountColorsInDoc" \
"InformationExtraction/ExtractDocumentInfo" \
"OCR/OCRImage" \
"Printing/PostScriptInjection" \
"Security/AESEncryption" \
"Security/AddDigitalSignatureCMS" \
Expand Down
7 changes: 7 additions & 0 deletions All/run_all_DL_samples_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ cd ../../InformationExtraction/ExtractDocumentInfo
./ExtractDocumentInfo-${stage}.app/Contents/MacOS/ExtractDocumentInfo-${stage}
echo ""

# OCR

echo Running sample OCRImage
cd ../../OCR/OCRImage
./OCRImage-${stage}.app/Contents/MacOS/OCRImage-${stage}
echo ""

# Printing

echo Running sample PostScriptInjection
Expand Down
7 changes: 7 additions & 0 deletions OCR/OCRImage/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SAMPNAME=OCRImage
OTHER_OBJS = $(SAMPNAME).o

include ../../dlutils/common.mak

$(SAMPNAME).o: $(SRC)/$(SAMPNAME).cpp

110 changes: 110 additions & 0 deletions OCR/OCRImage/OCRImage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//
// Copyright (c) 2017-2025, Datalogics, Inc. All rights reserved.
//
//
// The OCRImage sample demonstrates how the Library works to OCR an image.
//
// Command-line: <output-file> (Optional)
//

#include <iostream>

#include "ASExtraCalls.h"
#include "DLExtrasCalls.h"
#include "PSFCalls.h"
#include "PERCalls.h"
#include "PEWCalls.h"
#include "PagePDECntCalls.h"
#include "PagePDECntCalls.h"
#include "OCREngineCalls.h"

#include "InitializeLibrary.h"
#include "APDFLDoc.h"

#define DIR_LOC "../../../../Resources/Sample_Input/"
#define DEF_INPUT "OCRImage.png"
#define DEF_OUTPUT "OCRImage-out.pdf"

int main(int argc, char **argv) {
APDFLib libInit;
ASErrorCode errCode = 0;
if (libInit.isValid() == false) {
errCode = libInit.getInitError();
std::cout << "Initialization failed with code " << errCode << std::endl;
return libInit.getInitError();
}

std::string csInputFileName(argc > 1 ? argv[1] : DIR_LOC DEF_INPUT);
std::string csOutputFileName(argc > 2 ? argv[2] : DEF_OUTPUT);
std::cout << "Recognizing text in " << csInputFileName.c_str() << std::endl;

ASPathName sInput = APDFLDoc::makePath(csInputFileName.c_str());
ASPathName sOutput = APDFLDoc::makePath(csOutputFileName.c_str());

DURING
// Sets the correct location for the OCREngine function table.
gOCREngineHFT = InitOCREngineHFT;

// Initialize the OCREngine plugin.
if (!OCREngineInitialize()) {
std::cout << "The OCREngine plugin failed to initialize." << std::endl;
errCode = -1;
}

if (0 == errCode) {
// Create a PDEImage object to perform OCR on.
PDEImage image = DLCreatePDEImageFromFile(sInput, nullptr);

// Set default OCR parameters.
OCRParamsRec ocrParams = PDOCRDefaultParams();

// Set languages to configure OCREngine with.
OCRLanguage newLanguages[] = {OCRLanguage_English, OCRLanguage_French, OCRLanguage_ChineseTraditional,
OCRLanguage_ChineseSimplified, OCRLanguage_Japanese};

ASInt32 numLanguages = sizeof(newLanguages) / sizeof(newLanguages[0]);
PDOCRParamsSetLanguagesConfigured(&ocrParams, newLanguages, numLanguages);

// Create the destination document for the created form.
PDDoc doc = PDDocCreate();

ASFixedRect mediaBox = {};
mediaBox.left = fixedZero;
mediaBox.right = FloatToASFixed(72.0 * 8.5);
mediaBox.bottom = fixedZero;
mediaBox.top = FloatToASFixed(72.0 * 11.0);

PDPage page = PDDocCreatePage(doc, kPDEBeforeFirst, mediaBox);

// Run OCR on the image to get Form element containing the image with text underneath.
PDEForm form = PDOCRCreateForm(&ocrParams, doc, image, 300, OCRMissingFontStrategy_Raise);

// Put that form into the page in the destination document.
PDEContent content = PDPageAcquirePDEContent(page, 0);
PDEContentAddElem(content, PDEContentGetNumElems(content) - 1, (PDEElement)form);
PDPageSetPDEContent(page, 0);

// Save the output.
PDDocSave(doc, PDSaveFull | PDSaveLinearized, sOutput, NULL, NULL, NULL);

// Release resources.
PDPageReleasePDEContent(page, 0);
PDPageRelease(page);
PDDocClose(doc);

PDERelease((PDEObject)form);
PDERelease(reinterpret_cast<PDEObject>(image));
ASFileSysReleasePath(NULL, sInput);
ASFileSysReleasePath(NULL, sOutput);

// Release OCREngine resources and terminate the plugin.
PDOCRReleaseParams(&ocrParams);
OCREngineTerminate();
} // if 0 == errCode
HANDLER
errCode = ERRORCODE;
libInit.displayError(errCode);
END_HANDLER

return errCode; // APDFLib's destructor terminates the library.
}
Loading