Skip to content

Commit e367b21

Browse files
Merge pull request #79 from datalogics/develop
Sync main with develop for release 18.0.5PlusP1w
2 parents 109479f + bfa2f65 commit e367b21

15 files changed

+453
-7
lines changed

All/All_Datalogics_64Bit.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AddDigitalSignatureCMS", ".
165165
EndProject
166166
Project("{1D787362-28C9-4460-9606-840F3B484350}") = "AddDigitalSignatureRFC3161", "..\Security\AddDigitalSignatureRFC3161\AddDigitalSignatureRFC3161.vcxproj", "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"
167167
EndProject
168+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OCRImage", "..\OCR\OCRImage\OCRImage.vcxproj", "{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}"
169+
EndProject
168170
Global
169171
GlobalSection(SolutionConfigurationPlatforms) = preSolution
170172
Debug|x64 = Debug|x64
@@ -491,6 +493,10 @@ Global
491493
{1D787362-28C9-4460-9606-840F3B484350}.Debug|x64.Build.0 = Debug|x64
492494
{1D787362-28C9-4460-9606-840F3B484350}.Release|x64.ActiveCfg = Release|x64
493495
{1D787362-28C9-4460-9606-840F3B484350}.Release|x64.Build.0 = Release|x64
496+
{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}.Debug|x64.ActiveCfg = Debug|x64
497+
{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}.Debug|x64.Build.0 = Debug|x64
498+
{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}.Release|x64.ActiveCfg = Release|x64
499+
{26B0DAAC-1B6E-4020-BEC0-D47DDBA263C6}.Release|x64.Build.0 = Release|x64
494500
EndGlobalSection
495501
GlobalSection(SolutionProperties) = preSolution
496502
HideSolutionNode = FALSE

All/All_Datalogics_ARM64.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AddDigitalSignatureCMS", ".
163163
EndProject
164164
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AddDigitalSignatureRFC3161", "..\Security\AddDigitalSignatureRFC3161\AddDigitalSignatureRFC3161.vcxproj", "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"
165165
EndProject
166+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OCRImage", "..\OCR\OCRImage\OCRImage.vcxproj", "{CFABC1FE-3F70-47E9-A911-EA085E6D127A}"
167+
EndProject
166168
Global
167169
GlobalSection(SolutionConfigurationPlatforms) = preSolution
168170
Debug|ARM64 = Debug|ARM64
@@ -485,6 +487,10 @@ Global
485487
{1D787362-28C9-4460-9606-840F3B484350}.Debug|ARM64.Build.0 = Debug|ARM64
486488
{1D787362-28C9-4460-9606-840F3B484350}.Release|ARM64.ActiveCfg = Release|ARM64
487489
{1D787362-28C9-4460-9606-840F3B484350}.Release|ARM64.Build.0 = Release|ARM64
490+
{CFABC1FE-3F70-47E9-A911-EA085E6D127A}.Debug|ARM64.ActiveCfg = Debug|ARM64
491+
{CFABC1FE-3F70-47E9-A911-EA085E6D127A}.Debug|ARM64.Build.0 = Debug|ARM64
492+
{CFABC1FE-3F70-47E9-A911-EA085E6D127A}.Release|ARM64.ActiveCfg = Release|ARM64
493+
{CFABC1FE-3F70-47E9-A911-EA085E6D127A}.Release|ARM64.Build.0 = Release|ARM64
488494
EndGlobalSection
489495
GlobalSection(SolutionProperties) = preSolution
490496
HideSolutionNode = FALSE

All/GNUmakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ SAMPLES = Annotations/CreateAnnotations \
7878
Images/RenderPage \
7979
InformationExtraction/CountColorsInDoc \
8080
InformationExtraction/ExtractDocumentInfo \
81+
OCR/OCRImage \
8182
Printing/PostScriptInjection \
8283
Security/AddDigitalSignatureCMS \
8384
Security/AddDigitalSignatureRFC3161 \

All/build_run_all.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,14 @@ SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% ContentExtraction\ExtractAttachments"
250250
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% ContentExtraction\ExtractFonts"
251251
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% InformationExtraction\CountColorsInDoc"
252252
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% InformationExtraction\ExtractDocumentInfo"
253+
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% OCR\OCRImage"
253254
SET "DL_SAMPLE_LIST=%DL_SAMPLE_LIST% FileSystem\AlternateFileSystem"
254255

255256
REM *** The total number of DL samples. This must be accurate!
256257
IF NOT "%ARCH%"=="ARM64" (
257258
SET /A "NUM_DL_SAMPLES=73"
258259
) ELSE (
259-
SET /A "NUM_DL_SAMPLES=74"
260+
SET /A "NUM_DL_SAMPLES=75"
260261
)
261262

262263

