Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2008

Tip: Looking for answers? Try searching our database.

Check box

Thread view: 
ChinoKhan - 16 Apr 2008 15:38 GMT
I am writing an application in Java which submits data to MYSQL
database. I am using PDF fill able form to collect my data. Collecting
part of data is working fine. Problem comes in when I try to
repopulate data to the PDF form from MYSQL. The two types of objects I
have on my form are text field and check boxes. Text fields I can
repopulate without any problem. I need help in check boxes. I am using
Jar itext-2.0.6. Any help or code example will be appreciated.
Roedy Green - 16 Apr 2008 20:51 GMT
On Wed, 16 Apr 2008 07:38:20 -0700 (PDT), ChinoKhan
<kalimkhan@sbcglobal.net> wrote, quoted or indirectly quoted someone
who said :

>I am writing an application in Java which submits data to MYSQL
>database. I am using PDF fill able form to collect my data. Collecting
[quoted text clipped - 3 lines]
>repopulate without any problem. I need help in check boxes. I am using
>Jar itext-2.0.6. Any help or code example will be appreciated.

You are the first person I have encountered who has used PDF this way.
I would try some sort of PDF newsgroup. Most people here will be
familiar only with doing that only with AWT, Swing or HTTP and
Servlets.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Mark Space - 17 Apr 2008 00:11 GMT
> On Wed, 16 Apr 2008 07:38:20 -0700 (PDT), ChinoKhan
> <kalimkhan@sbcglobal.net> wrote, quoted or indirectly quoted someone
[quoted text clipped - 12 lines]
> familiar only with doing that only with AWT, Swing or HTTP and
> Servlets.

I think there's some PDF technology that turns PDFs into a Flash
website.  Adobe has been pushing Flex, I bet it's related to that.

I'm not sure at all though, and I've never worked with Flex.
Abhijat Vatsyayan - 17 Apr 2008 00:33 GMT
> I am writing an application in Java which submits data to MYSQL
> database. I am using PDF fill able form to collect my data. Collecting
[quoted text clipped - 3 lines]
> repopulate without any problem. I need help in check boxes. I am using
> Jar itext-2.0.6. Any help or code example will be appreciated.
Could you post the relevant source code? It also helps if you post a
simple program to  reproduce the problem . Did you do a google search at
all? What did you find out? I see several discussions related to
checkboxes, itext and PDF but unless I see your code, it difficult to help.
ChinoKhan - 22 Apr 2008 15:13 GMT
> > I am writing an application in Java which submits data to MYSQL
> > database. I am using PDF fill able form to collect my data. Collecting
[quoted text clipped - 8 lines]
> all? What did you find out? I see several discussions related to
> checkboxes,itextand PDF but unless I see your code, it difficult to help.

Here is the code that works for textbox, The last field in key and
value is checkbox. Value comming out of it is Corp. I hope you can
help me.

package Ola.src;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.AcroFields;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPTableEvent;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.events.FieldPositioningEvents;
import util.src.StrTran;
import sun.jdbc.rowset.CachedRowSet;

import java.sql.*;

/**
*
* @author  kkhan
*/

public class PDFFiller implements PdfPTableEvent {
   MySqlNativeDriver nativeDrive = new MySqlNativeDriver();
   MYSQLInsertUpdate insetupdate = new  MYSQLInsertUpdate();
   StrTran st = new StrTran();
   static CachedRowSet crs;

  /* public static final String BusinessName = "BusinessName"; //
Field Names
   public static final String BusinessAddress = "BusinessAddress";
   public static final String City = "City";
   public static final String State = "State";*/

   public static final String Session =            "Session";
   public static final String Agent_id=            "Agent_id";
   public static final String Status =             "Status";
   public static final String referral_id=         "BankNameNumber";
   public static final String AssociationNumber=
"AssociationNumber";
   public static final String OfficeName=
"OfficeNameNumber";
   public static final String RepName=             "RepNameNumber";
   public static final String BusinessName=        "BusinessName";
   public static final String BusinessAddress=     "BusinessAddress";
   public static final String City        =        "City";
   public static final String State        =       "State";
   public static final String Zip        =         "Zip";
   public static final String LocationPhone=       "LocationPhone";
   public static final String Ext           =      "Ext";
   public static final String LocationFax=         "LocationFax";
   public static final String WebSite =            "Website";
   public static final String CardholderName =     "CardholderName";
   public static final String CorporateName=       "CorporateName";
   public static final String BillingAddress   =   "BillingAddress";
   public static final String BillingCity=         "BillingCity";
   public static final String BillingState   =     "BillingState";
   public static final String BillingZip  =        "BillingZip";
   public static final String ContactName =        "ContactName";
   //public static final String           //" OwnerName";
   public static final String
BusinessContactPhone="BusinessContactPhone";
   public static final String BusinessEmail=       "BusinessEmail";
   public static final String CorporateEmail =    "ContactEmail";
   public static final String SendStatementTo =
"SendStatementTo"; // This is checkbox

   String vreferral_id="";
   String vRepName="";
   String vBusinessName ="";
   String vBusinessAddress = "";
   String vOfficeName ="";
   String vCity = "";
   String vstate = "";
   String vZip = "";
   String vLocationPhone="";
   String vExt="";
   String vLocationFax="";
   String vBusinessEmail="";
   String vBusinessWebsite="";
   String vCorporateName="";

