This API will break the pdf and multipage tiff file into single page tiff.  The API uses image magick and ghost script for splitting the input file. This API will have following parameter for configuration.

Request Method POST

Input Parameters

Input Parameter Values Descriptions
inputParams For Image Magick:

This value can be empty.  Reference for image magick parameter. http://www.imagemagick.org/script/command-line-options.php

For Ghost Script:

This value should not be empty. Reference for ghost script input parameter :

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

This parameter is used for both image magick and ghost script.
outputParams For Image Magick:

This value can be empty.  Reference for image magick parameter. http://www.imagemagick.org/script/command-line-options.php

This are the image magick output parameters used for optimizing the output file.
isGhostscript Either “true”/”false” This parameter is used to specified the weather ghost script is using for breaking the pdf/multipage tiff into single page tiff.

 

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

Checklist:

  1. Input only tiff and pdf file only.
  2. If “isGhostscript” is “true”, then only input params will work and PDF files will be split.
  • If “isGhostscript” is “false”, then input params and output params will work.

Notes:

– If the input is multipage TIFF, use Image-Magick for conversion, with below parameters

     parts[1] = new StringPart(“inputParams”, ” -limit memory 100mb”);

     parts[2] = new StringPart(“isGhostscript”, “false”);

     parts[3] = new StringPart(“outputParams”, “-compress LZW”);

– If the input is multipage PDF, use Ghost-script for conversion, with below parameters

     parts[1] = new StringPart(“inputParams”, “-dNOPAUSE -r300 -sDEVICE=tiff12nc -dBATCH”);

     parts[2] = new StringPart(“isGhostscript”, “true”);

     parts[3] = new StringPart(“outputParams”, “”);

 

Sample client code using apache commons http client:-

private static void splitMultiPageFile() {
		HttpClient client = new HttpClient();
		String url = "http://localhost:8080/dcma/rest/splitMultipageFile";
		PostMethod mPost = new PostMethod(url);

		File file1 = new File("C:\\sample\\sample.tif");

		Part[] parts = new Part[4];
		try {
			parts[0] = new FilePart(file1.getName(), file1);
			parts[1] = new StringPart("inputParams", "-dNOPAUSE -r300 -sDEVICE=tiff12nc -dBATCH");
			parts[2] = new StringPart("isGhostscript", "true");
			parts[3] = new StringPart("outputParams", "");

			MultipartRequestEntity entity = new MultipartRequestEntity(parts, mPost.getParams());
			mPost.setRequestEntity(entity);

			int statusCode = client.executeMethod(mPost);
			if (statusCode == 200) {
				InputStream in = mPost.getResponseBodyAsStream();
				File file = new File("C:\\sample\\serverOutput.zip");
				FileOutputStream fos = new FileOutputStream(file);
				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.