how to set absolute position with iText and Coldfusion

Posted on 2011-02-28
Last Modified: 2013-12-20
I need genrate PDf form Java class iText from COldfusion and not with CFDOCUMENT that is very bad to generate PDF (too large file, too slow).
I've made some testing and when I use iText class its more quick, and my PDF are better optimized.
So in fact I need to create some text block, images. For the images its realy simple (see code below), you can choose to put the image bloc with point precision but impossible for the text block. I thing probably there are some setting that can be same...
So I created a paragrapgh block, but if I try to use phrase2.setAbsolutePosition(x,y); I have error message... What is the solution to put a text block at x,y position in my PDF page ?

Sample code for image block :

// create a 'Document' object
rectangle = CreateObject("java", "com.lowagie.text.Rectangle");
pageSize = Rectangle.init(595, 842);
document = CreateObject("java", "com.lowagie.text.Document").init(pageSize, 0, 0, 0, 0);
Image = CreateObject("java", "com.lowagie.text.Image");

// get an outputstream for the PDF Writer
fileIO = CreateObject("java", "");

// call the constructor, pass the location where you want
// the pdf to be created

// get a PDF Writer var
writer = CreateObject("java", "com.lowagie.text.pdf.PdfWriter");

// call the static 'getInstance' factory method
writer.getInstance(document, fileIO);

// open the document;
// create a new paragraph
paragraph = CreateObject("java", "com.lowagie.text.Paragraph");
phrase = CreateObject("java", "com.lowagie.text.Phrase");

phrase0 = paragraph.init(" ", Font.init(Font.HELVETICA, 15));

phrase = paragraph.init("HELLO", Font.init(Font.HELVETICA, 20));

phrase2 = paragraph.init("WORLD", Font.init(Font.HELVETICA, 20));


//image block
logo1.scaleAbsolute(263, 117);
logo1.setAbsolutePosition(166, 32);


Many thanks
Question by:alliancecube
  • 2
LVL 52

Accepted Solution

_agx_ earned 250 total points
Comment Utility
if I try to use phrase2.setAbsolutePosition(x,y); I have error message

com.lowagie.text.Phrase doesn't have a setAbsolutePosition method, only images.  Here's one alternative to positioning text absolutely. Since you're using cfscript, the code should be almost identical.

Author Closing Comment

Comment Utility
I asked for Coldfusion and Java integration not for just the Java code, because my problem was to integrate the Java class in a Coldfusion Script tag...
LVL 52

Expert Comment

Comment Utility

I'm not sure why you had problems with it.  Especially as you didn't ask any questions.  I guess didn't look at the code too closely. As I said, since you're using cfscript it's almost an exact translation. In fact the only line that's different is the font line

    cb.SetFontAndSize(bf, 12);

instead of

     cb.SetFontAndSize(Font, 12);

Not a huge difference. Good Luck!

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following:…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Click on Too…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now