I need to compose PDF output based on certain input,
For anybody interested, here is a snippet for outputting PDF
using iText - probably not the nicest solution, but for a newbie,
this might
be a nice starting point:
>>>
//
// Main.java: Class file for WO Component 'Main'
// Project dprint
//
// Created by sp on 30.11.05
//
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
// step 3: we open the document
document.open();
// step 4: we add some content
document.add(new Paragraph("To create a document in landscape
format, just make the height smaller than the width. For instance by
rotating the PageSize Rectangle: PageSize.A4.rotate()"));
document.setPageSize(PageSize.A4);
document.newPage();
document.add(new Paragraph("This is portrait again"));
document.add(new Paragraph("Hello World"));
document.add(new Paragraph(new Date().toString()));
Chunk c;
c = new Chunk("background");
c.setBackground(new Color(0xC0, 0xC0, 0xC0));
document.add(c);
// the 14 standard fonts in PDF: do not use this Font constructor!
// this is for demonstration purposes only, use FontFactory!
Font[] fonts = new Font[14];
fonts[0] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.NORMAL);
fonts[1] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.ITALIC);
fonts[2] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.BOLD);
fonts[3] = new Font(Font.COURIER, Font.DEFAULTSIZE, Font.BOLD |
Font.ITALIC);
fonts[4] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.NORMAL);
fonts[5] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.ITALIC);
fonts[6] = new Font(Font.HELVETICA, Font.DEFAULTSIZE, Font.BOLD);
fonts[7] = new Font(Font.HELVETICA, Font.DEFAULTSIZE,
Font.BOLDITALIC);
fonts[8] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.NORMAL);
fonts[9] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.ITALIC);
fonts[10] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD);
fonts[11] = new Font(Font.TIMES_ROMAN, Font.DEFAULTSIZE,
Font.BOLDITALIC);
fonts[12] = new Font(Font.SYMBOL);
fonts[13] = new Font(Font.ZAPFDINGBATS);
// add the content
for (int i = 0; i < 14; i++) {
document.add(new Paragraph("quick brown fox jumps over the lazy
dog", fonts[i]));
}
}
catch(DocumentException de) {
System.err.println("Document problem: " + de.getMessage());
} catch ( Exception ex) {
System.err.println("Document problem 2: " + ex.getMessage());
}
// step 5: we close the document
document.close();
// we need to prepare NSData instead of String, since we are going to
// output arbitraty data
response.setContent( new NSData( oBuffer.toByteArray() ) );