Filling PDF Forms with PHP

Question: Is there a way to fill PDF forms and then save (flatten) them to PDF files from within PHP, /C#/.NET/... etc.? Which library would you recommend?

Answer: According to your needs, maybe you can have a free trial of this software: VeryPDF PDF Form Filler SDK, by which you can fill PDF forms and then save (flatten) them to PDF files from within PHP, /C#/.NET/... etc. By the SDK version, you can merge a FDF file into an existing PDF file and generate a new filled PDF file, extract FDF data from a filled PDF file, flatten a form filled PDF file, encrypt a PDF file, allocate a handle for PDF Form Filling and other. If you need to know more functions of this software, please visit its homepage. In the following part, let us check how to use this software.

Step 1. Free download PDF Form Filler SDK

  • All the VeryPDF software are free downloading and trying, so you can download it free to evaluate this software.
  • When downloading finishes, there will be a zip file, please extract it to some folder then you can check elements in it.
  • When downloading, please make sure download the right version as there is also PDF Form Filler OCX version available.

Step 2. Fill PDF form from PHP, /C#/.NET/... etc.

  • Here are some code examples for your reference, please have a check.

Example code:
Private Declare Sub PDFForm_SetLicenseKey Lib "pdfform.dll" (ByVal lpLicenseKey As String)
Private Declare Function PDFForm_MergeFDFIntoPDF Lib "pdfform.dll" (ByVal lpInPDF As String, ByVal lpInFDF As String, ByVal lpOutPDF As String) As Long
      Private Declare Function PDFForm_ExtractFDFFromPDF Lib "pdfform.dll" (ByVal lpInPDF As String, ByVal lpOutFDF As String) As Long
      Private Declare Function PDFForm_FlattenPDF Lib "pdfform.dll" (ByVal lpInPDF As String, ByVal lpOutPDF As String) As Long
      Private Declare Function PDFForm_EncryptPDF Lib "pdfform.dll" (ByVal lpInPDF As String, ByVal lpUserPwd As String, ByVal lpOwnerPwd As String, ByVal lpPermissions As String, ByVal nKeyLen As Long, ByVal lpOutPDF As String) As Long
      Private Declare Function PDFForm_Alloc Lib "pdfform.dll" () As Long
      Private Declare Function PDFForm_Free Lib "pdfform.dll" (ByVal id As Long) As Long
      Private Declare Function PDFForm_SetTextField Lib "pdfform.dll" (ByVal id As Long, ByVal lpFieldName As String, ByVal lpFieldValue As String) As Long
      Private Declare Function PDFForm_SetCheckBox Lib "pdfform.dll" (ByVal id As Long, ByVal lpFieldName As String, ByVal lpFieldValue As String) As Long
      Private Declare Function PDFForm_Apply Lib "pdfform.dll" (ByVal id As Long, ByVal lpInFile As String, ByVal lpOutFile As String, ByVal bFlatten As Long) As Long
      Private Declare Function PDFForm_ClearFields Lib "pdfform.dll" (ByVal id As Long) As Long

      Private Function PDFFormFilling1()
Dim id As Long
              Dim nRet As Long
              Dim szOutPDF1 As String
              Dim szOutPDF2 As String
              Dim szPDFFile As String
szPDFFile = App.Path + "\example-fw9.pdf"
              szOutPDF1 = App.Path + "\out1.pdf"
              szOutPDF2 = App.Path + "\out2.pdf"
              id = PDFForm_Alloc()
              nRet = PDFForm_SetTextField(id, "f1-1", "1 Test for Name")
              nRet = PDFForm_SetTextField(id, "f1-2", "1 Test for Business Name")
              nRet = PDFForm_SetTextField(id, "f1-3", "1 Test for f1-3")
              nRet = PDFForm_SetTextField(id, "f1-4", "1 Test for f1-4")
              nRet = PDFForm_SetTextField(id, "f1-5", "1 Test for f1-5")
              nRet = PDFForm_SetTextField(id, "f1-6", "1 Test for f1-6")
              nRet = PDFForm_SetCheckBox(id, "c1-4", "Off")
              nRet = PDFForm_SetCheckBox(id, "c1-5", "Off")
              nRet = PDFForm_SetCheckBox(id, "c1-1", "Yes")
              nRet = PDFForm_SetCheckBox(id, "c1-2", "Yes")
              nRet = PDFForm_Apply(id, szPDFFile, szOutPDF1, False)
              nRet = PDFForm_ClearFields(id)
              nRet = PDFForm_SetTextField(id, "f1-1", "2 Test for Name")
              nRet = PDFForm_SetTextField(id, "f1-2", "2 Test for Business Name")
              nRet = PDFForm_SetTextField(id, "f1-3", "2 Test for f1-3")
              nRet = PDFForm_SetTextField(id, "f1-4", "2 Test for f1-4")
              nRet = PDFForm_SetTextField(id, "f1-5", "2 Test for f1-5")
              nRet = PDFForm_SetTextField(id, "f1-6", "2 Test for f1-6")
              nRet = PDFForm_SetCheckBox(id, "c1-4", "Off")
              nRet = PDFForm_SetCheckBox(id, "c1-5", "Off")
              nRet = PDFForm_SetCheckBox(id, "c1-1", "Yes")
              nRet = PDFForm_SetCheckBox(id, "c1-2", "Yes")
              nRet = PDFForm_Apply(id, szPDFFile, szOutPDF2, True)
              nRet = PDFForm_Free(id)
End Function
      Private Function PDFFormFilling2()
Dim bRet As Long
              Dim szInPDFFile As String
              Dim szInFDFFile As String
              Dim szOutPDFFile As String
              Dim szOutFDFFile As String
              Dim szFlattenPDFFile As String
              Dim szEncryptPDFFile As String
szInPDFFile = App.Path + "\example-fw9.pdf"
              szInFDFFile = App.Path + "\example-fw9.fdf"
              szOutPDFFile = App.Path + "\out-filled.pdf"
              szOutFDFFile = App.Path + "\out.fdf"
              szFlattenPDFFile = App.Path + "\out-flatten.pdf"
              szEncryptPDFFile = App.Path + "\out-encrypt.pdf"
              bRet = PDFForm_MergeFDFIntoPDF(szInPDFFile, szInFDFFile, szOutPDFFile)
              bRet = PDFForm_ExtractFDFFromPDF(szOutPDFFile, szOutFDFFile)
              bRet = PDFForm_FlattenPDF(szOutPDFFile, szFlattenPDFFile)
              bRet = PDFForm_EncryptPDF(szOutPDFFile, "123", "456", "Printing", 128, szEncryptPDFFile)
End Function
      Private Sub PDFForm_Click()
              PDFForm_SetLicenseKey ("XXXXXXXXXXXXXXXX")
              PDFFormFilling1
              PDFFormFilling2
End Sub

During the using, if you have any question, please contact us as soon as possible.

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

This entry was posted in PDF Form Filler and tagged . Bookmark the permalink.

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!