
PDF - why is this so hard?
OK.
For anyone interested, and I assume that are very few of you,
I have actually cracked this particular nut concerning FDF,
XFDF and PDF population form VB6.
As it turns out my assumption of how it all works was a little
off, which caused me great confusion in the end.
It seems once you generate an FDF file, or an XFDF file (which
is the XML version of the original FDF format) that file becomes
the one that is opened by the reader (there is a reference in the
FDF file to the PDF document) and the reader merges the data with
the blank PDF file.
So, for a simple PDF file with two fields, Text1 and Text2
FDF:
Dim FdfAcX As FDFACXLib.FdfApp
Set FdfAcX = CreateObject("FdfApp.FdfApp")
Dim fdf As FDFACXLib.FdfDoc
Set fdf = FdfAcX.FDFCreate
fdf.FDFSetFile "c:\pdf\Application.pdf"
fdf.FDFSetValue "Text1", "myValue1", False
fdf.FDFSetValue "Text2", "myValue2", False
fdf.FDFSaveToFile "c:\pdf\Application.fdf"
fdf.FDFClose
XFDF:
xfdf = "<?xml version=""1.0"" encoding=""UTF-8""?>"
xfdf = xfdf & "<xfdf xmlns=""http://ns.adobe.com/xfdf/""
xml:space=""preserve"">"
xfdf = xfdf & "<f href=""c:\pdf\Application.pdf""/>"
xfdf = xfdf & "<fields>"
xfdf = xfdf & "<field name=""Text1"">"
xfdf = xfdf & "<value>myValue1</value>"
xfdf = xfdf & "</field>"
xfdf = xfdf & "<field name=""Text2"">"
xfdf = xfdf & "<value>myValue2</value>"
xfdf = xfdf & "</field>"
xfdf = xfdf & "</fields>"
xfdf = xfdf & "</xfdf>"
Open "c:\pdf\Application.xfdf" For Output As #1
Print #1, xfdf
Close
Excuse the fact that I'm not using an XML object to generate
the xml file, as would be the normal case, this is just an
example of the XFDF format.
Then a simple shellopen to the fdf or xfdf file opens Acrobat
Reader with the data filled in, and the user is free to admire
or print it at their leisure.
I like the XFDF technique due to the lack of a required AX,
but I think the client will need a fairly new version of reader,
the least of my worries.
kpg