DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

John has posted 11 posts at DZone. View Full User Profile

Creating A PDF Using IText And ColdFusion

03.06.2006
| 8215 views |
  • submit to reddit
        // description of your code here

<cfscript>
// create document
document 		= CreateObject("java", "com.lowagie.text.Document");
document.init();

// writer
fileIO 			= CreateObject("java", "java.io.FileOutputStream");
fileIO.init(pdf_path);
writer 			= CreateObject("java", "com.lowagie.text.pdf.PdfWriter");
writer.getInstance(document, fileIO);
document.open();

// newsinfo header image
Image 			= CreateObject("java", "com.lowagie.text.Image");
jpg 			= Image.getInstance(header_image);
jpg.setAbsolutePosition(28, 713);
jpg.setDpi(300,300);
document.add(jpg);

// top margin; dumb i know but i was in a hurry
paragraph = CreateObject("java", "com.lowagie.text.Paragraph");
paragraph.init(" ");
for (i=0; i lt 9; i=i+1) {
	document.add(paragraph);
}

// the fonts
FontFactory 	= createobject("java", "com.lowagie.text.FontFactory");
Font 			= createObject("java", "com.lowagie.text.Font");
TimesLargeBI 	= Font.init(Font.TIMES_ROMAN, 14.0, Font.BOLDITALIC);
TimesNormal 	= Font.init(Font.TIMES_ROMAN, 12.0);

// all the text
paragraph 		= CreateObject("java", "com.lowagie.text.Paragraph");

paragraph.init("Hello World!", TimesLargeBI);
paragraph.setIndentationLeft(indentation_left);
paragraph.setIndentationRight(indentation_right);
document.add(paragraph);

paragraph.init("#dateFormat(now(), 'long')#", TimesNormal);
paragraph.setIndentationLeft(indentation_left);
paragraph.setIndentationRight(indentation_right);
document.add(paragraph);

document.close();
</cfscript>