Solved

how to set absolute position with iText and Coldfusion

Posted on 2011-02-28
3
2,625 Views
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 :

<cfscript>
// 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", "java.io.FileOutputStream");


// call the constructor, pass the location where you want
// the pdf to be created
fileIO.init("#expandpath("MYPDF.pdf")#");

// 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
document.open();
 
// 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));
phrase.setAlignment(Element.ALIGN_LEFT);

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

document.add(phrase0);
document.add(phrase);
document.add(phrase2);

//image block
Image.getInstance("#expandpath("logo.jpg")#");
logo1.setDpi(300,300);
logo1.scaleAbsolute(263, 117);
logo1.setAbsolutePosition(166, 32);
document.add(logo1);

document.close();
</cfscript>

Many thanks
0
Comment
Question by:alliancecube
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
ID: 35001566
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.

http://stackoverflow.com/questions/1625455/itext-positioning-text-absolutely
0
 

Author Closing Comment

by:alliancecube
ID: 35007955
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...
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35009124
@alliancecube

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!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is JNDI datasource in spring 1 62
Nameserver and MX Record 2 71
null output 3 24
web & database SERVERS -- PHYSICAL & VM ? 5 55
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

806 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