[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to set absolute position with iText and Coldfusion

Posted on 2011-02-28
3
Medium Priority
?
2,719 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 750 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
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: mywebsite.com/wp…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
Suggested Courses

656 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