/*
* $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.tables.pdfptable;
import java.awt.Color;
import com.lowagie.text.LwgDocument;
import com.lowagie.text.LwgElement;
import com.lowagie.text.LwgImage;
import com.lowagie.text.LwgPageSize;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.LwgPdfPCell;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;
/**
* Vertical Text in Cells.
*/
public class VerticalTextInCells {
/**
* Example with vertical text in Cells.
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("Vertical text in cells");
// step1
LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
try {
// step2
PdfWriter writer = PdfWriter.getInstance(document,
new GfrFileOutputStream("com.lowagie.examples.objects.tables.pdfptable.VerticalTextInCells.pdf"));
// step3
document.open();
// step4
// make a PdfTemplate with the vertical text
PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false);
String text = "Vertical";
float size = 16;
float width = bf.getWidthPoint(text, size);
template.beginText();
template.setRGBColorFillF(1, 1, 1);
template.setFontAndSize(bf, size);
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(size + 2);
// make an LwgImage object from the template
LwgImage img = LwgImage.getInstance(template);
img.setRotationDegrees(90);
LwgPdfPTable table = new LwgPdfPTable(3);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(LwgElement.ALIGN_MIDDLE);
LwgPdfPCell cell = new LwgPdfPCell(img);
cell.setPadding(4);
cell.setBackgroundColor(new Color(0, 0, 255));
cell.setHorizontalAlignment(LwgElement.ALIGN_CENTER);
table.add("I see a template on my right");
table.add(cell);
table.add("I see a template on my left");
table.add(cell);
table.add("I see a template everywhere");
table.add(cell);
table.add("I see a template on my right");
table.add(cell);
table.add("I see a template on my left");
document.add(table);
}
catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}
}