?
Solved

Fill PDF forms with Access data using JavaScript Code Question

Posted on 2004-08-21
3
Medium Priority
?
1,793 Views
Last Modified: 2007-11-27
I have some code that using ADBC connects to a db and gets data that I prepared programmatically prior to the opening of the PDF file.

My problem is that is doesn't close the object quick enough to fill in the form with new data.  It takes some amount of time to time out and "disconnect" before you can open the PDF and fill the form again with new data.  

The code is enclosed!

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//<ACRO_Document-Level>
//<ACRO_source>Connect</ACRO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.Connect ***********/


function Connect()
{
  try
  {
    //app.alert("Attempting Connection ...");
    dbConn = ADBC.newConnection(dbName);
    if(dbConn == null)
       throw "Error connecting to AcroTips";

    stmtObj = dbConn.newStatement();
   
    // Execute the SQL statement inside the database
    stmtObj.execute(sqlToExecute);

    // Move the Result Set to the First Record Found
    stmtObj.nextRow();

    // The current row object
    rowObj = stmtObj.getRow();

    // Insert the values of the first Row of data into the
    // form field values.
    FillForm(rowObj);

    // Let the user know that a connection was made.
    //app.alert("Connected to Database");

  }
  catch(exc)
  {
    console.println(exc);
    throw "Unable to Connect to Database";

  }
}


//</ACRO_script>
//</ACRO_Document-Level>

//<ACRO_Document-Level>
//<ACRO_source>FillForm</ACRO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.FillForm ***********/
function FillForm(row)
{
  this.getField("Name").value = row.Name.value;
  this.getField("Address").value = row.Address.value;
  this.getField("CSZ").value = row.CSZ.value;
  this.getField("SS").value = row.SS.value;
  this.getField("Age").value = row.Age.value;
  this.getField("DOB1").value = row.DOB1.value;
this.getField("Today").value = row.Today.value;
this.getField("HomePhone").value = row.HomePhone.value;


}
//</ACRO_script>
//</ACRO_Document-Level>

//<ACRO_Document-Level>
//<ACRO_source>FirstRecord</ACRO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.FirstRecord ***********/

function firstRecord()
{
  stmtObj.execute(sqlToExecute);
  stmtObj.nextRow();
  rowObj = stmtObj.getRow();
  FillForm(rowObj);
}

//</ACRO_script>
//</ACRO_Document-Level>

//<ACRO_Document-Level>
//<ACRO_source>ListDataBases</ACRO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.ListDataBases ***********/

function ListDataBases()
{
    var aList = ADBC.getDataSourceList();
    console.show(); console.clear();
    try
    {
   
        var DB = "", msg = "";
        if (aList != null)
        {
           for (var i=0; i < aList.length; i++)
           {
                console.println("Name: "+aList[i].name);
                console.println("Description: "+aList[i].description);
                // and choose one of interest
           }
         }  
    }      
    catch(exc)
    {
        console.println(exc);
    }

}

//</ACRO_script>
//</ACRO_Document-Level>

//<ACRO_Document-Level>
//<ACRO_source>NextRecord</ACRO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.NextRecord ***********/

function nextRecord()
{
  try
  {
      stmtObj.nextRow();
      FillForm(stmtObj.getRow());
  }
  catch(e)
  {
  }
}

//</ACRO_script>
//</ACRO_Document-Level>

//<ACRO_Document-Level>
//<ACRO_source>StartUP</ACRO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.StartUP ***********/
// Globals
var dbName = "WF2002";
var dbConn = null;
var stmtObj = null;
var sqlToExecute = "Select * from dotout";
var rowObj = null;
function Startup()
{
}
//</ACRO_script>
//</ACRO_Document-Level>

//<AcroForm>
//<ACRO_source>Fill In.ACRO_Annotation1.MouseUp.ACRO_Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm.Fill In.ACRO_Annotation1.MouseUp.ACRO_Action1 ***********/
Connect();

//</ACRO_script>
//</AcroForm>




Troyo
0
Comment
Question by:toverholt
[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 44

Expert Comment

by:Karl Heinz Kremer
ID: 11862090
You need to close your connection when you are done with it. Lookup the Connection object in the Acrobat JavaScript Scripting Reference document (from what I see in the code, I figure that you already have this document). You will find a close() method. Call this (on the connection to your DB) when you don't need it anymore (e.g. when the document gets closed).
0
 

Author Comment

by:toverholt
ID: 11866415
I was hoping for a little more direction.....like where to put the code.  I am a HUGE vb geek, and MS Access geek.  This area is new to me, and javascript still seems foreign to me, althought I muttered through this.

Troyo
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 2000 total points
ID: 11866505
Troyo,

sorry about that. You can create "document actions" (see the "Advanced>JavaScript>Set Document Actions" menu item). A document action allows you to create a callback that gets executed on certain events. For this case, you are looking for "Document will close". The JavaScript you put into this document action will be executed right before the document gets closed. So, assuming you have your connection variable in a document level variable, you can add this line to the "document will close" action:

dbConn.close();

This should take care of resetting the connection so that you can open it again without timeout.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Getting information about Fonts being used in a PDF file A colleague of mine recently faced an issue related to the PDF file format. The PDFs were containing mission critical client information, they were successfully mailed but there was a sm…
Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe A recent question here at Experts Exchange piqued my interest, so I decided to provide a thorough solution and publ…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Suggested Courses

777 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