Use of VeryPDF PDF Form Filler SDK with VBA code from MS Office products to fill PDF forms dynamically

Some customers want to know how to fill the PDF forms from MS Excel, MS Word or MS PowerPoint Macro, in fact, this can be done easily suing VeryPDF PDF Form Filler SDK, VeryPDF PDF Form Filler SDK can be called from MS office products (MS Access, MS Excel etc.) to fill forms, we will provide the details of how to integrate PDF Form Filler SDK with excel VBA in this article.

image

VeryPDF PDF Form Filler SDK is a professional product to fill PDF forms, you can also call it from Excel VBA to fill the PDF forms easily.

Please download the trial version from following web page to try,

https://www.verypdf.com/app/pdf-form-filler/try-and-buy.html#buy-sdk
https://www.verypdf.com/pdfform/pdfformsdk.zip

after you download it, please run following command line to register pdfformcom.exe with administrator privilege,

pdfformcom.exe /regserver

then you can use following VB Script code to fill PDF forms,
-------------------------------
Set fso = CreateObject("Scripting.FileSystemObject")
strFolderDir = App.Path

Set VeryPDFFormCom = CreateObject("VeryPDFFormEXECOM.pdfformcom")

szInPDFFile = (strFolderDir & "\example-fw9.pdf")
szInFDFFile = (strFolderDir & "\example-fw9.fdf")
szInXFDFFile = (strFolderDir & "\example-fw9.xfdf")
szOutPDFFile = (strFolderDir & "\out-filled.pdf")
szOutPDFFileByXFDF = (strFolderDir & "\out-filled-byXFDF.pdf")
szOutFDFFile = (strFolderDir & "\out.fdf")
szFlattenPDFFile = (strFolderDir & "\out-flatten.pdf")
szEncryptPDFFile = (strFolderDir & "\out-encrypt.pdf")

VeryPDFFormCom.com_PDFForm_SetLicenseKey ("XXXXXXXXXXXXXXX")
bRet = VeryPDFFormCom.com_PDFForm_MergeFDFIntoPDF(szInPDFFile, szInFDFFile, szOutPDFFile)
bRet = VeryPDFFormCom.com_PDFForm_MergeXFDFIntoPDF(szInPDFFile, szInXFDFFile, szOutPDFFileByXFDF)
bRet = VeryPDFFormCom.com_PDFForm_ExtractFDFFromPDF(szOutPDFFile, szOutFDFFile)
bRet = VeryPDFFormCom.com_PDFForm_FlattenPDF(szOutPDFFile, szFlattenPDFFile)
bRet = VeryPDFFormCom.com_PDFForm_EncryptPDF(szOutPDFFile, "123", "456", "Printing", 128, szEncryptPDFFile)
-------------------------------

You have two methods to fill the data into PDF forms,

1. Use FDF file to fill PDF forms,

You can write the form data to a FDF file first, and then call com_PDFForm_MergeFDFIntoPDF() function to combine FDF and PDF together.

2. Fill the data to PDF forms directly,

You can use "com_PDFForm_SetTextField()" and "com_PDFForm_SetCheckBox()" functions to fill the data to PDF forms directly, the following is a VBA example which can be used from MS Office VBA to fill the PDF forms from VBA code directly,

--------------------------------
Private Sub CommandButton1_Click()
Set fso = CreateObject("Scripting.FileSystemObject")
strFolderDir = ActiveWorkbook.Path & "\"

Set VeryPDFFormCom = CreateObject("VeryPDFFormEXECOM.pdfformcom")

szInPDFFile = (strFolderDir & "test.pdf")
szOutPDFFile = (strFolderDir & "_out-filled-PDFForm_Alloc.pdf")

VeryPDFFormCom.com_PDFForm_SetLicenseKey ("XXXXXXXXXXXXXXX")

ID = VeryPDFFormCom.com_PDFForm_Alloc()
nRet = VeryPDFFormCom.com_PDFForm_SetCheckBox(ID, "12_Permission1", "Yes")
nRet = VeryPDFFormCom.com_PDFForm_SetCheckBox(ID, "12_Permission2", "Off")
nRet = VeryPDFFormCom.com_PDFForm_SetCheckBox(ID, "12_Permission3", "Yes")
nRet = VeryPDFFormCom.com_PDFForm_SetCheckBox(ID, "12_Permission4", "Off")
nRet = VeryPDFFormCom.com_PDFForm_SetCheckBox(ID, "12_Permission5", "Yes")
nRet = VeryPDFFormCom.com_PDFForm_SetCheckBox(ID, "12_Permission6", "Off")
nRet = VeryPDFFormCom.com_PDFForm_SetCheckBox(ID, "12_Permission7", "Yes")

nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "1_SchoolNumber", "99999")
nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "2_SchoolName", "VeryPDF")
nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "9_Reason1", "VeryPDF")
nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "9_Reason2", "VeryPDF")
nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "9_Reason3", "VeryPDF")
nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "9_Reason4", "VeryPDF")
nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "9_Reason5", "VeryPDF")
nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "9_Reason6", "VeryPDF")
nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "9_Reason7", "VeryPDF")
nRet = VeryPDFFormCom.com_PDFForm_SetTextField(ID, "Designation1", "Designation1")

nRet = VeryPDFFormCom.com_PDFForm_Apply(ID, szInPDFFile, szOutPDFFile, False)
nRet = VeryPDFFormCom.com_PDFForm_Free(ID)

MsgBox ("Create " & szOutPDFFile & " Successful.")

End Sub
--------------------------------

Please download the latest version of PDF Form Filler SDK from this web page,

https://www.verypdf.com/app/pdf-form-filler/try-and-buy.html#buy-sdk
https://www.verypdf.com/pdfform/pdfformsdk.zip

this package is contain a "VBA" folder, this folder is contain two sample Excel files,

test_very_PDF_VBA.xlsm: This file does use FDF to fill the PDF forms.

test_very_PDF_VBA2.xlsm: This file does fill PDF forms directly.

You can press ALT+F11 to active VBA Editor in MS Excel application, then you can modify the functions to best meet your requirements.

In order to run these two .XLSM files properly, you need place them and test.pdf file into same folder, then you can test them properly.

VeryPDF

VN:F [1.9.20_1166]
Rating: 6.4/10 (5 votes cast)
VN:F [1.9.20_1166]
Rating: -1 (from 1 vote)
Use of VeryPDF PDF Form Filler SDK with VBA code from MS Office products to fill PDF forms dynamically, 6.4 out of 10 based on 5 ratings

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!