Difference between revisions of "How to create an e-Mail PDF Survey Form"

From Scribus Wiki
Jump to: navigation, search
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
[[Category:PDF_Forms]][[Category:EN]][[Category:PDF]]
 +
 
'''Introduction'''
 
'''Introduction'''
 
+
{{TOC_Forms_sidebar}}
 
How often have you ever been emailed a PDF form that you have been told to print it, fill it in with a pen and then fax or post it back to the sender?
 
How often have you ever been emailed a PDF form that you have been told to print it, fill it in with a pen and then fax or post it back to the sender?
 
   
 
   
Line 9: Line 11:
 
The demonstration form however uses an online server which is complicated and expensive to setup.
 
The demonstration form however uses an online server which is complicated and expensive to setup.
  
A far simpler way is to use e-mails to exchange the data and the form can be easily modified to change the way the data is transferred. The setup of the Submit Button is all that needs to be changed. Instead of the data being sent as HTML to a web address, the '''“mailto:”''' command is used.  By using the '''“mailto:”''' command, Adobe Acrobat Reader automatically attaches data in a FDF file to an email. This command works with most mail clients used in Windows and Linux.
+
A far simpler way is to use e-mails to exchange the data and the form can be easily modified to change the way the data is transferred. The setup of the Submit Button is all that needs to be changed. Instead of the data being sent as HTML to a web address, the '''“mailto:”''' command is used.  By using the '''“mailto:”''' command, Adobe Acrobat Reader automatically attaches data in a FDF file to an email. This command works with most mail clients used in Windows and Linux. You can test your system by clicking on '''“mailto:”'''.
 
   
 
   
 
FDF is short for Forms Data Format and they are basically text files that contain data from the PDF form. Not quite HTML, but a similar cousin. The form's field names and data are stored within a tag set. Characters between tags are irrelevant and don't appear anywhere within the displayed PDF file.  
 
FDF is short for Forms Data Format and they are basically text files that contain data from the PDF form. Not quite HTML, but a similar cousin. The form's field names and data are stored within a tag set. Characters between tags are irrelevant and don't appear anywhere within the displayed PDF file.  
Line 67: Line 69:
  
 
'''An example of a script to process FDF files into MS Excel'''
 
'''An example of a script to process FDF files into MS Excel'''
 +
<br/>'''Links are BROKEN'''
  
