I used itext on a project about 5 years ago, and am attempting to get back into
it for a project I am working on now, combining Jfreecharts and some text and
graphics (header, footer, table, a corporate logo - nothing terribly fancy) in
producing pdf files. My problem comes when doing what would seem to be a
simple operation, displaying some text 'Foo' at a position (x,y). I've tried
to look for examples on how to do this and found several, but I cannot get the
simplest example to work for me, and I'm wondering if there's some strange
configuration issue or something causing my problem.
For example, I came across an example while surfing around that just draws a
headline on a page with a horizontal line under it.
public class PdfTest {
public static void main(String[] args) {
System.out.println("PDF example");
Document document = new Document();
try {
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("output2.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
cb.beginText();
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "Our headline",
200,200, 0);
cb.endText();
// now draw a line below the headline
cb.setLineWidth(1f);
cb.moveTo(0, 755);
cb.lineTo(595, 755);
cb.stroke();
// now we can place content elements on the page
} catch (Exception e) {
}
document.close();
}
}
I get nothing. but if I take the text drawing section out of it:
public class PdfTest {
public static void main(String[] args) {
System.out.println("PDF example");
Document document = new Document();
try {
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("output2.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
// now draw a line below the headline
cb.setLineWidth(1f);
cb.moveTo(0, 755);
cb.lineTo(595, 755);
cb.stroke();
// now we can place content elements on the page
} catch (Exception e) {
}
document.close();
}
}
.... I get the horizontal line, no problem. It seems like the initial example
should work, and it should be that easy to do what I'm trying to do, but it
just... ain't... working. Anyone else seen something like that? Am I
completely missing something? I rather liked my earlier project that used
itext and was kind of looking forward to doing this new one with it, but now
I'm not so sure.
Stuart Neal
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php