|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.PDFObject
org.faceless.pdf2.PDFStream
org.faceless.pdf2.PDFImage
The PDFImage class encapsulates a bitmap image, like a JPEG or PNG file, which can be inserted directly into the PDF document.
ExamplePDFPage page = pdf.newPage(PAGESIZE_A4); PDFImage img = new PDFImage(new FileInputStream("mypicture.jpg")); page.drawImage(img, 100, 100, i.getWidth(), i.getHeight());
Images embedded into the document can be stretched to any size, but it's important to remember that there is a loss in quality as they're stretched. A thumbnail-size image scaled to full page will look bad on a 72dpi screen, and worse on a 600dpi printer.
Transparency as supported by the GIF, PNG, TIFF and JPEG2000 file formats can be used - since version 2.0 this includes the alpha transparency available in the PNG file format (and alpha information in TIFF image since version 2.1.1). Note that this feature is only supported in Acrobat 5 or later, and even the "mask" transparency used in GIF and 8-bit PNG images requires PostScript level 3 support in order to print correctly. For this reason, we can't guarantee correct results when viewing documents with translucent images in Acrobat 4 or earlier. As best as we can tell, the worst that will happen is the transparency information will be ignored..
Any ICC Color profiles embedded in PNG, TIFF, JPEG and JPEG2000 images will be automatically embedded in the resulting PDF.
Constructor Summary | |
PDFImage(byte[] in)
Load a PDFimage from a byte array. |
|
PDFImage(Image img)
Create a new PDFimage from the specified java.awt.Image .
|
|
PDFImage(InputStream in)
Load a PDFimage from an InputStream. |
|
PDFImage(int w,
int h,
int bpc,
double dpix,
double dpiy,
boolean photo,
boolean alpha,
ColorSpace space,
InputStream[] planes)
Create a PDFImage from the raw bitmap data provided. |
Method Summary | |
void |
close()
Compress the image and close it, preventing any further changes. |
double |
getDPIX()
Return the dots-per-inch of the image in the X direction (horizontally). |
double |
getDPIY()
Return the dots-per-inch of the image in the Y direction (vertically) Not every image contains this information (for example, it's not part of the GIF specification), in which case this method returns the default resolution of 72, which means 1 pixel = 1 point. |
float |
getHeight()
Return the height in points of the image. |
Reader |
getMetaData()
Return any XML metadata associated with this object. |
float |
getWidth()
Return the width in points of the image. |
void |
setMetaData(String xmldata)
Set the XML metadata associated with this object. |
String |
toString()
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public PDFImage(Image img) throws InterruptedException, IllegalArgumentException
java.awt.Image
.
The image must be fully loaded, ie. the width and height are known,
otherwise an IllegalArgumentException
is thrown.
img
- the image to load
InterruptedException
- if the library is unable to read the pixels from
the image before being interrupted
IllegalArgumentException
- if the image is invalid - ie. the width or height
is zero or not defined, or if the image is not an embeddable image typepublic PDFImage(InputStream in) throws IOException, IllegalArgumentException
PNG | All except for 16 bit PNG |
---|---|
JPEG | Progressive JPEG images can only be viewed in Acrobat 4 or later. Additionally, CMYK JPEG images created with Adobe tools like Photoshop may print incorrectly unless you're running Java 1.4 or later. |
GIF | If the GIF is animated, only the first frame is embedded |
TIFF | Since 2.1.1 we can handle CCITT, Flate, LZW, CMYK, alpha transparency,
most YCbCr and (if you're running Java 1.4 or later) new-style JPEG images, but old-style
JPEG, JBIG, SGI, 16-bit and Lab images remain unsupported. For multi-page TIFF support see the
PDFImageSet class. |
PBM, PGM | Only standard 8-bit PBM and PGM images are supported. Support was added in version 2.0.6 |
JPEG 2000 | These can only be displayed in Acrobat 6 or later. Support added in version 2.1.1 |
in
- the InputStream
to read the image from
IOException
- if the method is unable to read or parse the image
IllegalArgumentException
- if the image is invalid or can't be embedded.public PDFImage(byte[] in) throws IOException, IllegalArgumentException
PDFImage(InputStream)
constructor, but takes a byte array
containing the image as a parameter instead
public PDFImage(int w, int h, int bpc, double dpix, double dpiy, boolean photo, boolean alpha, ColorSpace space, InputStream[] planes) throws IOException
Create a PDFImage from the raw bitmap data provided. The vast majority of
users will be better off either parsing an encoded image format or calling
the PDFImage(Image)
constructor, but for special cases it's possible
to use this constructor to pass the raw bitmap data in for each plane.
w
- the width of the image in pixelsh
- the height of the image in pixelsbpc
- the number of bits for each component of the image. Must be 1, 2, 4, 8 or 16 - although 16 is only supported by Acrobat 6 or later.dpix
- the horizontal dots-per-inch of the imagedpiy
- the vertical dots-per-inch of the imagephoto
- for 8 bit images, whether to use JPEG compression instead of the normal Flate compression. For non 8-bit images this has no effectalpha
- whether or not an alpha plane is being passed in as the last planespace
- The ColorSpace this image is in. The number of components in the colorspace must match the number of planes passed in.planes
- The planes of the image. Each InputStream represents a single plane (for example, a CMYK image would have four planes passed in, the first representing Cyan, the second Magenta and so on). Each InputStream must contain w*h*bpc
bits of image data in the form of a number of horizontal scanlines starting at the top of the image. Each scanline must start on a byte boundary. Note the InputStreams are not closed by this constructor.
IOException
- if one of the InputStreams throws an IOException while being read, or if one of
them returns a -1 from it's read()
method.Method Detail |
public float getWidth()
Return the width in points of the image. This may be different to the width in pixels, depending on whether the image contains information about it's resolution.
getDPIX()
public float getHeight()
Return the height in points of the image. This may be different to the height in pixels, depending on whether the image contains information about it's resolution.
getDPIY()
public double getDPIX()
public double getDPIY()
public void setMetaData(String xmldata)
PDF.setMetaData
for more information.
xmldata
- the XML data to embed into the document, or null
to clear any existing metadata. No validation is performed on this input.public Reader getMetaData() throws IOException
Return any XML metadata associated with this object. See the
PDF.getMetaData()
for more information.
Note that JPEG2000 images may have more than one MetaData stream embedded in
them. If this is the case, in order to present only a single root node to the
XML Parser, the XML objects are all wrapped in a single <JPEG2000>
node
Reader
containing the source of the XML or
null if no metadata is available.
IOException
- if the metadata can't be extractedpublic void close()
Cache
public String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |