Summary: Ctors | Methods | Inherited Methods | [Expand All]
public class

# OCROptions

extends OptionsBase

java.lang.Object
↳ | com.pdftron.pdf.OptionsBase
| ↳ | com.pdftron.pdf.OCROptions

## Summary

Public Constructors
| OCROptions() Constructor.
| OCROptions(String json_string) Constructor.

Public Methods
OCROptions | addDPI(int dpi) Sets the value for DPI in the options object.
OCROptions | addIgnoreZonesForPage(RectCollection regions, int page_num) Adds a zones to the IgnoreZones array.
OCROptions | addLang(String lang) Adds a language to the Langs array.
OCROptions | addTextZonesForPage(RectCollection regions, int page_num) Adds a zones to the TextZones array.
boolean | getAutoRotate() Gets the value AutoRotate from the options object.
int | getDPI() Gets the value DPI from the options object.
boolean | getIgnoreExistingText() Gets the value IgnoreExistingText from the options object.
boolean | getIncludeExistingText() Gets the value IncludeExistingText from the options object.
String | getOCREngine() Gets the value OCREngine from the options object.
boolean | getUsePDFPageCoords() Gets the value UsePDFPageCoords from the options object.
OCROptions | setAutoRotate(boolean value) Sets the value for AutoRotate in the options object.
OCROptions | setIgnoreExistingText(boolean value) Sets the value for IgnoreExistingText in the options object.
OCROptions | setIncludeExistingText(boolean value) Sets the value for IncludeExistingText in the options object.
OCROptions | setOCREngine(String value) Sets the value for OCREngine in the options object.
OCROptions | setUsePDFPageCoords(boolean value) Sets the value for UsePDFPageCoords in the options object.

[Expand] Inherited Methods
From class java.lang.Object
boolean | equals(Object arg0)
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()

## Public Constructors

#### public OCROptions ()

Constructor.

##### Throws

PDFNetException |

#### public OCROptions (String json_string)

Constructor.

##### Throws

PDFNetException |

## Public Methods

#### public OCROptions addDPI (int dpi)

Sets the value for DPI in the options object.

Knowing proper image resolution is important, as it enables the OCR engine to translate pixel heights of characters to their respective font sizes.

We do our best to retrieve resolution information from the input's metadata, however it occasionally can be corrupt or missing. Hence we allow manual override of source's resolution, which supersedes any metadata found (both explicit as in image metadata and implicit as in PDF).

If input is a PDF file, the SDK will render PDF page for OCR as a raster image with 300 DPI resolution. Otherwise, if input is an image, SDK will pass to OCR raster image in original resolution. Exceptionally, if the user, by using this method, suggests the resolution (say 300 DPI), the SDK will try do as suggested.

Here, some restrictions apply:

- New image size in pixels (Width X Height) cannot exceed 75 MP (Mega Pixels)
- Each image side (Width or Height), in pixels, cannot exceed 16 bits (65,535)

To achieve that, SDK will iteratively scale down the DPI till both conditions are met.

##### Parameters

dpi | The new value for DPI.

##### Returns

- This object, for call chaining.

##### Throws

PDFNetException |

#### public OCROptions addIgnoreZonesForPage (RectCollection regions, int page_num)

Adds a zones to the IgnoreZones array.

It is an optional list of areas that will be excluded from analysis.

The meaning and handling of the passed region coordinates will vary depending on:

- Whether input is PDF (rather than an image), and
- Whether setUsePDFPageCoords() is called with value true.

If either of above is true, then the region coordinates have to be given in PDF Points and coodinate space origin at bottom-left.

Otherwise:

- The input is a raster image,
- The coordinates has to be given in pixel units and with coordinate space origin at top-left

See also: processPDF() imageToPDF() setUsePDFPageCoords() addTextZonesForPage().

##### Parameters

regions | The new zones to add to IgnoreZonesForPage.
page_num | The page number the added regions belong to.

##### Returns

- This object, for call chaining.

##### Throws

PDFNetException |

#### public OCROptions addLang (String lang)

Adds a language to the Langs array.

