fill a pdf form with data

  • what can be done in access to fill a pdf form with data stored in access?

  • some developers usually create their forms using e.g. word and then print it to a pdf printer. the reason being the ease of use of the the apis that are available


    Everything you can imagine is real.

  • you would need to get the pdf form API/component/ DLL


    Everything you can imagine is real.

  • where can i get the pdf form API/component/ DLL?

    is it free?

  • you can try cute pdf, but its not free   http://www.cutepdf.com/ pdf sdk

    from their sample code you will be doing something similar to

    Dim objMyForm

    Set objMyForm = Server.CreateObject("CutePDF.Document")  'Create form object

    objMyForm.initialize("FS20-001-12345678-12345678")          'Initialize object by serial number of the license

    'Open an encrypted PDF form file from an URL with password 'cutepdf'

    if objMyForm.openFile("ftp://www.ftpsite.com/Encrypted_Form.pdf","cutepdf") = false then 

        errorMessage = objMyForm.GetLastError()

    end if

    'Set some value into fields

    nReturn = objMyForm.setField("Company", "Acro Software Inc.")

    nReturn = objMyForm.setField("Address.1", "Company address")

    nReturn = objMyForm.setField("Address.2", "City, State, Zip")

    nReturn = objMyForm.setField("Product", "CutePDF Form SDK")

    'Save completed form file into a new PDF file

    objMyForm.saveFile("D:\CutePDF SDK\Forms\Form01.pdf")

    'Save a duplicate copy

    objMyForm.saveFile("D:\CutePDF SDK\Forms\Form02.pdf")

    ----

    which is your normal component usage


    Everything you can imagine is real.

  • Any way to convert the above vb code to sql

  • I spent a fair amount of time researching this very thing and trying all sorts of VBA code. I have successfully created code that will open a PDF and then insert data from Access into the form-fillable PDF. Getting code samples from Acrobat forums is extremely difficult. It's as if Acrobat programmers don't like to share code.

    That said, I've been wanting to share how I did it because I can't be the only one who needed this. Yes, Access can output to Word. Yes, Access can output a report as PDF. But what if the PDF is not your creation? What if you just need to populate it with data you have in your database?

    I am using Adobe Acrobat X Standard. I have a couple of ways I populate PDFs with data.

    1. pass an array of values to the procedure that populates the PDF and loop thru the array to insert the data

    2. use recordset and get data, then hard code the names of the PDF fields and populate them

    3. use a table to store the field mapping so that I can use a loop to populate the PDF fields with the corresponding Access data

    I work PT for an insurance brokerage so some of the forms I'm populating are called ACORD apps. You do NOT want to recreate these in Access so populating a PDF is 100x easier.

    I'm attaching a text file with the various code samples. It's all VBA code so it can be pasted into a new module. It will have to be modified quite a bit to meet your needs, but it's a start. Here's a basic sample:

    ' VERY BASIC EXAMPLE OF INSERTING DATA IN A PDF

    Public Sub PopulateCertHolder(ByVal sValue As String, ByVal sAcord As String, ByVal sSaveAs As String)

    Dim WshShell As Object

    On Error GoTo PopulateCertHolder_Error

    'open pdf fillable form

    1 Set WshShell = CreateObject("Wscript.Shell")

    2 WshShell.Run "Acrobat.exe " & sAcord

    'delay to let the form load completely

    3 PauseTime = 1

    4 Start = Timer

    5 Do While Timer < Start + PauseTime

    6 DoEvents

    7 Loop

    8 Set APP = CreateObject("Acroexch.app")

    9 Set AVDOC = CreateObject("AcroExch.AVDoc")

    10 Set AVDOC = APP.GetActiveDoc

    11 Set PDDOC = AVDOC.GetPDDoc

    12 Set jso = PDDOC.GetJSObject

    'populate fields

    Dim val As Variant

    18 Set x = jso.GetField("FormFieldName")

    19 val = sValue

    23 x.Value = val

    'save file

    31 PDDOC.Save 1, sSaveAs

    32 AVDOC.Close 1

    DoEvents

    33 APP.CloseAllDocs

    DoEvents

    34 APP.Exit

    'just in case window didn't close

    35 fCloseApp "AcrobatSDIWindow"

    'housekeeping on the way out

    36 Set APP = Nothing

    37 Set AVDOC = Nothing

    38 Set PDDOC = Nothing

    39 Set jso = Nothing

    Exit_PopulateCertHolder:

    Exit Sub

    PopulateCertHolder_Error:

    Call LogError(Err.Number, Err.Description, "AcrobatCode.PopulateCertHolder", Erl)

    Resume Exit_PopulateCertHolder

    End Sub

    Hope this helps!

    Diana

  • diana_criscione (12/24/2013)


    That said, I've been wanting to share how I did it because I can't be the only one who needed this. Yes, Access can output to Word. Yes, Access can output a report as PDF[/url]. But what if the PDF is not your creation[/url]? What if you just need to populate it with data you have in your database?

    Diana, thank you so so so much for sharing your findings with us. It definitely helps a lot.:-) I saves us much time in searching and reading each related topics.:-P

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply