Is there a way in iText (the java version) to draw a rectangle into a pdf document?
A:
In the .NET version I just create a table with a border. I know it isn't Java but maybe the following code will help you.
iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER, 20, 20, 20, 20);
PdfPTable table;
PdfPCell cell;
// single element w/ border
table = new PdfPTable(1);
cell = new PdfPCell(new Phrase("BOLD WORDS", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 11, Font.BOLD)));
cell.BorderWidth = 2;
cell.Padding = 5;
cell.PaddingTop = 3;
cell.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell);
table.SetWidthPercentage(new float[1] { 598f }, PageSize.LETTER);
table.HorizontalAlignment = Element.ALIGN_CENTER;
document.Add(table);
Mayo
2009-08-21 13:01:06
+1
A:
You're in luck. There is an example on the iText website of how to do direct rendering.
http://itextdocs.lowagie.com/tutorial/directcontent/graphics/index.php
Dylan McClung
2009-08-21 14:02:12
Link no longer exists
Shaggy Frog
2010-04-25 21:05:04
+1
A:
Here is the solution. Thanks Dylan McClung.
cb.saveState();
cb.setColorStroke(Color.black);
cb.rectangle(x,y,x1,y1);
cb.stroke();
cb.saveState();
Milhous
2009-08-25 17:04:34