I am trying to add some rows, images and tables to my pdf file (there should be several pages there), but when I try to use ColumnText(I use this because I want to place the rows in absolute positions), I run into a problem. When the column height is insufficient to add row content, the content is incomplete. How can I avoid losing content?
Here is the related code:
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
String imageUrl = "/Users/nofear/workspace/deneme23/pics/a4-ust.png";
String imageUrlAlt = "pics/a4-alt.png";
Image imageust = null;
Image imageAlt = null;
try {
imageust = Image.getInstance(imageUrl);
imageAlt = Image.getInstance(imageUrlAlt);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("HEIGHT"
+ (document.getPageSize().getHeight() - imageust.getHeight()));
imageust.setAbsolutePosition(0f,
document.getPageSize().getHeight() - imageust.getHeight()-10);
imageAlt.setAbsolutePosition( 0f, 10f);
document.add(imageust);
document.add(imageAlt);
cb.setLineWidth(1f);
cb.moveTo(0, 200);
cb.lineTo(200, 200);
cb.stroke();
Font helvetica8BoldBlue = FontFactory.getFont(FontFactory.HELVETICA,16);
ColumnText ct = new ColumnText(cb);
Phrase myText = new Phrase("Very Very Long String!!!" , helvetica8BoldBlue);
ct.setSimpleColumn(myText, 60, 750,
document.getPageSize().getWidth() - 40, 100,
20, Element.ALIGN_LEFT);
ct.go();
} catch (Exception e) {
} finally {
document.close();
}
source
share