@@ -57,7 +57,8 @@ This file is part of the iText (R) project.
57
57
import com .itextpdf .layout .font .FontProvider ;
58
58
import com .itextpdf .layout .properties .TextAlignment ;
59
59
import com .itextpdf .pdfa .PdfADocument ;
60
- import com .itextpdf .pdfocr .exceptions .OcrException ;
60
+ import com .itextpdf .pdfocr .exceptions .PdfOcrException ;
61
+ import com .itextpdf .pdfocr .exceptions .PdfOcrExceptionMessageConstant ;
61
62
import com .itextpdf .pdfocr .logs .PdfOcrLogMessageConstant ;
62
63
import com .itextpdf .pdfocr .statistics .PdfOcrOutputType ;
63
64
import com .itextpdf .pdfocr .statistics .PdfOcrOutputTypeStatisticsEvent ;
@@ -165,14 +166,14 @@ public final void setOcrPdfCreatorProperties(
165
166
* @return result PDF/A-3u {@link com.itextpdf.kernel.pdf.PdfDocument}
166
167
* object
167
168
*
168
- * @throws OcrException if it was not possible to read provided or
169
+ * @throws PdfOcrException if it was not possible to read provided or
169
170
* default font
170
171
*/
171
172
public final PdfDocument createPdfA (final List <File > inputImages ,
172
173
final PdfWriter pdfWriter ,
173
174
final DocumentProperties documentProperties ,
174
175
final PdfOutputIntent pdfOutputIntent )
175
- throws OcrException {
176
+ throws PdfOcrException {
176
177
LOGGER .info (MessageFormatUtil .format (
177
178
PdfOcrLogMessageConstant .START_OCR_FOR_IMAGES ,
178
179
inputImages .size ()));
@@ -220,13 +221,13 @@ public final PdfDocument createPdfA(final List<File> inputImages,
220
221
* @return result PDF/A-3u {@link com.itextpdf.kernel.pdf.PdfDocument}
221
222
* object
222
223
*
223
- * @throws OcrException if it was not possible to read provided or
224
+ * @throws PdfOcrException if it was not possible to read provided or
224
225
* default font
225
226
*/
226
227
public final PdfDocument createPdfA (final List <File > inputImages ,
227
228
final PdfWriter pdfWriter ,
228
229
final PdfOutputIntent pdfOutputIntent )
229
- throws OcrException {
230
+ throws PdfOcrException {
230
231
return createPdfA (inputImages , pdfWriter , new DocumentProperties (), pdfOutputIntent );
231
232
}
232
233
@@ -247,12 +248,12 @@ public final PdfDocument createPdfA(final List<File> inputImages,
247
248
*
248
249
* @return result {@link com.itextpdf.kernel.pdf.PdfDocument} object
249
250
*
250
- * @throws OcrException if provided font is incorrect
251
+ * @throws PdfOcrException if provided font is incorrect
251
252
*/
252
253
public final PdfDocument createPdf (final List <File > inputImages ,
253
254
final PdfWriter pdfWriter ,
254
255
final DocumentProperties documentProperties )
255
- throws OcrException {
256
+ throws PdfOcrException {
256
257
return createPdfA (inputImages , pdfWriter , documentProperties , null );
257
258
}
258
259
@@ -272,11 +273,11 @@ public final PdfDocument createPdf(final List<File> inputImages,
272
273
*
273
274
* @return result {@link com.itextpdf.kernel.pdf.PdfDocument} object
274
275
*
275
- * @throws OcrException if provided font is incorrect
276
+ * @throws PdfOcrException if provided font is incorrect
276
277
*/
277
278
public final PdfDocument createPdf (final List <File > inputImages ,
278
279
final PdfWriter pdfWriter )
279
- throws OcrException {
280
+ throws PdfOcrException {
280
281
return createPdfA (inputImages , pdfWriter , new DocumentProperties (), null );
281
282
}
282
283
@@ -288,12 +289,12 @@ public final PdfDocument createPdf(final List<File> inputImages,
288
289
* @param outPdfFile the {@link java.io.File} object to write final PDF document to
289
290
*
290
291
* @throws IOException signals that an I/O exception of some sort has occurred.
291
- * @throws OcrException if it was not possible to read provided or
292
+ * @throws PdfOcrException if it was not possible to read provided or
292
293
* default font
293
294
*/
294
295
public void createPdfFile (final List <File > inputImages ,
295
296
final File outPdfFile )
296
- throws OcrException , IOException {
297
+ throws PdfOcrException , IOException {
297
298
createPdfAFile (inputImages , outPdfFile , null );
298
299
}
299
300
@@ -308,13 +309,13 @@ public void createPdfFile(final List<File> inputImages,
308
309
* for PDF/A-3u document
309
310
*
310
311
* @throws IOException signals that an I/O exception of some sort has occurred
311
- * @throws OcrException if it was not possible to read provided or
312
+ * @throws PdfOcrException if it was not possible to read provided or
312
313
* default font
313
314
*/
314
315
public void createPdfAFile (final List <File > inputImages ,
315
316
final File outPdfFile ,
316
317
final PdfOutputIntent pdfOutputIntent )
317
- throws OcrException , IOException {
318
+ throws PdfOcrException , IOException {
318
319
DocumentProperties documentProperties = new DocumentProperties ();
319
320
if (ocrPdfCreatorProperties .getMetaInfo () != null ) {
320
321
documentProperties .setEventCountingMetaInfo (ocrPdfCreatorProperties .getMetaInfo ());
@@ -356,13 +357,13 @@ public final void setOcrEngine(final IOcrEngine reader) {
356
357
* @param imageData input image if it is a single page or its one page if
357
358
* this is a multi-page image
358
359
* @param createPdfA3u true if PDF/A3u document is being created
359
- * @throws OcrException if PDF/A3u document is being created and provided
360
+ * @throws PdfOcrException if PDF/A3u document is being created and provided
360
361
* font contains notdef glyphs
361
362
*/
362
363
private void addToCanvas (final PdfDocument pdfDocument ,
363
364
final Rectangle imageSize ,
364
365
final List <TextInfo > pageText , final ImageData imageData ,
365
- final boolean createPdfA3u ) throws OcrException {
366
+ final boolean createPdfA3u ) throws PdfOcrException {
366
367
final Rectangle rectangleSize =
367
368
ocrPdfCreatorProperties .getPageSize () == null
368
369
? imageSize : ocrPdfCreatorProperties .getPageSize ();
@@ -393,11 +394,11 @@ private void addToCanvas(final PdfDocument pdfDocument,
393
394
try {
394
395
addTextToCanvas (imageSize , pageText , canvas , multiplier ,
395
396
pdfPage .getMediaBox ());
396
- } catch (OcrException e ) {
397
+ } catch (PdfOcrException e ) {
397
398
LOGGER .error (MessageFormatUtil .format (
398
- OcrException .CANNOT_CREATE_PDF_DOCUMENT ,
399
+ PdfOcrExceptionMessageConstant .CANNOT_CREATE_PDF_DOCUMENT ,
399
400
e .getMessage ()));
400
- throw new OcrException ( OcrException .CANNOT_CREATE_PDF_DOCUMENT )
401
+ throw new PdfOcrException ( PdfOcrExceptionMessageConstant .CANNOT_CREATE_PDF_DOCUMENT )
401
402
.setMessageParams (e .getMessage ());
402
403
}
403
404
if (layers [1 ] != null ) {
@@ -427,9 +428,9 @@ private PdfDocument createPdfDocument(final PdfWriter pdfWriter,
427
428
&& !ocrPdfCreatorProperties .getPdfLang ().equals ("" );
428
429
if (createPdfA3u && !hasPdfLangProperty ) {
429
430
LOGGER .error (MessageFormatUtil .format (
430
- OcrException .CANNOT_CREATE_PDF_DOCUMENT ,
431
+ PdfOcrExceptionMessageConstant .CANNOT_CREATE_PDF_DOCUMENT ,
431
432
PdfOcrLogMessageConstant .PDF_LANGUAGE_PROPERTY_IS_NOT_SET ));
432
- throw new OcrException ( OcrException .CANNOT_CREATE_PDF_DOCUMENT )
433
+ throw new PdfOcrException ( PdfOcrExceptionMessageConstant .CANNOT_CREATE_PDF_DOCUMENT )
433
434
.setMessageParams (PdfOcrLogMessageConstant .PDF_LANGUAGE_PROPERTY_IS_NOT_SET );
434
435
}
435
436
@@ -472,13 +473,13 @@ private PdfDocument createPdfDocument(final PdfWriter pdfWriter,
472
473
* map pageNumber -> text for the page
473
474
* @param pdfDocument result {@link com.itextpdf.kernel.pdf.PdfDocument}
474
475
* @param createPdfA3u true if PDF/A3u document is being created
475
- * @throws OcrException if input image cannot be read or provided font
476
+ * @throws PdfOcrException if input image cannot be read or provided font
476
477
* contains NOTDEF glyphs
477
478
*/
478
479
private void addDataToPdfDocument (
479
480
final Map <File , Map <Integer , List <TextInfo >>> imagesTextData ,
480
481
final PdfDocument pdfDocument ,
481
- final boolean createPdfA3u ) throws OcrException {
482
+ final boolean createPdfA3u ) throws PdfOcrException {
482
483
for (Map .Entry <File , Map <Integer , List <TextInfo >>> entry
483
484
: imagesTextData .entrySet ()) {
484
485
File inputImage = entry .getKey ();
@@ -545,7 +546,7 @@ private void addImageToCanvas(final ImageData imageData,
545
546
* @param pdfCanvas canvas to place the text
546
547
* @param multiplier coefficient to adjust text placing on canvas
547
548
* @param pageMediaBox page parameters
548
- * @throws OcrException if PDF/A3u document is being created and provided
549
+ * @throws PdfOcrException if PDF/A3u document is being created and provided
549
550
* font contains notdef glyphs
550
551
*/
551
552
private void addTextToCanvas (
@@ -554,7 +555,7 @@ private void addTextToCanvas(
554
555
final PdfCanvas pdfCanvas ,
555
556
final float multiplier ,
556
557
final Rectangle pageMediaBox )
557
- throws OcrException {
558
+ throws PdfOcrException {
558
559
if (pageText != null && pageText .size () > 0 ) {
559
560
final Point imageCoordinates =
560
561
PdfCreatorUtil .calculateImageCoordinates (
@@ -750,7 +751,7 @@ public PdfCanvas showText(GlyphLine text) {
750
751
if (this .createPdfA3u ) {
751
752
// exception is thrown only if PDF/A document is
752
753
// being created
753
- throw new OcrException (message );
754
+ throw new PdfOcrException (message );
754
755
}
755
756
// setting actual text to NotDef glyph
756
757
glyphLine .setActualTextToGlyph (i ,
0 commit comments