Tips For Success

Having the best tools for document imaging is only half of the equation. Our Tech Tips are designed to provide you with valuable information to help you succeed by achieving faster results with our RasterMaster Imaging and Conversion SDKs or VirtualViewer high-speed document and image viewers. New time-saving tips are added monthly - you can receive them through Imaging News or our Tech Tips RSS feed.

Printing a Multi-page File

Snowbound Software’s RasterMasterTM for the JavaTM Platform includes the ability to print multi-page file formats such as TIFF files. You can use the code sample below to print a multi-page file. The key step to include is to create the PrintJob outside of the loop and call PrintJob.end() after the loop.

/**
 * Copyright (C) 2002-2007 by Snowbound Software Corp.
 * All rights reserved.
 */

package com.snowbound.test;

 

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.JobAttributes;
import java.awt.PrintJob;
import java.awt.Toolkit;
import Snow.Snowbnd;

 

public class PrintSample

{

public static void printDocument(String fileName, Frame parentFrame)

{

Snowbnd snow = new Snowbnd();

JobAttributes job = new JobAttributes();

PrintJob pjob = Toolkit.getDefaultToolkit().getPrintJob(parentFrame,

"Snowbound",

job,

null);

int pageCount = snow.IMGLOW_get_pages(fileName);

for (int pageIndex = 0; pageIndex < pageCount; pageIndex++)

{

snow.IMG_decompress_bitmap(fileName, pageIndex);

printImage(snow, 300, pjob);

}

pjob.end();

}

 

public static void printImage(Snowbnd simage, int dpi, PrintJob pjob)

{

int width, height, x, y;

int imageHeight, imageWidth;

PrintJob printJob;

Graphics printGraphics;

if (pjob != null && simage != null)

{

printGraphics = pjob.getGraphics();

if (printGraphics != null)

{

Dimension pd = pjob.getPageDimension();

if (simage.dis_rotate == 90 || simage.dis_rotate == 270)

{

imageWidth = simage.getHeight();

imageHeight = simage.getWidth();

}

else

{

imageWidth = simage.getWidth();

imageHeight = simage.getHeight();

}

System.out.println("imageWidth: " + imageWidth);

width = (pd.width / 72) * dpi;

height = (imageHeight * width) / imageWidth;

if (height > ((pd.height / 72) * dpi))

{

x = (((pd.width / 72) * dpi) - width) / 2;

y = 0;

}

else

{

x = 0;

y = (((pd.height / 72) * dpi) - height) / 2;

}

simage

.IMG_print_bitmap(printGraphics, x, y, width, height, dpi);

printGraphics.dispose();

}

}

return;

}

public static void main (String args[])

{

printDocument("c:/imgs/6-pages.tif", new Frame());

}

}