This API will create the multipage tif/pdf using “Image MagicK” or “IText” or “GhostScript”. This API works only for tif/tiff files. This API will have following parameters for configuration.

Request Method POST

Input Parameters

     Input Parameter Values Descriptions
imageProcessingAPI Either “IMAGE_MAGICK” /”GHOSTSCRIPT”/”ITEXT” This parameter is used for generating pdf using image_magick, itext and ghost script.
pdfOptimizationParams This value should not be empty. Reference for ghost script input parameter :

http://ghostscript.com/doc/8.54/Use.htm#Output_device

These are the ghost script output parameters used for optimizing the output file.
multipageTifSwitch Either “ON”/”OFF” This parameter is used for generating multipage tif along with multipage pdf.
pdfOptimizationSwitch Either “ON”/”OFF” This switch is used for generating optimized pdf.
ghostscriptPdfParameters This value should not be empty. Reference for ghost script input parameter :

http://ghostscript.com/doc/8.54/Use.htm#Output_device

This are the ghost script parameter used for creating multipage pdf.

 

Web Service URL: http://{serverName}:{port}/dcma/rest/createMultiPageFile

 

Checklist:

  1. Input only tiff file for processing and xml file for inputs.
  2. If “imageProcessingAPI” is “GHOSTSCRIPT”, than only ghostscriptPdfParameters will work.
  • If “pdfOptimizationSwitch” is “ON”, than pdfOptimizationParams will work.

 

 

Format for XML:

<WebServiceParams>
<Params>
<Param>
<Name>imageProcessingAPI</Name>
<Value>GHOSTSCRIPT</Value>
</Param>
<Param>
<Name>pdfOptimizationSwitch</Name>
<Value>on</Value>
</Param>
<Param>
<Name>pdfOptimizationParams</Name>
<Value>-q -dNODISPLAY -P- -dSAFER -dDELAYSAFER -- pdfopt.ps</Value>
</Param>
<Param>
<Name>multipageTifSwitch</Name>
<Value>on</Value>
</Param>
<Param>
<Name>ghostscriptPdfParameters</Name>
<Value>-dQUIET -dNOPAUSE -r300 -sDEVICE=pdfwrite -dBATCH</Value>
</Param>
</Params>
</WebServiceParams> 

Sample client code using apache commons http client:-

private static void createMultiPage() {
		HttpClient client = new HttpClient();
		String url = "http://localhost:8080/dcma/rest/createMultiPageFile";
		PostMethod mPost = new PostMethod(url);
		// Adding XML file for parameters
		File file1 = new File("C:\\sample\\input.xml");
		// Adding tif file for processing
		File file2 = new File("C:\\sample\\Application.tif");
		File file3 = new File("C:\\sample\\US-Invoice.tif");
		Part[] parts = new Part[3];
		try {
			parts[0] = new FilePart(file1.getName(), file1);
			parts[1] = new FilePart(file2.getName(), file2);
			parts[2] = new FilePart(file3.getName(), file3);
			MultipartRequestEntity entity = new MultipartRequestEntity(parts, mPost.getParams());
			mPost.setRequestEntity(entity);
			int statusCode = client.executeMethod(mPost);
			if (statusCode == 200) {
				InputStream inputStream = mPost.getResponseBodyAsStream();
				// Retrieving file from result
				File file = new File("C:\\sample\\serverOutput.zip");
				FileOutputStream fos = new FileOutputStream(file);
				try {
					byte[] buf = new byte[1024];
					int len = inputStream.read(buf);
					while (len > 0) {
						fos.write(buf, 0, len);
						len = inputStream.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(statusCode + " *** " + 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.