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
Solved

how to set absolute position with iText and Coldfusion

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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to best troubleshoot slow internet connections via proxy server? 2 87
HSSFWorkbook cannot be resolved error 10 105
eclipse apache tomcat admin console 52 121
WebSite Direction 1 54
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

809 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