/*
* $Id$
*
* This code is part of the 'iText Tutorial'.
* You can find the complete tutorial at the following address:
* http://itextdocs.lowagie.com/tutorial/
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* itext-questions@lists.sourceforge.net
*/
package com.lowagie.examples.objects.images;
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Chunk;
import com.lowagie.text.LwgDocument;
import com.lowagie.text.DocumentException;
import com.lowagie.text.LwgElement;
import com.lowagie.text.LwgImage;
import com.lowagie.text.LwgPhrase;
import com.lowagie.text.pdf.LwgPdfPCell;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfWriter;
/**
* Wrapping Images in a Chunk.
*/
public class ImageChunks {
/**
* Images wrapped in a Chunk.
* @param args no arguments needed
*/
public static void main(String[] args) {
LwgDocument.compress = false;
System.out.println("images wrapped in a Chunk");
// step 1: creation of a document-object
LwgDocument document = new LwgDocument();
try {
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.getInstance(document, new FileOutputStream("imageChunks.pdf"));
// step 3: we open the document
document.open();
// step 4: we create a table and add it to the document
LwgImage img = LwgImage.getInstance("pngnow.png");
img.scalePercent(70);
Chunk ck = new Chunk(img, 0, -5);
LwgPdfPTable table = new LwgPdfPTable(3);
LwgPdfPCell cell = new LwgPdfPCell();
cell.addElement(new Chunk(img, 5, -5));
cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
cell.setHorizontalAlignment(LwgElement.ALIGN_CENTER);
table.add("I see an image\non my right");
table.add(cell);
table.add("I see an image\non my left");
table.add(cell);
table.add("I see images\neverywhere");
table.add(cell);
table.add("I see an image\non my right");
table.add(cell);
table.add("I see an image\non my left");
LwgPhrase p1 = new LwgPhrase("This is an image ");
p1.add(ck);
p1.add(" just here.");
document.add(p1);
document.add(p1);
document.add(p1);
document.add(p1);
document.add(p1);
document.add(p1);
document.add(p1);
document.add(table);
}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
catch(IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
}