You are here

You are here

Download Document - PNG Images

One of the most useful aspects of using SpringCM via the UI is that it allows users to view documents without having to download the entire document.

SpringCM does this by generating an image for each page of the document and then lets the user page through them.  The preview images are available for download via the API which enables external applications to build their own custom document viewers.  This is exposed via the DocumentDownloadPreviewImage method call.

Inputs

  • token – Authentication token used in all SOAP calls
  • documentId – The ID of the document who’s preview images are to be retrieved.
  • start –The index of the image stream to start downloading, used in conjunction with the length parameter, images can be “chunked” out of the API
  • length – length of bytes of the image to get.  A negative value will attempt to send back the full size.  So a start of 0 and length of -1 will try to send back the whole image without chunking.  This ok for a single page, but chunking should be used for larger file downloads.
  • pageNumber – the page number of the document from which to retrieve a page image.  The SCMDocument object will contain the total page count, so this can be used to create paging controls for the user.
  • imageZoom – This is the SCMPreviewImageZoom enumeration that states the zoom level of the image returned.

Outputs

This method returns a byte array that is an image of the page number at the zoom level for the document requested.

Not every document in SpringCM has a preview image created for it.  For example, jpg files will not have a preview image associated with them, as the jpg itself can just be viewed.  Documents without a preview will have a PageCount of zero on its SCMDocument object.

Vertical Tabs

c#
string documentId = "<Document Id retrieved by other method calls>";
int pageNumber = <Page number to retrieve>;
string localPagePath = "<Local file system path and file name for downloaded file.  Should have .png extension.>";
 
//Setting -1 for the page number will download the entire page
//Since there is only one page at a time, chunking is generally not needed
//SpringCM may create the image on the fly, so a retry needs to be built in
//as the image generation can take a short bit of time.
 
int retries = 10;
while (retries > 0)
{
	try
	{
		byte[] pageImage = springCMService.DocumentDownloadPreviewImage(token, documentId, 0, -1, pageNumber,SCMPreviewImageZoom.Percent100);
		File.WriteAllBytes(localPagePath, pageImage);
		retries = 0;
	}
	catch (Exception ex)
	{
		Console.WriteLine("Image could not be retrieved, retrying: " + ex.Message);
		Thread.Sleep(5000);
	}
 
	retries--;
}
java
String documentId = "<Document Id retrieved by other method calls>";
int pageNumber = <Page number to retrieve>;
String localPagePath = "<Local file system path and file name for downloaded file.  Should have .png extension.>";
 
//Setting -1 for the page number will download the entire page
//Since there is only one page at a time, chunking is generally not needed
//SpringCM may create the image on the fly, so a retry needs to be built in
//as the image generation can take a short bit of time.
 
int retries = 10;
while (retries > 0)
{
	try
	{
		byte[] pageImage = springCMService.documentDownloadPreviewImage(token, documentId, 0, -1, pageNumber,SCMPreviewImageZoom.Percent100);
 
		FileOutputStream stream = new FileOutputStream(localPagePath);
		try 
		{
			stream.write(pageImage);
		} 
		finally 
		{
			stream.close();
		}
 
		retries = 0;
	}
	catch (Exception ex)
	{
		System.out.println("Image could not be retrieved, retrying: " + ex.getMessage());
		Thread.sleep(5000);
	}
 
	retries--;
}