Eric Summkeller wrote:
OK! I will try to explain you my problem in simple words.
In my programm I create a Chunk in which I want to save the toal page number.
For this problem I saw in your examples that I must use the PdfPTemplate. The
problem that I've got is, that this Chunk later will be added to a Pharagraph
with different other Chunks.
OK, but why on earth are you using a Generic Tag?
Create a PdfTemplate, wrap it in an Image.
Wrap the image in a Chunk.
The simple case is that I directly write this
Pharagraph into the Document. The other and the difficult case is, that this
Pharagraph can be added to a PdfPCell and in this cell the rotation can
change. Have you any idea how I can ensure that the total page number will be
correctly shown in the cell?
See the attached example.
br,
Bruno
package test;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
public class TotalPagesRotatedInTable {
public static final String TEXT = "blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah";
public static void main(String[] args) {
Document.compress = false;
Document document = new Document();
try {
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("x_of_y_in_table.pdf"));
document.open();
// we prepare our variables
PdfContentByte cb = writer.getDirectContent();
Chunk chunk = new Chunk("000");
PdfTemplate template =
cb.createTemplate(chunk.getWidthPoint(), 20);
Image image = Image.getInstance(template);
Chunk c = new Chunk(image, 0, 0);
PdfPTable table;
PdfPCell cell;
Phrase p;
// we add tables
for (int i = 0; i < 20; i++) {
table = new PdfPTable(2);
p = new Phrase("page " + writer.getPageNumber()
+ " of");
p.add(c);
cell = new PdfPCell();
cell.addElement(p);
cell.setRotation(90);
table.addCell(cell);
table.addCell(TEXT);
document.add(table);
document.newPage();
}
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
template.beginText();
template.setFontAndSize(bf, 12);
template.showTextAligned(Element.ALIGN_LEFT, " " +
(writer.getPageNumber() - 1), 0, 0, 0);
template.endText();
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
document.close();
}
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/