Mike Buchanan wrote:
It does get frustrating when I can pump in a few hundred lines of code a day but then it sometimes takes two or three days to figure out how to do just one function.
I studied architecture. As a developer I'm a Mies Van der Rohe adept: Less is More. I'd rather spend a week doing nothing, thinking about how to solve a problem, and then code 100 lines solving the problem in one day. Then code a 1000 lines a day for two weeks, ending up with a solution that is almost impossible to maintain.
In the book, page 284, it notes that drawing lines and shapes is called"constructing and painting paths". So, what is a path?
On the same page, it says: "The first thing you need to know is how to draw lines and shapes; in PDF terminology this is called constructing and painting paths."
I understood it to be setting a starting position in a table cell and then placing something there.
No, it's about drawing lines and shapes.
The example you returned to me does the same as theexample in the book, it simply draws a line through the table cell.
Yes, because I hadn't the faintest idea of what you were trying to achieve.
So you moveTo() a starting point and then lineTo() a destination point to draw the line. This I understand. Now I need to moveTo() a starting point and draw the text, not a straight line.
So you want to draw text instead of lines and shapes? Then you should move on to chapter 11 (p344): "The text state is a subset of the graphics state."
Simply put, we need to overlay several table columns with text while still showing all of the borders and coloring of the table columns under the text. In effect, this is like printing over a preprinted form, if you catch my drift.
See the attachment. Of course, showTextAligned DOESN'T WRAP the text string. Maybe you'll want to calculate the width of the String first, and then change the font accordingly. Or you may want to use ColumnText to position the text correctly; I don't know... It all depends on your requirements. And it's all explained in the book. I'm not using any special methods that aren't mentioned in the book here. Maybe I should start thinking about a 3 day course on iText. It would be fun to teach how to use iText, and it would surely lower the threshold for future users... best regards, Bruno
package test; //Test overlaying multiple PDF table cells with text import java.io.*; import com.lowagie.text.*; import com.lowagie.text.pdf.*; class TextOverlay { private static Document doc; private static float[] colWidths; private static boolean colorSw = false; public static void main (String [] args) throws Exception { doc = new Document (PageSize.LETTER.rotate()); PdfWriter.getInstance (doc, new FileOutputStream ("test_overlay.pdf")); doc.open (); float[] colSizes = { 72f, 18f, 140f, 95f, 30f }; colWidths = colSizes; createTable(); doc.close (); } private static void createTable() throws Exception { // Define an inner and outer table. PdfPTable outerTable = new PdfPTable(1); outerTable.setTotalWidth(355f); outerTable.setLockedWidth(true); PdfPTable innerTable = new PdfPTable(5); innerTable.setTotalWidth(colWidths); innerTable.setLockedWidth(true); // Load the inner table with every other cell colored Paragraph innerPara = new Paragraph(); PdfPCell innerCell = new PdfPCell(innerPara); innerPara.setLeading(11f); innerPara.add (new Phrase (" ")); innerCell.setFixedHeight(15f); for(int i = 0;i < 5;i++) { if(colorSw) { colorSw = false; innerCell.setBackgroundColor(new CMYKColor(.05f, .01f, .00f, .03f)); } else { colorSw = true; innerCell.setBackgroundColor(new CMYKColor(0f, 0f, 0f, 0f)); } innerTable.addCell(innerCell); } PdfPCell outerCell = new PdfPCell(innerTable); outerCell.setCellEvent(new DoCellEvent()); outerCell.setBorder(Rectangle.NO_BORDER); outerTable.addCell(outerCell); doc.add(outerTable); } } class DoCellEvent implements PdfPCellEvent { protected BaseFont bf; public DoCellEvent() throws DocumentException, IOException { bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); } public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { PdfContentByte cb = canvases[PdfPTable.TEXTCANVAS]; String commentStr = "This comment in the outer table will extend over multiple cells in the inner table"; cb.beginText(); cb.setFontAndSize(bf, 9); cb.showTextAligned(Element.ALIGN_LEFT, commentStr, position.left() + 3, position.bottom() + 3, 0); cb.endText(); } }
------------------------------------------------------------------------- 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 iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/