Planet PDF Forum Archive

Planet PDF ForumWowsers! This is page is old, head to the LIVE Planet PDF Forum. It features more than 10 conferences, covering everything from beginner to in-depth developer and pre-press discussions. If you wish to continue... one & two archive covers 1999-2011 (160,000 pages).


New Forum | Previous | Next | (P-PDF) Developers


Topic: How to fill in data based on selection, 2 Attachments
Conf: (P-PDF) Developers, Msg: 75356
From: chicks
Date: 5/8/2003 03:12 AM

Here's a simple example to fill a standard IRS form, the W4, using the isedQuickPDF library (ActiveX version).

The library is available here ($65, unlimited installs):

http://www.sedtech.com/isedquickpdf/?page=home

The fillable version of the W4 is available here:

http://www.irs.gov/pub/irs-fill/fw4_02.pdf

Here's the vbscript to fill it from an XML datasource. The XML is just below it. The XML source file would normally be created from your http results. This command-line example can easily be adapted for ASP use...

fillpdf.vbs
--------------------------------------------------------------

Dim QP, i, value, ffName
Dim searchXPath, dom, nodes, node, element
Dim xmlFileName, inFileName, outFileName
'-- Init iSedQuickPDF and DOM objects
Set QP = CreateObject("iSED.QuickPDF")
Set dom = CreateObject("MSXML2.DOMDocument") '-- Set file names inFileName = "fw4_02.pdf" xmlFileName = "fw4_02.xml" '-- Load XML file into DOM If dom.load(xmlFileName) = False Then WScript.Echo("Could Not Load " + xmlFileName) WScript.Quit(Err) End If '-- Unlock the PDF library Call QP.UnlockKey("My Unlock Key") '-- Load the input PDF Call QP.LoadFromFile(inFileName) '-- Get the "FW4_02" nodes in DOM Set nodes = dom.selectNodes("//FW4_02") '-- Loop through each "FW4_02" node For Each node In nodes '-- Set the output PDF file name to SSAN.pdf outFileName = node.selectSingleNode("f1-10").nodeTypedValue & _ node.selectSingleNode("f1-11").nodeTypedValue & _ node.selectSingleNode("f1-12").nodeTypedValue & ".pdf" WScript.Echo(outFileName) '-- Loop through PDF Form fields For i = 1 to QP.FormFieldCount '-- Get the field name ffName = QP.GetFormFieldTitle(i) '-- If it's a text field If(left(ffName, 1) = "f") Then '-- Null out the field value Call QP.SetFormFieldValue(i, "") '-- Set the field to Editable Call QP.SetFormFieldReadOnly(i, 0) End If '-- Set the XML Search Path searchXPath = ffName '-- Find the first matching element Set element = node.selectSingleNode(searchXPath) If element Is Nothing Then WScript.Echo(searchXPath & " Not Found") Else '-- Get the element's value value = element.nodeTypedValue '-- If it's not null If value <> vbNull Then '-- Fill the field with value from XML file Call QP.SetFormFieldValue(i, value) '-- Set the field to Read Only Call QP.SetFormFieldReadOnly(i, 1) End If End If Next '-- Save document to PDF File Call QP.SaveToFile(outFileName) Next '-- Clean up Call QP.RemoveDocument(QP.SelectedDocument) Set QP = Nothing Set dom = Nothing '-- We're Done! WScript.Quit(Err)

fw4_02.xml ------------------------------------------------------



1
0
0
0
1
0
0
0
Charles H.
Brown
999
99
9999
123 Main Street
Petaluma, CA 92348-9999
2
0.00

Charles Shultz  22 Peanuts Lane Santa Rosa, CA 91234

11
2222





















1
0
0
0
1
0
0
0
Lucy Q.
Van Pelt
888
88
8888
125 Main Street
Petaluma, CA 92348-9999
2
0.00

Charles Shultz  22 Peanuts Lane Santa Rosa, CA 91234

11
2222






















Click to open!fillpdf.vbs
fillpdf.vbs (2,098 bytes)

Click to open!fw4_02.xml
fw4_02.xml (1,935 bytes)


PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link...

Download free demo

Debenu PDF Tools Pro

It's simple to use and will let you preview and edit PDF files, it's a Windows application that makes...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.