Example 10 - Advanced: Import PDF, Output PDF Fields and Values

Imports FDFApp
Partial Public Class example_10
    Inherits System.Web.UI.Page
    Private Debug_Me As Boolean = False
    Private _example_dataset_datasource As String = ""
    Protected Sub Load_Examples_GridView(ByVal grid As GridView, Optional ByVal IsDefault As Boolean = False)
        Dim ds As DataSet, selectedIndex As Integer = 0
        ds = Examples_Dataset
        grid.DataMember = ds.Tables(0).TableName
        grid.DataSource = ds.Tables(0).DefaultView
        grid.DataBind()
        grid.Visible = True
        grid.Focus()
        Me.lblMessage_Bottom.Text = "Status: scroll to see gridview..."
    End Sub
    Protected Property Examples_Dataset() As DataSet
        Get
	  Dim ds As DataSet
	  If Not Session("Example_Dataset") Is Nothing Then
	      ds = New DataSet("Examples")
	      ds = CType(Session("Example_Dataset"), DataSet)
	  Else
	      ds = New DataSet("Examples")
	      ds.Tables(0).Columns.Add("FieldName", GetType(System.String))
	      ds.Tables(0).Columns.Add("FieldValue", GetType(System.String))
	  End If
	  Return ds
        End Get
        Set(ByVal value As DataSet)
	  Session("Example_Dataset") = CType(value, DataSet)
        End Set
    End Property
    Private Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
        Page.Validate()
        If (Page.IsValid) Then
	  Example()
        Else
	  Update_Message("Message - Sorry, Capcha is invalid!")
        End If
    End Sub
    Public Sub Example()
        Me.form1.Target = "_self"
        ' DECLARE FDFApp & FDFDoc Classes
        Dim cFDFApp As New FDFApp.FDFApp_Class
        Dim cFDFDoc As New FDFApp.FDFDoc_Class
        If Not String.IsNullOrEmpty(frmPDFURL.Text & "") Then
			cFDFDoc = cFDFApp.PDFOpenFromURL(frmPDFURL.Text & "", True, True, "")
        ElseIf PDFUpload1.HasFile Then
            cFDFDoc = cFDFApp.PDFOpenFromBuf(PDFUpload1.FileBytes, True, False, "")
		Else
			Update_Message("Please select a PDF file url or upload a PDF.")
			Examples_Selection.DataSource = Nothing
			Examples_Selection.DataBind()
			Exit Sub
		End If
        ' CREATE Examples DATASET
        Dim ds As New DataSet
        ds = New DataSet
        Dim dt As New DataTable("Examples")
        dt.Columns.Add("FieldNumber", GetType(System.Int32))
        dt.Columns.Add("FieldName", GetType(System.String))
        dt.Columns.Add("FieldValue", GetType(System.String))
        ds.Tables.Add(dt)
        Dim dr As DataRow, fldNumber As Integer = 0

        If cFDFDoc.FDFFieldCount >= 1 Then
	  ' LOOP THROUGH EACH FIELD/FIELD VALUE
	  For Each fld In cFDFDoc.FDFGetFields
	      dr = ds.Tables(0).NewRow
	      fldNumber += 1
	      dr("FieldNumber") = fldNumber + 0
	      If CStr(fld.FieldName & "").Length > 30 Then
                    dr("FieldName") = StripCodeFromString(CStr(fld.FieldName).Substring(0, 29)) & ".."
	      Else
                    dr("FieldName") = StripCodeFromString(fld.FieldName & "")
	      End If

                If fld.FieldValue.Count > 0 Then
                    If CStr(fld.FieldValue(0).Length & "").Length > 30 Then
                        dr("FieldValue") = StripCodeFromString(CStr(fld.FieldValue(0)).Substring(0, 29)) & ".."
                    Else
                        dr("FieldValue") = StripCodeFromString(fld.FieldValue(0) & "")
                    End If
                End If
	      ds.Tables(0).Rows.Add(dr)
	  Next
	  Examples_Dataset = ds
	  ' UPDATE GRIDVIEW
	  Load_Examples_GridView(Examples_Selection, False)
        Else
	  ' UPDATE GRIDVIEW
	  Examples_Selection.DataSource = Nothing
	  Examples_Selection.DataBind()
        End If
        Exit Sub
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        PDFUpload1.CssClass = "file"
        _example_dataset_datasource = "Example_Dataset"
        Me.SubmitButton.Text = "Submit"
        Me.SubmitButton.Enabled = True
        Me.SubmitButton.CssClass = "button button-250 bgRed white"
        Me.ResetButton.CssClass = "button button-250 bgRed white"
        Me.ResetButton.Text = "Reset"
        If Not IsPostBack Then
            Me.SubmitButton.Enabled = True
            Me.SubmitButton.CssClass = "button button-250 bgRed white"
        End If
        Update_Message("Complete this form, and then press submit.")
    End Sub
    Private Sub Update_Message(ByVal strMsg As String)
        Me.lblMessage_Top.Text = "Status: " & strMsg
        Me.lblMessage_Bottom.Text = "Status: " & strMsg
    End Sub
    Private Sub ResetButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ResetButton.Click
        Me.form1.Target = "_self"
        Me.SubmitButton.Enabled = True
        Me.SubmitButton.CssClass = "button button-250 bgRed white"
        Example()
    End Sub

    

End Class