KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > faceless > pdf > PDFImageSet


1 // $Id: PDFImageSet.java,v 1.5 2003/11/04 17:16:01 mike Exp $
2

3 package org.faceless.pdf;
4
5 import java.io.*;
6
7 /**
8  * <p>
9  * The <code>PDFImageSet</code> class is a thin wrapper around a multi-page
10  * image format (currently only TIFF images). Although it can be used with
11  * single page images, it's simpler just to create a {@link PDFImage} directly.
12  * </p>
13  *
14  * <b>Example</b>
15  * <pre>
16  * PDFImageSet tiff = new PDFImageSet(new FileInputStream("multipage.tif"));
17  * PDFImage page1 = tiff.getImage(1);
18  * PDFImage page2 = tiff.getImage(2);
19  * </pre>
20  *
21  * @version $Revision: 1.5 $
22  * @since 1.1.13
23  * @see PDFImage
24  */

25 public class PDFImageSet
26 {
27     private final org.faceless.pdf2.PDFImageSet set;
28     
29     /**
30      * Create a new <code>PDFImageSet</code> from the specified InputStream.
31      * The stream must contain a recognized Image format - see the {@link PDFImage}
32      * class for a list of formats and restrictions
33      * @throws IOException if the image cannot be loaded or the format cannot be parsed
34      * @throws IllegalArgumentException if the image cannot be parsed
35      */

36     public PDFImageSet(InputStream in)
37         throws IOException, IllegalArgumentException JavaDoc
38     {
39     set = new org.faceless.pdf2.PDFImageSet(in);
40     }
41
42     /**
43      * Return the number of sub images, or "pages" in this image set.
44      * For all formats but TIFF this will return 1.
45      * @return the number of pages in this image
46      */

47     public int getNumImages()
48     {
49     return set.getNumImages();
50     }
51
52     /**
53      * Return the specified sub-image from this image as a {@link PDFImage}.
54      * If the requested page is out of range this method throws an
55      * <code>ArrayIndexOutOfBoundsException</code>. If the specified subimage
56      * is corrupt or cannot be parsed, throws an <code>IOException</code>
57      *
58      * @param page the page number, from 0 to {@link #getNumImages}
59      * @throws IOException if the TIFF file is corrupt or the image cannot be used
60      * @throws ArrayIndexOutOfBoundsException
61      */

62     public PDFImage getImage(int page)
63         throws IOException
64     {
65     return (PDFImage)PeeredObject.getPeer(set.getImage(page));
66     }
67 }
68
Popular Tags