OCR engine is prepared for recognition of a predefined set of language scripts. Various scripts have differences in glyphs and it is recommended that OCR engine is instructed to use a correct glyph set to match the appropriate Unicode. At this moment, there are two avaliable engines for use. Let we refer them by their executable names: OCRModule and OCRModuleIRIS.

Here is a list of supported languages by their codes that may be passed as a parameter. One language per call to addLang(). Use multiple calls to addLang() to add additional languages.

Warning: Be aware that adding too many language codes at once may lead to wrong altertnatives regarding Latin characters with accents.

Language | Code | Language | Code
--- | --- | --- | ---
English | eng | Chinese Simpl. | chi_sim
French | fra | Chinese Trad. | chi_tra
German | deu | Japanese | jpn
Italian | ita | Korean | kor
Russian | rus |  |
Spanish | spa |  |

Here are the languages supported out of the box per engine:

Executable Name | Supported Codes
--- | ---
OCRModule | eng fra deu ita spa rus
OCRModuleIRIS | eng fra deu ita spa rus chi_sim chi_tra jpn kor

Note: OCRModuleIRIS allows mix of a single Asian language and just English.

##### Parameters

lang | The new language to add to Langs.

##### Returns

- This object, for call chaining.

##### Throws

PDFNetException |

#### public OCROptions addTextZonesForPage (RectCollection regions, int page_num)

Adds a zones to the TextZones array.

It is as an optional list of known text zones that will be used to improve OCR quality.

See also: AddIgnoreZonesForPage().

##### Parameters

regions | The new zones to add to TextZonesForPage.
page_num | The page number the added regions belong to.

##### Returns

- This object, for call chaining.

##### Throws

PDFNetException |

#### public boolean getAutoRotate ()

Gets the value AutoRotate from the options object.

Default value is false. Setting to true will deskew the image before conducting OCR.

Note: This function doesn't apply to IRIS OCR module.

##### Returns

- The current value for AutoRotate.

##### Throws

PDFNetException |

#### public int getDPI ()

Gets the value DPI from the options object.

Knowing proper image resolution is important, as it enables the OCR engine to translate pixel heights of characters to their respective font sizes.

We do our best to retrieve resolution information from the input's metadata, however it occasionally can be corrupt or missing. Hence we allow manual override of source's resolution, which supersedes any metadata found (both explicit as in image metadata and implicit as in PDF).

If input is a PDF file, the SDK will render PDF page for OCR as a raster image with 300 DPI resolution. Otherwise, if input is an image, SDK will pass to OCR raster image in original resolution. Exceptionally, if the user, by using this method, suggests the resolution (say 300 DPI), the SDK will try do as suggested.

Here, some restrictions apply:

- New image size in pixels (Width X Height) cannot exceed 75 MP (Mega Pixels)
- Each image side (Width or Height), in pixels, cannot exceed 16 bits (65,535)

To achieve that, SDK will iteratively scale down the DPI till both conditions are met.

##### Returns

- The current value for DPI.

##### Throws

PDFNetException |

#### public boolean getIgnoreExistingText ()

Gets the value IgnoreExistingText from the options object.

Default value is false, so that areas with existing text will be automatically skipped during OCR. Setting to true will cause a pre-existing text to be duplicated with the OCR-ed ones in the PDF document or in GetOCRJsonFromPDF() and getOCRXmlFromPDF() results.

Deprecated! Use getIncludeExistingText() instead.

##### Returns

- The current value for IgnoreExistingText.

##### Throws

PDFNetException |

#### public boolean getIncludeExistingText ()

Gets the value IncludeExistingText from the options object.

Default value is false, so that areas with existing text will be automatically skipped during OCR. Setting to true will cause a pre-existing text to be duplicated with the OCR-ed ones in the PDF document or in GetOCRJsonFromPDF() and getOCRXmlFromPDF() results.

##### Returns

- The current value for IncludeExistingText.

##### Throws

PDFNetException |

#### public String getOCREngine ()

Gets the value OCREngine from the options object.

Options include 'default' or 'iris'. Chosen module must be present and correctly licensed.

##### Returns

- The current value for OCREngine.

##### Throws

PDFNetException |