Below is a macro that allows you to extract data from FDF files. The macro is heavily commented to show what each line of code does. This script should be able to be easily converted to other applications.
+
[http://www.box.net/shared/e5hdj945gu openfdf.zip] contains a MS Excel spreadsheet with a macro that allows you to extract data from FDF files. The macro is heavily commented to show what each line of code does.
 
 
 
 
'''Excel Macro'''
 
 
 
<nowiki>Public Sub DoAdobeImport()
 
 
 
Dim FName As Variant
 
 
 
Dim Sep1 As String
 
 
 
Dim Sep2 As String
 
 
 
Dim Sep3 As String
 
 
 
Dim Sep4 As String
 
 
 
Dim RowNdx As Integer
 
 
 
Dim ColNdx As Integer
 
 
 
Dim WholeLine As String
 
 
 
Dim Pos As Integer
 
 
 
Dim NextPos As Integer
 
 
 
Dim StartPos As Integer
 
 
 
Dim EndPos As Integer
 
 
 
Dim recordPos As Integer
 
 
 
Dim recordPos2 As Integer
 
 
 
Dim SaveColNdx As Integer
 
 
 
Dim Part1 As String
 
 
 
Dim Part2 As String
 
 
 
'get name of FDF file
 
 
 
FName = Application.GetOpenFilename _
 
    (filefilter:="Adobe FDF Data Files(*.fdf),*.fdf,All Files (*.*),*.*", Title:="Select FDF file to import")
 
   
 
If FName = False Then
 
 
 
    MsgBox "You didn't select a file"
 
 
 
    Exit Sub
 
 
 
End If
 
 
 
'Set record separators
 
 
 
Application.ScreenUpdating = False
 
 
 
Sep1 = "<<"
 
 
 
Sep2 = ">>"
 
  
Sep3 = "/T"
+
For those without Excel who would like to have the script, [http://www.box.net/shared/ucureoydhn openfdf.txt] is the macro script in a text file.  The macro code should be easily converted for use in other applications.
  
Sep4 = ")"
 
  
'set cell row and column where to start entering data
+
'''An example of code to process FDF files into MS Access'''
  
ColNdx = ActiveCell.Column
+
[http://www.box.net/shared/2a0bo1pupc FDFdataImport.mdb] contains a MS Access file with functions that allows you to extract data from FDF files. The functions are heavily commented to show what each line of code does.
  
RowNdx = ActiveCell.Row
+
There are two functions:-
  
Open FName For Input Access Read As #1 'open fdf file
 
  
 +
'''CreateTable'''
  
    Line Input #1, WholeLine 'Skip first three lines as they do not contain any data
+
This module displays creates an dialog box that lets the user specify the drive, directory, and the name of a FDF file to open. The data fields are extracted and a table called "tblFDFImport"  is created with the appropriate field names.
  
    Line Input #1, WholeLine
+
The table can be manually adjusted to change the field types and sizes. The default field type is Text with a size of 200 characters.
  
    Line Input #1, WholeLine
 
  
    StartPos = (InStr(1, WholeLine, "[")) + 1 ' find where data starts
+
'''DoAdobeImport'''
  
    EndPos = (InStr(1, WholeLine, "]")) - 1 ' find where data ends
+
This module displays creates an dialog box that lets the user specify the drive, directory, and the name of a FDF file to open. The data  is extracted into the table called "tblFDFImport".
  
    WholeLine = Mid(WholeLine, StartPos, EndPos) 'capture just the data fields
 
 
    Pos = 3 ' set start position
 
 
   
 
    NextPos = InStr(Pos, WholeLine, Sep2) 'find end of current record
 
 
    While NextPos >= 1
 
 
        TempVal = Mid(WholeLine, Pos, NextPos - Pos) 'Find start of next record
 
 
        recordPos = (InStr(1, TempVal, Sep4)) 'Go to end of record by using ")"
 
 
        'Assume the value is in A1, in B1  =Left(A1,len(A1)-2)
 
 
       
 
 
        Part1 = Trim(Mid(TempVal, 1, recordPos)) 'get data record name
 
       
 
        '*******Comment out the line below if you do not want data record name*****
 
 
        Cells(RowNdx, ColNdx).Value = Right((Left(Part1, Len(Part1) - 1)), Len((Left(Part1, Len(Part1) - 1))) - 3) ' trim off
 
 
start and end superfluous characters and enter in cell
 
       
 
        '*******Comment out the line below if you do not want data record name*****
 
 
        RowNdx = RowNdx + 1 'move to next row
 
       
 
        recordPos2 = (InStr(1, TempVal, Sep4)) ' find ")" which is end of record
 
       
 
        Part2 = Trim(Mid(TempVal, recordPos2)) 'get data
 
 
        'Check to see if data field is blank
 
 
        If Part2 = Sep4 Then
 
 
        Cells(RowNdx, ColNdx).Value = ""
 
 
        'Check if Data is Yes or No
 
 
        ElseIf Right(Part2, 1) <> Sep4 Then 'trim off start and end superfluous characters and enter in cell
 
 
        Cells(RowNdx, ColNdx).Value = Right((Left(Part2, Len(Part2) - 0)), Len((Left(Part2, Len(Part2) - 0))) - 4) ' trim off start and end superfluous characters and enter in cell
 
 
        Else
 
 
        Cells(RowNdx, ColNdx).Value = Right((Left(Part2, Len(Part2) - 1)), Len((Left(Part2, Len(Part2) - 1))) - 4) ' trim off start and end superfluous characters and enter in cell
 
 
        End If
 
       
 
        'Cells(RowNdx, ColNdx).Value = Trim(Mid(TempVal, recordPos2))  'Second part which contains data
 
 
        ColNdx = ColNdx + 1 ' move to next column
 
       
 
        '*******Comment out the line below if you do not want data record name*****
 
 
        RowNdx = RowNdx - 1 ' move up a row
 
 
       
 
        Pos = NextPos + 4 ' move to start of next record record
 
 
        NextPos = InStr(Pos, WholeLine, Sep2) ' find end of next record
 
 
        'if more records loop again
 
 
    Wend
 
 
'if no more records end
 
 
Close #1
 
 
End Sub</nowiki>
 
  
 
'''Possible Uses for this System'''
 
'''Possible Uses for this System'''
  
 
Club membership applications / database
 
Club membership applications / database
 +
 
Client information database
 
Client information database
 +
 
Electronic Survey forms
 
Electronic Survey forms
 +
 
Electronic examinations
 
Electronic examinations

Latest revision as of 06:09, 14 January 2011


Introduction

edit
  1. Your first PDF form with Scribus
  2. How to create an e-Mail PDF Survey Form
  3. Your second PDF form with Scribus
  4. Enhance PDF forms with JavaScript

How often have you ever been emailed a PDF form that you have been told to print it, fill it in with a pen and then fax or post it back to the sender?

….and you thought to yourself, “Why don’t they just send me a PDF form that I can quickly type in the information and email it back.”

With Scribus you can create electronic PDF forms that can do exactly this. In the Scribus Wiki article “Your first PDF form with Scribus” you are shown how to create a sample PDF form and if you tried it, you will have an idea of what is involved.

The demonstration form however uses an online server which is complicated and expensive to setup.

A far simpler way is to use e-mails to exchange the data and the form can be easily modified to change the way the data is transferred. The setup of the Submit Button is all that needs to be changed. Instead of the data being sent as HTML to a web address, the mailto:” command is used. By using the mailto:” command, Adobe Acrobat Reader automatically attaches data in a FDF file to an email. This command works with most mail clients used in Windows and Linux. You can test your system by clicking on mailto:”.

FDF is short for Forms Data Format and they are basically text files that contain data from the PDF form. Not quite HTML, but a similar cousin. The form's field names and data are stored within a tag set. Characters between tags are irrelevant and don't appear anywhere within the displayed PDF file.

Adobe Acrobat Reader can open a FDF file but requires the original PDF form to do so. If you double click on a FDF file, Reader requests the location of the PDF form. Once linked up with the PDF form location, the PDF form opens with the FDF data in the fields. FDF files are a fraction of the size of the complete PDF form.


Creating a e-Mail PDF form

Scribussurvey.JPG


In the document “Your first PDF form with Scribus” you are shown how to create a PDF form to submit data to a server. A copy of the example file can be downloaded from a link on that page.

You can easily modify the example form to e-mail the data. Open the Scribus version of the document with Scribus. Right click your mouse on the “Submit” Button (Blue Rectangle). A menu pops up and select PDF Options –> Field Properties

Next select the Action Tab –> choose Submit Form and enter “mailto:” with your email address. Do not tick the Submit data as HTML.


Submit.JPG

Click OK. Now save your document as a PDF and view it with Adobe Acrobat Reader.

Testing your PDF form

Enter some data on the form and click the SUBMIT Button. By answering the prompts and security questions correctly, your email client should create an email with a FDF attachment to the address you specified. Something like the image below.

Email.JPG


Notice the difference in the file size between the FDF and PDF.


How to use FDF files

There are two options that I can think of -

1. Dump the data back into the form and print it, or

2. Extract the data into a spreadsheet or database


While Adobe would prefer you to purchase the full version of Acrobat, you can still do a lot with the free Scribus and Acrobat Reader software.

As the data in the FDF file is text, it is easily accessible by using a script or macro to extract the data contained in it. If you Save a FDF file from a e-mail (this is the only way to get one out of Reader) and open it in a text editor, you will the field names and your data with a whole lot of other characters.

If you use the example, you will see amongst other words and characters, the following words

Country Komentarz Miasto Name No Street Submit Telefon Zip

You will notice that this order is different to the PDF form. The fields are in alphabetical order. If you want your fields in the same order as on the PDF form, then you will need to name the fields in alphabetical order.

For example-

AName BStreet CNo DZip EMiasto FCountry GTelefon HKomentarz Submit


An example of a script to process FDF files into MS Excel
Links are BROKEN

openfdf.zip contains a MS Excel spreadsheet with a macro that allows you to extract data from FDF files. The macro is heavily commented to show what each line of code does.

For those without Excel who would like to have the script, openfdf.txt is the macro script in a text file. The macro code should be easily converted for use in other applications.


An example of code to process FDF files into MS Access

FDFdataImport.mdb contains a MS Access file with functions that allows you to extract data from FDF files. The functions are heavily commented to show what each line of code does.

There are two functions:-


CreateTable

This module displays creates an dialog box that lets the user specify the drive, directory, and the name of a FDF file to open. The data fields are extracted and a table called "tblFDFImport" is created with the appropriate field names.

The table can be manually adjusted to change the field types and sizes. The default field type is Text with a size of 200 characters.


DoAdobeImport

This module displays creates an dialog box that lets the user specify the drive, directory, and the name of a FDF file to open. The data is extracted into the table called "tblFDFImport".


Possible Uses for this System

Club membership applications / database

Client information database

Electronic Survey forms

Electronic examinations