Creating the ASP Code I

We can now begin to look at the ASP code that we need to provide the functionality. Firstly we need to define a few standard functions and variables, this includes subroutines to produce a standard FDF header and footer for our output and a simple subroutine to encode field values in FDF as well. These three functions will form the basis of our interaction with the PDF Form :

rem Define Carriage Return/Line Feed
CRLF = Chr(13) & Chr(10)

rem Generate FDF header data
sub FDFHeader()
    response.ContentType = "application/vnd.fdf"
    'response.ContentType = "text/html"
    response.write("%FDF-1.2" & CRLF)
    response.write("1 0 obj <<" & CRLF)
    response.write("/FDF <<" & CRLF)
    response.write("/Fields" & CRLF)
    response.write("[" & CRLF)
end sub

rem Generate FDF footer data
sub FDFFooter ( pdfFile)
    response.write("]" & CRLF)
    response.write("/F (" & pdfFile & ") " & CRLF)
    response.write(">>" & CRLF)
    response.write(">>" & CRLF)
    response.write("endobj" & CRLF)
    response.write("trailer" & CRLF)
    response.write("<</Root 1 0 R>>" & CRLF)
    response.write ("%%EOF")
end sub

rem Generate FDF name/value pair
sub FDFValue (fdf_name, fdf_value)
    response.write("<<" & CRLF)
    response.write("/T (" & fdf_name & ") " & CRLF)
    response.write("/V (" & fdf_value & ") " & CRLF)
    response.write(">>" & CRLF)
end sub

One of the important things to note here is contained in the FDFHeader function :

    response.ContentType = "application/vnd.fdf"
    'response.ContentType = "text/html"

Here we appear to have two defined Content Types for the output - although one is commented out - the first application/vnd.fdf is the correct Content Type for FDF output, but the inclusion of the second - text/html - allows us to display the FDF datastream as plain text, which can be very useful when debugging a problem as you can see all the FDF elements that are returned as well as any errors that are returned, as shown in this example. Changing the type is relatively simple, you simply uncomment one line and comment the other.

In the next section we will look at adding a little more detail to the skeltal structure provided here.

Website Designed by Adservio Consulting      Bookmark and Share Valid HTML 4.01 Strict    Valid CSS!    Level A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0