#### public boolean getUsePDFPageCoords ()

Gets the value UsePDFPageCoords from the options object.

Defines the coordinate system, scaling and units. SDK and OCRModule will refer to this setting while dealing with potential input zone rectangle(s) (ignorable or text) and with the output result as well. The default value is false which corresponds to raster image input.

Here are the meanings for value:

Value | Origin | +Y axis dir. | Unit | Size | Expected input
--- | --- | --- | --- | --- | ---
false | top-left | Downwards | Pixel | 1/DPI inches | Image
true | bottom-left | Upwards | Point | 1/72 inches | PDF

Note that, OCRModule backend has no notion about the SDK's real input. So, if not explicitelly instructed via this call and value, it will work by default and will report the coordinates as for false. This is important to know for cases when the call for OCR service comes from getOCRJsonFromPDF() or getOCRXmlFromPDF() where the results should be correct in JSON or XML format - and removes the need for user to do additional adjustments.

See also: addIgnoreZonesForPage() addTextZonesForPage() addDPI() getOCRJsonFromImage() getOCRXmlFromImage().

##### Returns

- The current value for UsePDFPageCoords.

##### Throws

PDFNetException |

#### public OCROptions setAutoRotate (boolean value)

Sets the value for AutoRotate in the options object.

Default value is false. Setting to true will deskew the image before conducting OCR.

Note: This function doesn't apply to IRIS OCR module.

##### Parameters

value | The new value for AutoRotate.

##### Returns

- This object, for call chaining.

##### Throws

PDFNetException |

#### public OCROptions setIgnoreExistingText (boolean value)

Sets the value for IgnoreExistingText in the options object.

Default value is false, so that areas with existing text will be automatically skipped during OCR. Setting to true will cause a pre-existing text to be duplicated with the OCR-ed ones in the PDF document or in getOCRJsonFromPDF() and getOCRXmlFromPDF() results.

Deprecated! Use setIncludeExistingText() instead.

##### Parameters

value | The new value for IgnoreExistingText.

##### Returns

- This object, for call chaining.

##### Throws

PDFNetException |

#### public OCROptions setIncludeExistingText (boolean value)

Sets the value for IncludeExistingText in the options object.

Default value is false, so that areas with existing text will be automatically skipped during OCR. Setting to true will cause a pre-existing text to be duplicated with the OCR-ed ones in the PDF document or in getOCRJsonFromPDF() and getOCRXmlFromPDF() results.

##### Parameters

value | The new value for IncludeExistingText.

##### Returns

- This object, for call chaining.

##### Throws

PDFNetException |

#### public OCROptions setOCREngine (String value)

Sets the value for OCREngine in the options object.

Options include 'default' or 'iris'. Chosen module must be present and correctly licensed.

##### Parameters

value | The new value for OCREngine.

##### Returns

- This object, for call chaining.

##### Throws

PDFNetException |

#### public OCROptions setUsePDFPageCoords (boolean value)

Sets the value for UsePDFPageCoords in the options object.

Defines the coordinate system, scaling and units. SDK and OCRModule will refer to this setting while dealing with potential input zone rectangle(s) (ignorable or text) and with the output result as well. The default value is false which corresponds to raster image input.

Here are the meanings for value:

Value | Origin | +Y axis dir. | Unit | Size | Expected input
--- | --- | --- | --- | --- | ---
false | top-left | Downwards | Pixel | 1/DPI inches | Image
true | bottom-left | Upwards | Point | 1/72 inches | PDF

Note that, OCRModule backend has no notion about the SDK's real input. So, if not explicitelly instructed via this call and value, it will work by default and will report the coordinates as for false. This is important to know for cases when the call for OCR service comes from getOCRJsonFromPDF() or getOCRXmlFromPDF() where the results should be correct in JSON or XML format - and removes the need for user to do additional adjustments.

See also: addIgnoreZonesForPage() addTextZonesForPage() addDPI() getOCRJsonFromImage() getOCRXmlFromImage().

##### Parameters

value | The new value for UsePDFPageCoords.

##### Returns

- This object, for call chaining.

##### Throws

PDFNetException |