All/build_run_all_mac.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ declare -a DL_SAMPLE_LIST=( \
109109
"Images/OutputPreview" \
110110
"InformationExtraction/CountColorsInDoc" \
111111
"InformationExtraction/ExtractDocumentInfo" \
112+
"OCR/OCRImage" \
112113
"Printing/PostScriptInjection" \
113114
"Security/AESEncryption" \
114115
"Security/AddDigitalSignatureCMS" \

All/run_all_DL_samples_mac.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ cd ../../InformationExtraction/ExtractDocumentInfo
269269
./ExtractDocumentInfo-${stage}.app/Contents/MacOS/ExtractDocumentInfo-${stage}
270270
echo ""
271271

272+
# OCR
273+
274+
echo Running sample OCRImage
275+
cd ../../OCR/OCRImage
276+
./OCRImage-${stage}.app/Contents/MacOS/OCRImage-${stage}
277+
echo ""
278+
272279
# Printing
273280

274281
echo Running sample PostScriptInjection

OCR/OCRImage/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SAMPNAME=OCRImage
2+
OTHER_OBJS = $(SAMPNAME).o
3+
4+
include ../../dlutils/common.mak
5+
6+
$(SAMPNAME).o: $(SRC)/$(SAMPNAME).cpp
7+

OCR/OCRImage/OCRImage.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//
2+
// Copyright (c) 2017-2025, Datalogics, Inc. All rights reserved.
3+
//
4+
//
5+
// The OCRImage sample demonstrates how the Library works to OCR an image.
6+
//
7+
// Command-line: <output-file> (Optional)
8+
//
9+
10+
#include <iostream>
11+
12+
#include "ASExtraCalls.h"
13+
#include "DLExtrasCalls.h"
14+
#include "PSFCalls.h"
15+
#include "PERCalls.h"
16+
#include "PEWCalls.h"
17+
#include "PagePDECntCalls.h"
18+
#include "PagePDECntCalls.h"
19+
#include "OCREngineCalls.h"
20+
21+
#include "InitializeLibrary.h"
22+
#include "APDFLDoc.h"
23+
24+
#define DIR_LOC "../../../../Resources/Sample_Input/"
25+
#define DEF_INPUT "OCRImage.png"
26+
#define DEF_OUTPUT "OCRImage-out.pdf"
27+
28+
int main(int argc, char **argv) {
29+
APDFLib libInit;
30+
ASErrorCode errCode = 0;
31+
if (libInit.isValid() == false) {
32+
errCode = libInit.getInitError();
33+
std::cout << "Initialization failed with code " << errCode << std::endl;
34+
return libInit.getInitError();
35+
}
36+
37+
std::string csInputFileName(argc > 1 ? argv[1] : DIR_LOC DEF_INPUT);
38+
std::string csOutputFileName(argc > 2 ? argv[2] : DEF_OUTPUT);
39+
std::cout << "Recognizing text in " << csInputFileName.c_str() << std::endl;
40+
41+
ASPathName sInput = APDFLDoc::makePath(csInputFileName.c_str());
42+
ASPathName sOutput = APDFLDoc::makePath(csOutputFileName.c_str());
43+
44+
DURING
45+
// Sets the correct location for the OCREngine function table.
46+
gOCREngineHFT = InitOCREngineHFT;
47+
48+
// Initialize the OCREngine plugin.
49+
if (!OCREngineInitialize()) {
50+
std::cout << "The OCREngine plugin failed to initialize." << std::endl;
51+
errCode = -1;
52+
}
53+
54+
if (0 == errCode) {
55+
// Create a PDEImage object to perform OCR on.
56+
PDEImage image = DLCreatePDEImageFromFile(sInput, nullptr);
57+
58+
// Set default OCR parameters.
59+
OCRParamsRec ocrParams = PDOCRDefaultParams();
60+
61+
// Set languages to configure OCREngine with.
62+
OCRLanguage newLanguages[] = {OCRLanguage_English, OCRLanguage_French, OCRLanguage_ChineseTraditional,
63+
OCRLanguage_ChineseSimplified, OCRLanguage_Japanese};
64+
65+
ASInt32 numLanguages = sizeof(newLanguages) / sizeof(newLanguages[0]);
66+
PDOCRParamsSetLanguagesConfigured(&ocrParams, newLanguages, numLanguages);
67+
68+
// Create the destination document for the created form.
69+
PDDoc doc = PDDocCreate();
70+
71+
ASFixedRect mediaBox = {};
72+
mediaBox.left = fixedZero;
73+
mediaBox.right = FloatToASFixed(72.0 * 8.5);
74+
mediaBox.bottom = fixedZero;
75+
mediaBox.top = FloatToASFixed(72.0 * 11.0);
76+
77+
PDPage page = PDDocCreatePage(doc, kPDEBeforeFirst, mediaBox);
78+
79+
// Run OCR on the image to get Form element containing the image with text underneath.
80+
PDEForm form = PDOCRCreateForm(&ocrParams, doc, image, 300, OCRMissingFontStrategy_Raise);
81+
82+
// Put that form into the page in the destination document.
83+
PDEContent content = PDPageAcquirePDEContent(page, 0);
84+
PDEContentAddElem(content, PDEContentGetNumElems(content) - 1, (PDEElement)form);
85+
PDPageSetPDEContent(page, 0);
86+
87+
// Save the output.
88+
PDDocSave(doc, PDSaveFull | PDSaveLinearized, sOutput, NULL, NULL, NULL);
89+
90+
// Release resources.
91+
PDPageReleasePDEContent(page, 0);
92+
PDPageRelease(page);
93+
PDDocClose(doc);
94+
95+
PDERelease((PDEObject)form);
96+
PDERelease(reinterpret_cast<PDEObject>(image));
97+
ASFileSysReleasePath(NULL, sInput);
98+
ASFileSysReleasePath(NULL, sOutput);
99+
100+
// Release OCREngine resources and terminate the plugin.
101+
PDOCRReleaseParams(&ocrParams);
102+
OCREngineTerminate();
103+
} // if 0 == errCode
104+
HANDLER
105+
errCode = ERRORCODE;
106+
libInit.displayError(errCode);
107+
END_HANDLER
108+
109+
return errCode; // APDFLib's destructor terminates the library.
110+
}

0 commit comments

Comments
 (0)