This Web Service API is used to create HOCR XML forsingle page/multipage tiff/tif or zip containg tiff or pdf passed as input for a particular batch class. This Web Service API requires two Inputs i.e. Input xml and image file to create HOCR_xml.

On the basis of Batch Class Identifier provided as an input, this API will Extract plugin configuration settings of RECOSTAR_HOCR/TESSERACT_HOCR/NUANCE_HOCR plugin in Page Process module, if property named “Recostar Switch” value is turned ON then process of OCRing will be done for Recostar and its corresponding plugin configurations will be used else Tesseract will be used to perform OCRingin case of windows.Similarly OCRing can be performed on Linux using either Tesseract or Nunace.

Request Method POST

Input parameters required for the batch class creation are as follows:

Input Parameter Value Description
batchClassIdentifier It should contain a valid value of an existing batch Class Identifier. The Batch Class name whose configurations are to be utilised to generate HOCR.xml.
imageName Optional parameter This parameter value contain name tif/tiff or ZIP file for which HOCR XML need to be created with extension specified.

 

Web Service URL: [http://{serverName}:{port}/dcma/rest/batchClass/createHOCRforBatchClass]

Check list:

  1. Batch Class Identifier should be valid and existing.
  2. Only single page tif/tiff should be passed as an input or a zip file (which may contain single/multipage tiff or pdf).

Sample Input XML:

<WebServiceParams>

<Params>

<Param>

<Name>batchClassIdentifier</Name>

<Value>BC5</Value>

</Param>

<Param>

<Name>imageName</Name>

<Value>US-Invoice.zip</Value>

</Param>

</Params>

</WebServiceParams>

 

Sample client code using apache commons http client:-

private static void createHOCRXML() {
		HttpClient client = new HttpClient();
		String url = "http://localhost:8080/dcma/rest/batchClass/createHOCRforBatchClass";
		PostMethod mPost = new PostMethod(url);
		// Adding Input XML file for processing
		File file = new File("C:\\sample\\createHOCR.xml");
		File imageFile = new File("C:\\sample\\US-Invoice.tif");
		Part[] parts = new Part[2];
		try {
			parts[0] = new FilePart(file.getName(), file);
			parts[1] = new FilePart(imageFile.getName(), imageFile);
			MultipartRequestEntity entity = new MultipartRequestEntity(parts, mPost.getParams());
			mPost.setRequestEntity(entity);
			int statusCode = client.executeMethod(mPost);
			if (statusCode == 200) {
				InputStream in = mPost.getResponseBodyAsStream();
				// saving result generated.
				File outputFile = new File("F:\\sample\\serverOutput.zip");
				FileOutputStream fos = new FileOutputStream(outputFile);
				try {
					byte[] buf = new byte[1024];
					int len = in.read(buf);
					while (len > 0) {
						fos.write(buf, 0, len);
						len = in.read(buf);
					}
				} finally {
					if (fos != null) {
						fos.close();
					}
				}
				System.out.println("Web service executed successfully.");
			} else if (statusCode == 403) {
				System.out.println("Invalid username/password.");
			} else {
				System.out.println(mPost.getResponseBodyAsString());
			}
		} catch (FileNotFoundException e) {
			System.err.println("File not found for processing.");
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (mPost != null) {
				mPost.releaseConnection();
			}
		}
	}

Was this article helpful to you?

Engineering

Comments are closed.