   String vCorporateAddress="";
   String vCorporateCity="";
   String vCorporateState="";
   String vCorporateZip="";
   String vCorporateContactName="";
   String vCorporateContactPhone="";
   String vCorporateEmail="";
   String vSendMonthlyStatementsTo=""; // This is checkbox

   String queryString ="";

   /** Creates a new instance of olatemplet */
   public PDFFiller() {
   }

   /**
    * @param args the command line arguments
    */
   public void FillTemplet(String name) {
       try {
           queryString = "Select * from app where app_id ='"+name
+"'";
           crs=nativeDrive.query(queryString);

           while(crs.next()){

               vreferral_id = crs.getString("referral_id").trim();
               vRepName     = crs.getString("RepName").trim();
               vBusinessName =crs.getString("BusinessName").trim();
               vBusinessAddress =
crs.getString("BusinessAddress").trim();
               vOfficeName=crs.getString("OfficeName").trim();
               vCity = crs.getString("BusinessCity").trim();
               vstate = crs.getString("Businessstate").trim();
               vZip = crs.getString("BusinessZip").trim();
               vLocationPhone =crs.getString("BusinessPhone").trim();
               //vExt =crs.getString("Ext").trim();
               vLocationFax =crs.getString("BusinessFax").trim();
               vBusinessEmail=crs.getString("BusinessEmail").trim();

vBusinessWebsite=crs.getString("BusinessWebSite").trim();
               vCorporateName=crs.getString("CorporateName").trim();

vCorporateAddress=crs.getString("CorporateAddress").trim();
               vCorporateCity =crs.getString("CorporateCity").trim();

vCorporateState=crs.getString("CorporateState").trim();
               vCorporateZip=crs.getString("CorporateZip").trim();

vCorporateContactName=crs.getString("CorporateContactName").trim();

vCorporateContactPhone=crs.getString("BusinessContactPhone").trim();

vCorporateEmail=crs.getString("CorporateEmail").trim();
               //
vSendMonthlyStatementsTo=crs.getString("SendStatementTo").trim();
               vSendMonthlyStatementsTo="Corp";  // This is checkbox

               System.out.println("lllllllllllllllllllllll"+
crs.getString("SendStatementTo"));

           }
           crs.close();

       }
       catch (Exception e){
           System.out.println(e.toString());
       }

       Document document = new Document();
       String state ="CA";
       System.out.println("988888888888888888888888"+State);
       String[] keys =
       { referral_id,
         RepName,
         BusinessName,
         BusinessAddress,
         OfficeName,
         City,
         State,
         Zip,
         LocationPhone,
         //Ext,
         LocationFax,
         BusinessEmail,
         WebSite,
         CorporateName,
         BillingAddress,
         BillingCity,
         BillingState,
         BillingZip,
         ContactName,
         BusinessContactPhone,
         CorporateEmail,
         SendStatementTo,// This is checkbox

       };

       String[][] values = {
           { vreferral_id,
             vRepName,
             vBusinessName ,
             vBusinessAddress,
             vOfficeName,
             vCity,
             vstate,
             vZip,
             vLocationPhone,
             //vExt,
             vLocationFax,
             vBusinessEmail,
             vBusinessWebsite,
             vCorporateName,
             vCorporateAddress,
             vCorporateCity,
             vCorporateState,
             vCorporateZip,
             vCorporateContactName,
             vCorporateContactPhone,
             vCorporateEmail,
             vSendMonthlyStatementsTo,// This is checkbox

           },

       };

       PdfReader reader;
       ByteArrayOutputStream baos;
       PdfStamper stamper;
       AcroFields form;
       document = new Document();

       System.out.println("999999999999999999999999");
       try {
           PdfCopy copy = new PdfCopy(document, new
FileOutputStream("f:\\Kalim\\InProgress\\"+name+".pdf"));
           document.open();
           for (int i = 0; i < values.length; i++) {
               // set fields
               //reader = new PdfReader("K:\\KALIM\\online\\Newtek
Application1 PDF.pdf");
               reader = new PdfReader("C:\\Tomcat 4.1\\webapps\
\Templet\\App.pdf");
               baos = new ByteArrayOutputStream();
               stamper = new PdfStamper(reader, baos);
               form = stamper.getAcroFields();
               form.setExtraMargin(0, 1);
               for (int j = 0; j < keys.length; j++) {
                   form.setField(keys[j], values[i][j]);
                   System.out.println(keys[j]+" "+values[i][j]);
               }
               stamper.setFormFlattening(false);
               stamper.close();
               // add page
               reader = new PdfReader(baos.toByteArray());
               copy.addPage(copy.getImportedPage(reader, 1));
               copy.addPage(copy.getImportedPage(reader, 2));
               copy.addPage(copy.getImportedPage(reader, 3));

           }
       } catch (DocumentException de) {
           System.err.println(de.getMessage());
       } catch (IOException ioe) {
           System.err.println(ioe.getMessage());
       }
       document.close();
   }

   public void tableLayout(PdfPTable table, float[][] width, float[]
heights, int headerRows, int rowStart, PdfContentByte[] canvases) {
       float widths[] = width[0];
       PdfContentByte cb = canvases[PdfPTable.TEXTCANVAS];
       cb.rectangle(widths[0] - 5, heights[heights.length - 1] - 5,
widths[widths.length - 1] - widths[0] + 10, heights[0] -
heights[heights.length - 1] + 10);
       cb.stroke();
   }

}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.