// we create a reader for a certain document reader = createObject("java", "com.lowagie.text.pdf.PdfReader").init(inputFilePath); // filling in the form fos = createObject("java", "java.io.FileOutputStream").init(outputFilePath); stamp1 = createObject("java", "com.lowagie.text.pdf.PdfStamper").init(reader, fos); acrForm = stamp1.getAcroFields(); acrForm.setField("name", session.test1); acrForm.setField("address", session.test2); stamp1.close(); fos.close(); [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => mxstu [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> iText and Coldfusion - Coldfusion - Advanced Techniques

iText and Coldfusion - Coldfusion - Advanced Techniques

Hi I take it that the approach stated on http://www.worlddesign.com/index.cfm/rd/cf/PDFForms.htm does not work on CFMX7? I need to use the iText feature ? What is the latest version of iText that is on CFMX 7 ? would I have to replace this with iText version 1.3? If this is the case I have modified iText code below, how would I then integrate this into my CF page and where would the code below sit in the CF structure ? Finally how would the PDF doent know where to populate the correct form fields in the pdf doent as there is ...

  1. #1

    Default iText and Coldfusion

    Hi

    I take it that the approach stated on
    http://www.worlddesign.com/index.cfm/rd/cf/PDFForms.htm does not work on CFMX7?

    I need to use the iText feature ? What is the latest version of iText that is
    on CFMX 7 ? would I have to replace this with iText version 1.3?

    If this is the case I have modified iText code below, how would I then
    integrate this into my CF page and where would the code below sit in the CF
    structure ?

    Finally how would the PDF doent know where to populate the correct form
    fields in the pdf doent as there is no FDF doc involved?

    Ian

    -----------------------------

    package com.lowagie.examples.general.copystamp;

    import java.io.FileOutputStream;

    import com.lowagie.text.pdf.AcroFields;
    import com.lowagie.text.pdf.PdfReader;
    import com.lowagie.text.pdf.PdfStamper;

    /**
    * Fill in a simple registration form.
    */
    public class Register {
    /**
    * Reads a form and fills in the fields.
    * param args no arguments needed
    */
    public static void main(String[] args) {
    System.out.println("Filling in a form");
    try {
    // we create a reader for a certain doent
    PdfReader reader = new PdfReader("cex124original.pdf");
    int n = reader.getNumberOfPages();
    // filling in the form
    PdfStamper stamp1 = new PdfStamper(reader, new
    FileOutputStream("cex124modified.pdf"));
    AcroFields form = stamp1.getAcroFields();
    form.setField("test1", "#session.test1#");
    form.setField("test2", "#session.test2#");
    stamp1.close();
    }
    catch (Exception de) {
    de.printStackTrace();
    }
    }
    }




    rambo Guest

  2. #2

    Default Re: iText and Coldfusion

    I don't know whether or not the approach mentioned in your link works on MX7.
    If you are curious, try it.

    Re- Do you need to install version 1.3?
    I believe the iText version shipped with MX7 is older than 1.3. I don't know
    the exact version number. Whether or not you need to install version 1.3,
    depends on what features/bug fixes you need. You shouldn't need v1.3 for this
    simple example. Note - If for some reason you do need to version 1.3 you could
    use the workaround suggested at the end of
    http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=7&thread
    id=961725

    Re - Your sample code
    I don't think you can access cf #session# variables that way from within a
    java class. It would be much easier to simply manipulate the java objects
    directly in your cfm page, rather than putting the code in a separate class.
    Since I don't have access to your "cex124original.pdf" doent. Attached is a
    simplified example, using the "SimpleRegistrationForm.pdf" found in the iText
    examples page.



    <cflock scope="session" type="exclusive" timeout="10">
    <cfset session.test1 = "Testing, testing, one two three...">
    <cfset session.test2 = "Testing, testing, blah, blah, blah">
    </cflock>

    <!--- Note - set this value to your PDF file path --->
    <cfset inputFilePath = expandPath(".") &"\SimpleRegistrationForm.pdf">
    <cfset outputFilePath = expandPath(".") &"\SimpleRegistrationForm_Output.pdf">

    <!--- based on sample code at iText site --->
    <cfscript>
    // we create a reader for a certain doent
    reader = createObject("java",
    "com.lowagie.text.pdf.PdfReader").init(inputFilePa th);

    // filling in the form
    fos = createObject("java", "java.io.FileOutputStream").init(outputFilePat h);
    stamp1 = createObject("java", "com.lowagie.text.pdf.PdfStamper").init(reader ,
    fos);
    acrForm = stamp1.getAcroFields();
    acrForm.setField("name", session.test1);
    acrForm.setField("address", session.test2);

    stamp1.close();
    fos.close();
    </cfscript>

    mxstu Guest

  3. #3

    Default Re: iText and Coldfusion

    Hi

    I have tried your example but I am getting the following error, any ideas?

    Object Instantiation Exception.
    An exception occurred when instantiating a java object. The cause of this
    exception was that: .

    The error occurred in F:\createpdf.cfm: line 13

    11 : <cfscript>
    12 : // we create a reader for a certain doent
    13 : reader = createObject("java",
    "com.lowagie_new.text.pdf.PdfReader").init(inputFi lePath);
    14 :
    15 : // filling in the form

    I am using the workaround, for the new version of iText 1.3 as you can see
    from the snippet above com.lowagie_new


    rambo Guest

  4. #4

    Default Re: iText and Coldfusion

    rambo,

    So you're sure you actually need to use version 1.3? I didn't try it with
    version 1.3, but it should work the same assuming the PdfReader() constructor
    in version 1.3 still accepts a file path. Check the 1.3 API docs.

    Make sure you restarted the CF server after adding the new iText jar to the
    cf_root\wwwroot\WEB-INF\lib directory and make sure that the file path in the
    "inputFilePath" variable actually exists.





    mxstu Guest

  5. #5

    Default Re: iText and Coldfusion

    Hi

    Still getting the same error?

    In my CF Admin the class path is set to cfmx7\wwwroot\web-inf\lib\itext
    (where the itext directory contains the itext_new.jar file)

    And the simpleregistrationform.pdf is in the correct directory?

    Does this work for you ? as it is strange how it is not working ?



    rambo Guest

  6. #6

    Default Re: iText and Coldfusion

    Yes, it works fine for me, but as you can see the example uses the standard jar
    that comes with MX7. I would suggest using the example as is, before trying to
    change it to work with the version 1.3 jar. You don't need version 1.3 to run
    my example.

    You didn't answer my questions.

    1) Did you restart the CF server?
    2) Does the input file exist?
    3) Is the input file in the correct directory? For example, if you use this:

    <cfset inputFilePath = expandPath(".") &"\SimpleRegistrationForm.pdf">

    The file must be in the same directory as your test cfm page. I suspect the
    problem is that the file is not in the correct location.

    mxstu Guest

  7. #7

    Default Re: iText and Coldfusion

    Hi

    Thanks that seems to work now, I needed to add the \ before the filename.

    How could I now make your example have the generated pdf file integrate into a
    <cfmail as an e-mail attachment ?

    Any ideas on how I would achieve this with the cfmailparam tag?

    <cfmail to="#email#"
    from="#SESSION.app.applicant_email#"
    subject="Test Form"
    type="HTML" 
    <cfmailparam file="??????????">
    </cfmail>
    <cfmailp>

    rambo Guest

Similar Threads

  1. Concatenate paragraphs in one doent using itext (java)
    By Laurence_Bouvard@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 1
    Last Post: January 25th, 02:18 AM
  2. How to call a coldfusion function defined in other coldfusion file??
    By apngss@yahoo.com in forum Coldfusion - Getting Started
    Replies: 0
    Last Post: October 24th, 07:30 PM
  3. Itext Problems
    By iborsb in forum Coldfusion - Advanced Techniques
    Replies: 9
    Last Post: October 5th, 03:07 PM
  4. iText problem
    By the_last in forum Coldfusion - Advanced Techniques
    Replies: 4
    Last Post: September 24th, 05:19 AM
  5. Calling Itext Functions
    By iborsb in forum Coldfusion - Advanced Techniques
    Replies: 5
    Last Post: August 27th, 04:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •