I have a fillable pdf document that I did not create.
I been asked if I can place data into it from my database.
Looks as if it should be simple. However I do need to know or be able to name the fields (cells) that will contain the data.
Does anyone know how I can find out the fields names? Or at least give them names?
Once I have these I would need to open the pdf - any advice here would be welcome as to which application and then assign values to the named fields.
I have a fillable pdf document that I did not create.
I been asked if I can place data into it from my database.
Looks as if it should be simple. However I do need to know or be able to name the fields (cells) that will contain the data.
Does anyone know how I can find out the fields names? Or at least give them names?
Once I have these I would need to open the pdf - any advice here would be welcome as to which application and then assign values to the named fields.
Pointers in the direction of how to do this would be welcomed.
Jim
This post relates to Excel, but the VBA would work in Access as well. https://www.excelforum.com/excel-programming-vba-macros/1204659-writing-excel-data-into-pdf-form.html
It reads a pdf form to get all the field names and current values, and can also write to them as well.
I've adapted it to look loop through whatever fields it finds, rather than hard coding the field names.
Posting my slightly adjusted code below as well.
I am only beginning this journey of writing to a pdf...so can't offer much more help than this.
I'm about to explore what happens when I try to write to a field that doesn't exist.....
Good Luck,
Mal.
Sub ReadAdobeFields()
'Note: Remember to add your Adobe Acrobat Library in the VB Environment. 'Tools, References, Select the Adobe Acrobat Library.
row_number = 10 'Adjust for where to start on Sheet.
Dim AcrobatApplication As Acrobat.CAcroApp
Dim AcrobatDocument As Acrobat.CAcroAVDoc
Dim fcount As Long
Dim sWrkshtName As String
Dim sFileName As String
'On Error Resume Next
Set AcrobatApplication = CreateObject("AcroExch.App")
Set AcrobatDocument = CreateObject("AcroExch.AVDoc")
sFileName = Range("D5").Value
If AcrobatDocument.Open(sFileName, "") Then
AcrobatApplication.Show
Set AcroForm = CreateObject("AFormAut.App")
Set Fields = AcroForm.Fields
fcount = Fields.Count ' Number of Fields
For Each Field In Fields
ActiveSheet.Range("D" & row_number) = Field.Name
ActiveSheet.Range("E" & row_number) = Field.Value
row_number = row_number + 1
Next Field
Else
MsgBox "FAIL", vbOKOnly
End If
'Close template file & Acrobat.
AcrobatDocument.Close True
'AcrobatApplication.Exit
Set AcrobatApplication = Nothing
Set AcrobatDocument = Nothing
Set Field = Nothing
Set Fields = Nothing
Set ActoForm = Nothing
End Sub
Sub WriteAdobeFields()
'Note: Remember to add your Adobe Acrobat Library in the VB Environment. 'Tools, References, Select the Adobe Acrobat Library.
row_number = 10 'Adjust for where to start on Sheet.
Dim AcrobatApplication As Acrobat.CAcroApp
Dim AcrobatDocument As Acrobat.CAcroAVDoc
Dim fcount As Long
Dim sFieldName As String
Dim sFolderPath As String
Dim sFileName As String
Dim sWrkshtName As String
Dim sTemplateName As String
Dim sDATAtoWrite As String
Set AcrobatApplication = CreateObject("AcroExch.App")
Set AcrobatDocument = CreateObject("AcroExch.AVDoc")
sTemplateName = Range("D5").Value
sWrkshtName = ActiveSheet.Name
'ADJUST to pass name of Template from each Worksheet
If AcrobatDocument.Open(sTemplateName, "") Then
AcrobatApplication.Show
AcrobatApplication.Maximize 1
Set AcroForm = CreateObject("AFormAut.App")
Set Fields = AcroForm.Fields
fcount = Fields.Count ' Number of Fields
For Each Field In Fields
sFieldName = ActiveSheet.Range("D" & row_number).Value
sDATAtoWrite = ActiveSheet.Range("F" & row_number).Value
'check to see if this field is one to write, skip if not
If IsEmpty(ActiveSheet.Range("G" & row_number).Value) = False Then
Fields(sFieldName).Value = sDATAtoWrite
ActiveSheet.Range("h" & row_number).Value = "Done!"
Else
ActiveSheet.Range("h" & row_number).Value = "skipped"
End If
row_number = row_number + 1
Next Field
'ORIGINAL CODE COMMENTED OUT HERE
' Fields("Adults").Value = sWrkshtName.Range("C2").Value
' Fields("Students").Value = sWrkshtName.Range("C30").Value
' Fields("Group Name").Value = sWrkshtName.Range("C17").Value
' Fields("Campers NameRow1").Value = sWrkshtName.Range("C5").Value
' Fields("Campers NameRow2").Value = sWrkshtName.Range("C6").Value
' Fields("Campers NameRow3").Value = sWrkshtName.Range("C7").Value
' Fields("lunch").Value = sWrkshtName.Range("C51").Value
Else
MsgBox "failure"
End If
'Save PDF File
'Leave open for edit/printing
'? Close original template file
sFolderPath = "C:\Users\Administrator\Desktop\ExcelFilesForV360"
sFileName = sFolderPath & "\" & Fields("GroupName").Value & "-" & Format(Date, "dd-mm-yy") & ".pdf"
Set AcroApp = CreateObject("AcroExch.App")
Set avdoc = AcroApp.GetActiveDoc
If Not (avdoc Is Nothing) Then
Set PdDoc = avdoc.GetPDDoc
PdDoc.Save PDSaveFull, sFileName
End If
'Close template file here.
'AcrobatDocument.Close 1
'AcrobatApplication.Exit
Set AcrobatApplication = Nothing
Set AcrobatDocument = Nothing
Set Field = Nothing
Set Fields = Nothing
Set ActoForm = Nothing
End Sub
On Friday, July 24, 2020 at 2:17:25 AM UTC+10, internet...@foobox.com wrote:
I have a fillable pdf document that I did not create.
I been asked if I can place data into it from my database.
Looks as if it should be simple. However I do need to know or be able to name the fields (cells) that will contain the data.
Does anyone know how I can find out the fields names? Or at least give them names?
Once I have these I would need to open the pdf - any advice here would be welcome as to which application and then assign values to the named fields.
Pointers in the direction of how to do this would be welcomed.
Jim
Forgot to highlight/mention...and you also forgot to mention that an Adobe Acrobat must be installed
'Note: Remember to add your Adobe Acrobat Library in the VB Environment. 'Tools, References, Select the Adobe Acrobat Library.
Hi Mal,--- Synchronet 3.21d-Linux NewsLink 1.2
Am 24.07.2020 um 15:21 schrieb Mal Reeve:
Forgot to highlight/mention...and you also forgot to mention that an Adobe Acrobat must be installed
'Note: Remember to add your Adobe Acrobat Library in the VB Environment. 'Tools, References, Select the Adobe Acrobat Library.
and license is required.
Ulrich
This post relates to Excel, but the VBA would work in Access as well. https://www.excelforum.com/excel-programming-vba-macros/1204659-writing-excel-data-into-pdf-form.html
It reads a pdf form to get all the field names and current values, and can also write to them as well.
I've adapted it to look loop through whatever fields it finds, rather than hard coding the field names.
Posting my slightly adjusted code below as well.
I am only beginning this journey of writing to a pdf...so can't offer much more help than this.
I'm about to explore what happens when I try to write to a field that doesn't exist.....
Good Luck,
Mal.
Sub ReadAdobeFields()
'Note: Remember to add your Adobe Acrobat Library in the VB Environment. 'Tools, References, Select the Adobe Acrobat Library.
row_number = 10 'Adjust for where to start on Sheet.
Dim AcrobatApplication As Acrobat.CAcroApp
Dim AcrobatDocument As Acrobat.CAcroAVDoc
Dim fcount As Long
Dim sWrkshtName As String
Dim sFileName As String
'On Error Resume Next
Set AcrobatApplication = CreateObject("AcroExch.App")
Set AcrobatDocument = CreateObject("AcroExch.AVDoc")
sFileName = Range("D5").Value
If AcrobatDocument.Open(sFileName, "") Then
AcrobatApplication.Show
Set AcroForm = CreateObject("AFormAut.App")
Set Fields = AcroForm.Fields
fcount = Fields.Count ' Number of Fields
For Each Field In Fields
ActiveSheet.Range("D" & row_number) = Field.Name
ActiveSheet.Range("E" & row_number) = Field.Value
row_number = row_number + 1
Next Field
Else
MsgBox "FAIL", vbOKOnly
End If
'Close template file & Acrobat.
AcrobatDocument.Close True
'AcrobatApplication.Exit
Set AcrobatApplication = Nothing
Set AcrobatDocument = Nothing
Set Field = Nothing
Set Fields = Nothing
Set ActoForm = Nothing
End Sub
Sub WriteAdobeFields()
'Note: Remember to add your Adobe Acrobat Library in the VB Environment. 'Tools, References, Select the Adobe Acrobat Library.
row_number = 10 'Adjust for where to start on Sheet.
Dim AcrobatApplication As Acrobat.CAcroApp
Dim AcrobatDocument As Acrobat.CAcroAVDoc
Dim fcount As Long
Dim sFieldName As String
Dim sFolderPath As String
Dim sFileName As String
Dim sWrkshtName As String
Dim sTemplateName As String
Dim sDATAtoWrite As String
Set AcrobatApplication = CreateObject("AcroExch.App")
Set AcrobatDocument = CreateObject("AcroExch.AVDoc")
sTemplateName = Range("D5").Value
sWrkshtName = ActiveSheet.Name
'ADJUST to pass name of Template from each Worksheet
If AcrobatDocument.Open(sTemplateName, "") Then
AcrobatApplication.Show
AcrobatApplication.Maximize 1
Set AcroForm = CreateObject("AFormAut.App")
Set Fields = AcroForm.Fields
fcount = Fields.Count ' Number of Fields
For Each Field In Fields
sFieldName = ActiveSheet.Range("D" & row_number).Value
sDATAtoWrite = ActiveSheet.Range("F" & row_number).Value
'check to see if this field is one to write, skip if not
If IsEmpty(ActiveSheet.Range("G" & row_number).Value) = False Then Fields(sFieldName).Value = sDATAtoWrite
ActiveSheet.Range("h" & row_number).Value = "Done!"
Else
ActiveSheet.Range("h" & row_number).Value = "skipped"
End If
row_number = row_number + 1
Next Field
'ORIGINAL CODE COMMENTED OUT HERE
' Fields("Adults").Value = sWrkshtName.Range("C2").Value
' Fields("Students").Value = sWrkshtName.Range("C30").Value
' Fields("Group Name").Value = sWrkshtName.Range("C17").Value
' Fields("Campers NameRow1").Value = sWrkshtName.Range("C5").Value
' Fields("Campers NameRow2").Value = sWrkshtName.Range("C6").Value
' Fields("Campers NameRow3").Value = sWrkshtName.Range("C7").Value
' Fields("lunch").Value = sWrkshtName.Range("C51").Value
Else
MsgBox "failure"
End If
'Save PDF File
'Leave open for edit/printing
'? Close original template file
sFolderPath = "C:\Users\Administrator\Desktop\ExcelFilesForV360"
sFileName = sFolderPath & "\" & Fields("GroupName").Value & "-" & Format(Date, "dd-mm-yy") & ".pdf"
Set AcroApp = CreateObject("AcroExch.App")
Set avdoc = AcroApp.GetActiveDoc
If Not (avdoc Is Nothing) Then
Set PdDoc = avdoc.GetPDDoc
PdDoc.Save PDSaveFull, sFileName
End If
'Close template file here.
'AcrobatDocument.Close 1
'AcrobatApplication.Exit
Set AcrobatApplication = Nothing
Set AcrobatDocument = Nothing
Set Field = Nothing
Set Fields = Nothing
Set ActoForm = Nothing
End Sub
On Friday, July 24, 2020 at 2:17:25 AM UTC+10, internet...@foobox.com wrote:
I have a fillable pdf document that I did not create.
I been asked if I can place data into it from my database.
Looks as if it should be simple. However I do need to know or be able to name the fields (cells) that will contain the data.
Does anyone know how I can find out the fields names? Or at least give them names?
Once I have these I would need to open the pdf - any advice here would be welcome as to which application and then assign values to the named fields.
Pointers in the direction of how to do this would be welcomed.
Jim
I have a fillable pdf document that I did not create.
I been asked if I can place data into it from my database.
Looks as if it should be simple. However I do need to know or be able to name the fields (cells) that will contain the data.
Does anyone know how I can find out the fields names? Or at least give them names?
Once I have these I would need to open the pdf - any advice here would be welcome as to which application and then assign values to the named fields.
Pointers in the direction of how to do this would be welcomed.
Jim
I have just discovered this approach which I believe would work well.
It does depend on knowing the field names.
The sample file it includes has a routine that will get those field name - IF you have the full version of ACROBAT installed.
While I found a few postings about getting those names with READER DC - none of them worked for me.
Perhaps dig up an older version of the free Reader software - which would apparently let you export the form data and take a look. (untested)
Anyway....this page: http://www.excelhero.com/blog/2010/04/excel-acrobat-pdf-form-filler.html
Shows how to use create an "fdf" file (Form data only).
It's just a specially formatted text file.
Once created, you just open it....it grabs the default program (Acrobat or Reader DC) and drops the data into the fields.
I've done some basic testing with my situation and it's all working well with hard coded field names and data. Now on to use it in a looping function.
Good luck!
Mal.
On Friday, July 24, 2020 at 2:17:25 AM UTC+10, internet...@foobox.com wrote:
I have a fillable pdf document that I did not create.
I been asked if I can place data into it from my database.
Looks as if it should be simple. However I do need to know or be able to name the fields (cells) that will contain the data.
Does anyone know how I can find out the fields names? Or at least give them names?
Once I have these I would need to open the pdf - any advice here would be welcome as to which application and then assign values to the named fields.
--- Synchronet 3.21d-Linux NewsLink 1.2Pointers in the direction of how to do this would be welcomed.
Jim
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 59 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 24:08:10 |
| Calls: | 810 |
| Calls today: | 1 |
| Files: | 1,287 |
| D/L today: |
12 files (21,036K bytes) |
| Messages: | 195,978 |