Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
4791 lines (4778 sloc) 268 KB
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Web
Imports System.Diagnostics.Process
Imports System.Data.OleDb
Imports System.Data
Imports System.Xml
Imports System.Text.Encoder
Imports System.Security
Imports System.Security.Permissions
Namespace FDFApp
Public Class FDFApp_Class
Implements IDisposable
Private FDFDox As New FDFDoc_Class
Private _FDFErrors As New FDFErrors
Private _FDFMIME As String = "application/vnd.fdf"
Private _PDFMIME As String = "application/pdf"
Private _HTMMIME As String = "text/html"
Private _TXTMIME As String = "text/plain"
Private _XMLMIME As String = "text/xml"
Private _XFDFMIME As String = "application/vnd.adobe.xfdf"
Private _XDPMIME As String = "application/vnd.adobe.xdp+xml"
Private _defaultEncoding As Encoding = Encoding.UTF8
Public Property ThrowErrors() As Boolean
Get
Return _FDFErrors.ThrowErrors
End Get
Set(ByVal value As Boolean)
_FDFErrors.ThrowErrors = value
End Set
End Property
Public Enum FieldType
FldTextual = 1
FldMultiSelect = 3
FldOption = 5
End Enum
Public Enum FDFType
FDF = 1
xFDF = 2
XML = 3
PDF = 4
XDP = 5
XPDF = 6
XFA = 10
End Enum
Private Property FDFErrors() As FDFErrors
Get
Return _FDFErrors
End Get
Set(ByVal Value As FDFErrors)
_FDFErrors = Value
End Set
End Property
Public Function FDFHasErrors() As Boolean
Return _FDFErrors.FDFHasErrors
End Function
''' <summary>
''' MimeTxt is the string variable representing the TEXT MIME Type for Response.ContentType objects
''' </summary>
''' <value></value>
''' <returns>text/plain</returns>
''' <remarks></remarks>
Public ReadOnly Property MimeTXT() As String
Get
Return _TXTMIME
End Get
End Property
''' <summary>
''' MimeXDP is the string variable representing the XDP Mime Type for Response.ContentType objects
''' </summary>
''' <value></value>
''' <returns>application/vnd.adobe.xdp+xml</returns>
''' <remarks></remarks>
Public ReadOnly Property MimeXDP() As String
Get
Return _XDPMIME
End Get
End Property
''' <summary>
''' MimeHTML is the string variable representing the HTML MIME Type for Response.ContentType objects
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property MimeHTML() As String
Get
Return _HTMMIME
End Get
End Property
''' <summary>
''' MimeXML is the string variable representing the XML MIME Type for Response.ContentType objects
''' </summary>
''' <value></value>
''' <returns>text/xml</returns>
''' <remarks></remarks>
Public ReadOnly Property MimeXML() As String
Get
Return _XMLMIME
End Get
End Property
''' <summary>
''' MimeFDF is the string variable representing the FDF MIME Type for Response.ContentType objects
''' </summary>
''' <value></value>
''' <returns>application/vnd.fdf</returns>
''' <remarks></remarks>
Public ReadOnly Property MimeFDF() As String
Get
Return _FDFMIME
End Get
End Property
''' <summary>
''' MimeXFDF is the string variable representing the XFDF MIME Type for Response.ContentType objects
''' </summary>
''' <value></value>
''' <returns>application/vnd.adobe.xfdf</returns>
''' <remarks></remarks>
Public ReadOnly Property MimeXFDF() As String
Get
Return _XFDFMIME
End Get
End Property
''' <summary>
''' MimePDF is the string variable representing the PDF MIME Type for Response.ContentType objects
''' </summary>
''' <value></value>
''' <returns>application/pdf</returns>
''' <remarks></remarks>
Public ReadOnly Property MimePDF() As String
Get
Return _PDFMIME
End Get
End Property
''' <summary>
''' ResetErrors resets all errors in FDFApp.FDFApp_Class object
''' </summary>
''' <remarks></remarks>
Public Sub ResetErrors()
_FDFErrors.ResetErrors()
End Sub
''' <summary>
''' FDFAppErrors() Returns an array of FDFError objects
''' </summary>
''' <value></value>
''' <returns>FDFAppError Object Array</returns>
''' <remarks></remarks>
Public Property FDFAppErrors() As FDFErrors
Get
Return _FDFErrors
End Get
Set(ByVal Value As FDFErrors)
_FDFErrors = Value
End Set
End Property
''' <summary>
''' FDFAppErrorStr returns FDFAppErrors in string format, Optional HTML Format
''' </summary>
''' <param name="HTMLFormat">Set to true to return with HTML line breaks</param>
''' <returns>String with FDFAppError Array content</returns>
''' <remarks></remarks>
Public Function FDFAppErrorsStr(Optional ByVal HTMLFormat As Boolean = False) As String
Dim FDFErrors As FDFErrors
Dim FDFError As FDFErrors.FDFError
FDFErrors = _FDFErrors
Dim retString As String
retString = CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & "FDFApp Errors:"
If FDFErrors.FDFErrors Is Nothing Then Return ""
If FDFErrors.FDFErrors.Length <= 0 Then Return ""
For Each FDFError In FDFErrors.FDFErrors
retString = retString & CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & vbTab & "Error: " & FDFError.FDFError_Code & " - " & FDFError.FDFError & CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & vbTab & "#: " & FDFError.FDFError_Number & CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & vbTab & "Module: " & FDFError.FDFError_Module & CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & vbTab & "Message: " & FDFError.FDFError_Msg & CStr(IIf(HTMLFormat, "<br>", vbNewLine))
Next
Return retString
End Function
''' <summary>
''' Determines what format the data is in.
''' </summary>
''' <param name="PDFData">PDF Data (String) or PDF URL ir PDF Local File Path</param>
''' <returns>FDFType (XML/xFDF/XDP/PDF=Acrobat/XPDF=LiveCycle)</returns>
''' <remarks>EDITED: 2011-06-27</remarks>
Public Function Determine_Type(ByVal PDFData As String) As FDFType
FDFDox.DefaultEncoding = _defaultEncoding
Dim PDFData2 As String = PDFData
Dim PDFFileName As String = ""
Dim bytes() As Byte = Nothing
Try
If IsValidUrl(PDFData) Then
Dim client As New WebClient
PDFFileName = PDFData
Dim wClient As New Net.WebClient
Dim strPDF As New MemoryStream
bytes = wClient.DownloadData(PDFData)
PDFData = _defaultEncoding.GetString(bytes)
ElseIf File.Exists(PDFData) Then
PDFFileName = PDFData
Dim FS As New FileStream(PDFData, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim reader As StreamReader = New StreamReader(FS)
ReDim bytes(CInt(FS.Length))
reader.BaseStream.Read(bytes, 0, CInt(reader.BaseStream.Length))
FS.Close()
PDFData = _defaultEncoding.GetString(bytes)
End If
Catch ex As Exception
PDFData = PDFData2
End Try
If PDFData.StartsWith("%FDF") Then
Return FDFType.FDF
ElseIf PDFData.StartsWith("%PDF") Then
Try
Dim reader As iTextSharp.text.pdf.PdfReader
If Not String_IsNullOrEmpty(PDFFileName) Then
reader = New iTextSharp.text.pdf.PdfReader(PDFFileName)
Else
reader = New iTextSharp.text.pdf.PdfReader(bytes)
End If
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
reader.Close()
reader = Nothing
xfaFrm = Nothing
If isXFA Then
If FDFDox.PDFisXFADynamic(bytes) Then
Return FDFType.XFA
Else
Return FDFType.XPDF
End If
Else
Return FDFType.PDF
End If
Catch ex As Exception
Return FDFType.PDF
End Try
Return FDFType.PDF
ElseIf InStr(PDFData, "<xdp:xdp xmlns:xdp=""http://ns.adobe.com/xdp/""") > 0 Then
Return FDFType.XDP
ElseIf PDFData.StartsWith("<?xml version=""1.0""") Then
If InStrRev(PDFData, "<xfdf", -1, CompareMethod.Text) > 0 Then
Return FDFType.xFDF
Else
Return FDFType.XML
End If
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcBadFDF, "Error: Bad FDF/PDF or Unknown Data Type", "FDFApp.FDFType", 1)
End If
Return Nothing
Exit Function
End Function
''' <summary>
''' Determines what format the data is in.
''' </summary>
''' <param name="PDFData">PDF Data</param>
''' <returns>FDFType (XML/xFDF/XDP/PDF=Acrobat/XPDF=LiveCycle)</returns>
''' <remarks></remarks>
Public Function Determine_Type(ByVal PDFData As Byte()) As FDFType
Dim data As String = _defaultEncoding.GetString(PDFData)
If data.ToString.StartsWith("%FDF") Then
Return FDFType.FDF
ElseIf data.ToString.StartsWith("%PDF") Then
Try
Dim reader As New iTextSharp.text.pdf.PdfReader(PDFData)
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
reader.Close()
reader = Nothing
xfaFrm = Nothing
If isXFA Then
If FDFDox.PDFisXFADynamic(PDFData) Then
Return FDFType.XFA
Else
Return FDFType.XPDF
End If
Else
Return FDFType.PDF
End If
Catch ex As Exception
Return FDFType.PDF
End Try
Return FDFType.PDF
ElseIf InStr(data.ToString, "<xdp:xdp xmlns:xdp=""http://ns.adobe.com/xdp/""") > 0 Then
Return FDFType.XDP
ElseIf data.ToString.StartsWith("<?xml version=""1.0""") Then
If InStrRev(data.ToString, "<xfdf", -1, CompareMethod.Text) > 0 Then
Return FDFType.xFDF
Else
Return FDFType.XML
End If
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcBadFDF, "Error: Bad FDF/PDF or Unknown Data Type", "FDFApp.FDFType", 1)
Return FDFType.FDF
End If
End Function
''' <summary>
''' Determines what format the data is in.
''' </summary>
''' <param name="PDFData">PDF Data</param>
''' <param name="ownerPassword">OwnerPassword</param>
''' <returns>FDFType (XML/xFDF/XDP/PDF=Acrobat/XPDF=LiveCycle)</returns>
''' <remarks></remarks>
Public Function Determine_Type(ByVal PDFData As Byte(), ByVal ownerPassword As String) As FDFType
Dim data As String = _defaultEncoding.GetString(PDFData)
If data.ToString.StartsWith("%FDF") Then
Return FDFType.FDF
ElseIf data.ToString.StartsWith("%PDF") Then
Try
Dim reader As iTextSharp.text.pdf.PdfReader
If Not String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(PDFData, _defaultEncoding.GetBytes(ownerPassword))
Else
reader = New iTextSharp.text.pdf.PdfReader(PDFData)
End If
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
reader.Close()
reader = Nothing
xfaFrm = Nothing
If isXFA Then
If FDFDox.PDFisXFADynamic(PDFData) Then
Return FDFType.XFA
Else
Return FDFType.XPDF
End If
Else
Return FDFType.PDF
End If
Catch ex As Exception
Return FDFType.PDF
End Try
Return FDFType.PDF
ElseIf InStr(data.ToString, "<xdp:xdp xmlns:xdp=""http://ns.adobe.com/xdp/""") > 0 Then
Return FDFType.XDP
ElseIf data.ToString.StartsWith("<?xml version=""1.0""") Then
If InStrRev(data.ToString, "<xfdf", -1, CompareMethod.Text) > 0 Then
Return FDFType.xFDF
Else
Return FDFType.XML
End If
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcBadFDF, "Error: Bad FDF/PDF or Unknown Data Type", "FDFApp.FDFType", 1)
Return FDFType.FDF
End If
End Function
''' <summary>
''' Determines what format the data is in.
''' </summary>
''' <param name="PDFData">PDF Data</param>
''' <returns>FDFType (XML/xFDF/XDP/PDF=Acrobat/XPDF=LiveCycle)</returns>
''' <remarks></remarks>
Public Function Determine_Type(ByVal PDFData As Stream) As FDFType
Dim Data As String = ReadStream_New(PDFData, False)
If Data.StartsWith("%FDF") Then
Return FDFType.FDF
ElseIf Data.StartsWith("%PDF") Then
Try
Dim reader As New iTextSharp.text.pdf.PdfReader(PDFData)
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
reader.Close()
reader = Nothing
xfaFrm = Nothing
If isXFA Then
If FDFDox.PDFisXFADynamic(PDFData) Then
Return FDFType.XFA
Else
Return FDFType.XPDF
End If
Else
Return FDFType.PDF
End If
Catch ex As Exception
Return FDFType.PDF
End Try
Return FDFType.PDF
ElseIf InStr(Data, "<xdp:xdp xmlns:xdp=""http://ns.adobe.com/xdp/""") > 0 Then
Return FDFType.XDP
ElseIf Data.StartsWith("<?xml version=""1.0""") Then
If InStrRev(Data, "<xfdf", -1, CompareMethod.Text) > 0 Then
Return FDFType.xFDF
Else
Return FDFType.XML
End If
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcBadFDF, "Error: Bad FDF/PDF or Unknown Data Type", "FDFApp.FDFType", 1)
Return FDFType.FDF
End If
End Function
Public Property DefaultEncoding() As Encoding
Get
Return _defaultEncoding
End Get
Set(ByVal value As Encoding)
_defaultEncoding = value
End Set
End Property
#Region "OPEN DOCUMENT"
''' <summary>
''' FDFOpenFromStream opens an FDF Document from a Stream Object
''' </summary>
''' <param name="varFDFData">FDF Data Stream to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function FDFOpenFromStream(ByVal varFDFData As Stream, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
If varFDFData.CanSeek Then
varFDFData.Position = 0
End If
Dim bytesPDF(CInt(varFDFData.Length)) As Byte
varFDFData.Read(bytesPDF, 0, bytesPDF.Length)
Dim rawString As String = _defaultEncoding.GetString(bytesPDF)
Dim eFDFType As FDFType
eFDFType = Determine_Type(bytesPDF)
FDFDox.PDFData = bytesPDF
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(bytesPDF, FDFInitialize, AppendSaves)
Case FDFType.xFDF
FDFDox.FDFData = rawString '_defaultEncoding.GetString(FDFDox.PDFData)
Return parseXFDF(rawString, FDFInitialize)
Case FDFType.XML
FDFDox.FDFData = rawString
Return parseXML(rawString, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(bytesPDF, FDFInitialize)
Case FDFType.XPDF
Return parseXFA(bytesPDF, FDFInitialize)
Case FDFType.XDP
FDFDox.XDPData = rawString '_defaultEncoding.GetString(FDFDox.PDFData)
Return parseXDP(rawString, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromBuf", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' FDFOpenFromBuf opens an FDF Document from a Byte Array or Buffer
''' </summary>
''' <param name="varFDFData">FDF Data Byte Array to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function FDFOpenFromBuf(ByVal varFDFData() As Byte, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim FDFData As String = ReadBytes(varFDFData, False)
Dim eFDFType As FDFType
eFDFType = Determine_Type(FDFData)
Select Case eFDFType
Case FDFType.FDF
Return parseFDFi(varFDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(FDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(FDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(varFDFData, FDFInitialize)
Case FDFType.XPDF
Return parseXFA(varFDFData, FDFInitialize)
Case FDFType.XDP
FDFDox.XDPData = FDFData
Return parseXDP(FDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromBuf", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' PDFOpenFromBuf opens an PDF Document from a Byte Array or Buffer
''' </summary>
''' <param name="varPDFData">PDF Data Byte Array to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <param name="ownerPassword">Owner password for Original password protected documents</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function PDFOpenFromBuf(ByVal varPDFData() As Byte, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim FDFData As String = ReadBytes(varPDFData, False)
Dim eFDFType As FDFType
eFDFType = Determine_Type(varPDFData, ownerPassword)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(FDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(FDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(FDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(varPDFData, FDFInitialize, ownerPassword)
Case FDFType.XPDF
Return parseXFA(varPDFData, FDFInitialize, ownerPassword)
Case FDFType.XDP
FDFDox.XDPData = FDFData
Return parseXDP(FDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromBuf", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' PDFOpenFromStream opens an PDF Document from a Stream
''' </summary>
''' <param name="varPDFData">PDF Stream to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <param name="ownerPassword">Owner password for Original password protected documents</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function PDFOpenFromStream(ByVal varPDFData As Stream, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
If varPDFData.CanSeek Then
varPDFData.Position = 0
End If
ReDim FDFDox.PDFData(CInt(varPDFData.Length))
varPDFData.Read(FDFDox.PDFData, 0, CInt(varPDFData.Length))
Dim eFDFType As FDFType
eFDFType = Determine_Type(FDFDox.PDFData, ownerPassword)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(FDFDox.PDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
FDFDox.FDFData = _defaultEncoding.GetString(FDFDox.PDFData)
Return parseXFDF(FDFDox.FDFData, FDFInitialize)
Case FDFType.XML
FDFDox.FDFData = _defaultEncoding.GetString(FDFDox.PDFData)
Return parseXML(FDFDox.FDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(FDFDox.PDFData, FDFInitialize, ownerPassword)
Case FDFType.XPDF
Return parseXFA(FDFDox.PDFData, FDFInitialize, ownerPassword)
Case FDFType.XDP
FDFDox.XDPData = _defaultEncoding.GetString(FDFDox.PDFData)
Return parseXDP(FDFDox.XDPData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromBuf", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' FDFOpenFromStr opens an FDF Document from a String variable
''' </summary>
''' <param name="bstrFDFData">FDF Data String to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function FDFOpenFromStr(ByVal bstrFDFData As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
Dim FDFData As String = bstrFDFData
Dim eFDFType As FDFType
FDFDox.DefaultEncoding = _defaultEncoding
eFDFType = Determine_Type(FDFData)
Select Case eFDFType
Case FDFType.FDF
Return parseFDFi(_defaultEncoding.GetBytes(FDFData), FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(FDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(FDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(_defaultEncoding.GetBytes(FDFData), FDFInitialize)
Case FDFType.XPDF
Return parseXFA(_defaultEncoding.GetBytes(FDFData), FDFInitialize)
Case FDFType.XDP
FDFDox.XDPData = FDFData
Return parseXDP(FDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromStr", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' FDFOpenFromFile opens an FDF Document from a File Location or URL
''' </summary>
''' <param name="bstrFileName">FDF Data File or URL to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function FDFOpenFromFile(ByVal bstrFileName As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim FDFData As String
Dim bytes() As Byte = Nothing
If IsValidUrl(bstrFileName) Then
Dim client As New WebClient
bytes = GetUsedBytesOnly(client.DownloadData(bstrFileName))
FDFData = _defaultEncoding.GetString(bytes)
ElseIf File.Exists(bstrFileName) Then
Dim input As New StreamReader(bstrFileName, _defaultEncoding)
FDFData = input.ReadToEnd
bytes = _defaultEncoding.GetBytes(FDFData)
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File Does Not Exist", "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End If
FDFDox.DefaultEncoding = _defaultEncoding
Dim eFDFType As FDFType
eFDFType = Determine_Type(FDFData)
Select Case eFDFType
Case FDFType.FDF
Return parseFDFi(bytes, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(FDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(FDFData, bstrFileName, FDFInitialize)
Case FDFType.PDF
Return parsePDF(bytes, FDFInitialize)
Case FDFType.XPDF
Return parseXFA(bytes, FDFInitialize)
Case FDFType.XDP
FDFDox.XDPData = FDFData
Return parseXDP(FDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End Try
End Function
#Region "Edited 2010-09-28"
''' <summary>
''' FDFOpenFromStream opens an FDF Document from a Stream Object
''' </summary>
''' <param name="varFDFData">FDF Data Stream to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function FDFOpen(ByVal varFDFData As Stream, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
If varFDFData.CanSeek Then
varFDFData.Position = 0
End If
ReDim FDFDox.PDFData(CInt(varFDFData.Length))
varFDFData.Read(FDFDox.PDFData, 0, CInt(varFDFData.Length))
Dim eFDFType As FDFType
eFDFType = Determine_Type(FDFDox.PDFData)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(FDFDox.PDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
FDFDox.FDFData = _defaultEncoding.GetString(FDFDox.PDFData)
Return parseXFDF(FDFDox.FDFData, FDFInitialize)
Case FDFType.XML
FDFDox.FDFData = _defaultEncoding.GetString(FDFDox.PDFData)
Return parseXML(FDFDox.FDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(FDFDox.PDFData, FDFInitialize)
Case FDFType.XPDF
Return parseXFA(FDFDox.PDFData, FDFInitialize)
Case FDFType.XDP
FDFDox.XDPData = _defaultEncoding.GetString(FDFDox.PDFData)
Return parseXDP(FDFDox.XDPData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromBuf", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' FDFOpenFromBuf opens an FDF Document from a Byte Array or Buffer
''' </summary>
''' <param name="varFDFData">FDF Data Byte Array to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function FDFOpen(ByVal varFDFData() As Byte, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim FDFData As String = ReadBytes(varFDFData, False)
Dim eFDFType As FDFType
eFDFType = Determine_Type(FDFData)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(FDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(FDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(FDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(varFDFData, FDFInitialize)
Case FDFType.XPDF
Return parseXFA(varFDFData, FDFInitialize)
Case FDFType.XDP
FDFDox.XDPData = FDFData
Return parseXDP(FDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromBuf", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' FDFOpenFromFile opens an FDF Document from a File Location or URL
''' </summary>
''' <param name="bstrFileName">FDF Data File or URL to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function FDFOpen(ByVal bstrFileName As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim FDFData As String
Dim bytes() As Byte = Nothing
If IsValidUrl(bstrFileName) Then
Dim client As New WebClient
bytes = GetUsedBytesOnly(client.DownloadData(bstrFileName))
FDFData = _defaultEncoding.GetString(bytes)
ElseIf File.Exists(bstrFileName) Then
Dim input As New StreamReader(bstrFileName, _defaultEncoding)
FDFData = input.ReadToEnd
bytes = _defaultEncoding.GetBytes(FDFData)
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File Does Not Exist", "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End If
FDFDox.DefaultEncoding = _defaultEncoding
Dim eFDFType As FDFType
eFDFType = Determine_Type(FDFData)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(FDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(FDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(FDFData, bstrFileName, FDFInitialize)
Case FDFType.PDF
Return parsePDF(bytes, FDFInitialize)
Case FDFType.XPDF
Return parseXFA(bytes, FDFInitialize)
Case FDFType.XDP
FDFDox.XDPData = FDFData
Return parseXDP(FDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End Try
End Function
#End Region
''' <summary>
''' OPEN FILE WITH iText
''' </summary>
''' <param name="strFilePathOrURL">FDF URL, or Path String</param>
''' <param name="FDFInitialize">Intialize FDFDoc</param>
''' <param name="AppendSaves"></param>
''' <returns>FDFDoc</returns>
''' <remarks></remarks>
Public Function FDFOpenFromFileiText(ByVal strFilePathOrURL As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
Try
Select Case Determine_Type(strFilePathOrURL)
Case FDFType.FDF
Return parseFDFiB(_defaultEncoding.GetString(GetUsedBytesOnly(strFilePathOrURL)), True, True)
Case FDFType.XDP
Return parseXDP(_defaultEncoding.GetString(GetUsedBytesOnly(strFilePathOrURL)), True)
Case FDFType.XML
Return parseXML(_defaultEncoding.GetString(GetUsedBytesOnly(strFilePathOrURL)), True)
Case FDFType.xFDF
Return parseXFDF(_defaultEncoding.GetString(GetUsedBytesOnly(strFilePathOrURL)), True)
Case FDFType.PDF, FDFType.XPDF
Return parsePDF((GetUsedBytesOnly(strFilePathOrURL)), True, "")
Case FDFType.XFA
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File (XFA-Dynamic) not supported.", "FDFApp.FDFOpenFromFileiText", 1)
Return Nothing
Exit Function
Case Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File not supported.", "FDFApp.FDFOpenFromFileiText", 1)
Return Nothing
Exit Function
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromFileiText", 1)
Return Nothing
Exit Function
End Try
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromFileiText", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' Parse FDF with iText
''' </summary>
''' <param name="strUrl">String URL or Path of FDF</param>
''' <param name="FDFInitialize">Initialize FDFDoc</param>
''' <param name="AppendSaves"></param>
''' <returns>FDFDoc</returns>
''' <remarks></remarks>
Public Function FDFOpenWithiText(ByVal strUrl As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
Select Case Determine_Type(strUrl)
Case FDFType.FDF
Return parseFDFiB(_defaultEncoding.GetString(GetUsedBytesOnly(strUrl)), True, True)
Case FDFType.XDP
Return parseXDP(_defaultEncoding.GetString(GetUsedBytesOnly(strUrl)), True)
Case FDFType.XML
Return parseXML(_defaultEncoding.GetString(GetUsedBytesOnly(strUrl)), True)
Case FDFType.xFDF
Return parseXFDF(_defaultEncoding.GetString(GetUsedBytesOnly(strUrl)), True)
Case FDFType.PDF, FDFType.XPDF
Return parsePDF((GetUsedBytesOnly(strUrl)), True, "")
Case FDFType.XFA
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File (XFA-Dynamic) not supported.", "FDFApp.FDFOpenWithiText", 1)
Return Nothing
Exit Function
Case Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File not supported.", "FDFApp.FDFOpenWithiText", 1)
Return Nothing
Exit Function
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End Try
End Function
Public Function FDFOpenWithiText(ByVal strData() As Byte, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
If strData.Length > 0 Then
Select Case Determine_Type(strData)
Case FDFType.FDF
Return parseFDFiB(_defaultEncoding.GetString(strData), True, True)
Case FDFType.XDP
Return parseXDP(_defaultEncoding.GetString(strData), True)
Case FDFType.XML
Return parseXML(_defaultEncoding.GetString(strData), True)
Case FDFType.xFDF
Return parseXFDF(_defaultEncoding.GetString(strData), True)
Case FDFType.PDF, FDFType.XPDF
Return parsePDF(strData, True, "")
Case FDFType.XFA
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File (XFA-Dynamic) not supported.", "FDFApp.FDFOpenWithiText", 1)
Return Nothing
Exit Function
Case Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File not supported.", "FDFApp.FDFOpenWithiText", 1)
Return Nothing
Exit Function
End Select
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File Does Not Exist", "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End If
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End Try
End Function
Public Function FDFOpenWithiText(ByVal strData As Stream, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
If strData.Length > 0 Then
If strData.CanSeek Then
strData.Position = 0
End If
Select Case Determine_Type(strData)
Case FDFType.FDF
Return parseFDFiB(_defaultEncoding.GetString(GetUsedBytesOnly(strData)), True, True)
Case FDFType.XDP
Return parseXDP(_defaultEncoding.GetString(GetUsedBytesOnly(strData)), True)
Case FDFType.XML
Return parseXML(_defaultEncoding.GetString(GetUsedBytesOnly(strData)), True)
Case FDFType.xFDF
Return parseXFDF(_defaultEncoding.GetString(GetUsedBytesOnly(strData)), True)
Case FDFType.PDF, FDFType.XPDF
Return parsePDF(strData, True, "")
Case FDFType.XFA
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File (XFA-Dynamic) not supported.", "FDFApp.FDFOpenWithiText", 1)
Return Nothing
Exit Function
Case Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File not supported.", "FDFApp.FDFOpenWithiText", 1)
Return Nothing
Exit Function
End Select
Return Nothing
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File Does Not Exist", "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End If
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' FDFOpenFromURL opens an FDF Document from a URL
''' </summary>
''' <param name="FDFURL">FDF Document URL to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function FDFOpenFromURL(ByVal FDFURL As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim client As New WebClient
Dim bytes() As Byte = client.DownloadData(FDFURL)
Dim FDFData As String = _defaultEncoding.GetString(bytes)
Dim eFDFType As FDFType
eFDFType = Determine_Type(bytes)
Select Case eFDFType
Case FDFType.FDF
Return parseFDFi(bytes, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(FDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(FDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(bytes, FDFInitialize)
Case FDFType.XPDF
Return parseXFA(bytes, FDFInitialize)
Case FDFType.XDP
FDFDox.XDPData = FDFData
Return parseXDP(FDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromURL", 1)
Return Nothing
Exit Function
End Try
End Function
#Region "Edited 2010-09-28"
''' <summary>
''' PDFOpenFromBuf opens an PDF Document from a Byte Array or Buffer
''' </summary>
''' <param name="varPDFData">PDF Data Byte Array to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <param name="ownerPassword">Owner password for Original password protected documents</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function PDFOpen(ByVal varPDFData() As Byte, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim FDFData As String = ReadBytes(varPDFData, False)
Dim eFDFType As FDFType
eFDFType = Determine_Type(varPDFData, ownerPassword)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(FDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(FDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(FDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(varPDFData, FDFInitialize, ownerPassword)
Case FDFType.XPDF
Return parseXFA(varPDFData, FDFInitialize, ownerPassword)
Case FDFType.XDP
FDFDox.XDPData = FDFData
Return parseXDP(FDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromBuf", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' PDFOpenFromStream opens an PDF Document from a Stream
''' </summary>
''' <param name="varPDFData">PDF Stream to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <param name="ownerPassword">Owner password for Original password protected documents</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function PDFOpen(ByVal varPDFData As Stream, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
If varPDFData.CanSeek Then
varPDFData.Position = 0
End If
ReDim FDFDox.PDFData(CInt(varPDFData.Length))
varPDFData.Read(FDFDox.PDFData, 0, CInt(varPDFData.Length))
Dim eFDFType As FDFType
eFDFType = Determine_Type(FDFDox.PDFData, ownerPassword)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(FDFDox.PDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
FDFDox.FDFData = _defaultEncoding.GetString(FDFDox.PDFData)
Return parseXFDF(FDFDox.FDFData, FDFInitialize)
Case FDFType.XML
FDFDox.FDFData = _defaultEncoding.GetString(FDFDox.PDFData)
Return parseXML(FDFDox.FDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(FDFDox.PDFData, FDFInitialize, ownerPassword)
Case FDFType.XPDF
Return parseXFA(FDFDox.PDFData, FDFInitialize, ownerPassword)
Case FDFType.XDP
FDFDox.XDPData = _defaultEncoding.GetString(FDFDox.PDFData)
Return parseXDP(FDFDox.XDPData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromBuf", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' PDFOpenFromFile opens an PDF Document from a File Location or URL
''' </summary>
''' <param name="bstrFileName">PDF Data File or URL to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <param name="ownerPassword">Owner password for Original password protected documents</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function PDFOpen(ByVal bstrFileName As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim PDFFile As String
Dim PDFData As String
Dim bytes() As Byte = Nothing
If IsValidUrl(bstrFileName) Then
Dim client As New WebClient
bytes = GetUsedBytesOnly(client.DownloadData(bstrFileName))
PDFData = _defaultEncoding.GetString(bytes)
FDFDox.PDFData = bytes
ElseIf File.Exists(bstrFileName) Then
PDFFile = Me.OpenFile(bstrFileName)
Dim fInfo As New FileInfo(bstrFileName)
Dim numBytes As Long = fInfo.Length
Dim FS As New FileStream(bstrFileName, FileMode.Open, FileAccess.Read, FileShare.Read)
If FS.CanRead Then
FS.Position = 0
End If
Dim br As New BinaryReader(FS)
ReDim bytes(CInt(br.BaseStream.Length))
bytes = br.ReadBytes(CInt(br.BaseStream.Length))
PDFData = _defaultEncoding.GetString(bytes)
FDFDox.PDFData = bytes
FS.Close()
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File Does Not Exist", "FDFApp.PDFOpenFromFile", 1)
Return Nothing
Exit Function
End If
Dim eFDFType As FDFType
eFDFType = Me.Determine_Type(bytes)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(PDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(PDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(PDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(bstrFileName, FDFInitialize, ownerPassword)
Case FDFType.XPDF
Return parseXFA(bstrFileName, FDFInitialize, ownerPassword)
Case FDFType.XDP
FDFDox.XDPData = PDFData
Return parseXDP(PDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromFile", 1)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' PDFOpenFromURL opens an PDF Document from a File Location or URL
''' </summary>
''' <param name="PDFURL">PDF Data URL to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <param name="ownerPassword">Owner password for Original password protected documents</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function PDFOpen(ByVal PDFURL As System.Uri, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim PDFData As String
Dim bytes() As Byte = Nothing
If IsValidUrl(PDFURL.ToString) Then
Dim client As New WebClient
bytes = client.DownloadData(PDFURL.ToString)
PDFData = _defaultEncoding.GetString(bytes)
FDFDox.PDFData = bytes
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcFileSysErr, "Error: File Does Not Exist", "FDFApp.PDFOpenFromFile", 1)
Return Nothing
Exit Function
End If
Dim eFDFType As FDFType
eFDFType = Me.Determine_Type(bytes)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(PDFData, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(PDFData, FDFInitialize)
Case FDFType.XML
Return parseXML(PDFData, "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(bytes, FDFInitialize, ownerPassword)
Case FDFType.XPDF
Return parseXFA(bytes, FDFInitialize, ownerPassword)
Case FDFType.XDP
FDFDox.XDPData = PDFData
Return parseXDP(PDFData, FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromStr", 1)
Return Nothing
Exit Function
End Try
End Function
#End Region
''' <summary>
''' PDFOpenFromFile opens an PDF Document from a File Location or URL
''' </summary>
''' <param name="bstrFileName">PDF Data File or URL to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <param name="ownerPassword">Owner password for Original password protected documents</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function PDFOpenFromFile(ByVal bstrFileName As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim PDFFile As String
Dim PDFData As String
Dim bytes() As Byte = Nothing
If IsValidUrl(bstrFileName) Then
FDFDox.DefaultEncoding = _defaultEncoding
Dim client As New WebClient
bytes = GetUsedBytesOnly(client.DownloadData(bstrFileName))
ElseIf File.Exists(bstrFileName) Then
PDFFile = Me.OpenFile(bstrFileName)
Dim fInfo As New FileInfo(bstrFileName)
Dim numBytes As Long = fInfo.Length
Dim FS As New FileStream(bstrFileName, FileMode.Open, FileAccess.Read, FileShare.Read)
If FS.CanRead Then
FS.Position = 0
End If
Dim br As New BinaryReader(FS)
ReDim bytes(CInt(numBytes))
bytes = br.ReadBytes(CInt(numBytes))
PDFData = _defaultEncoding.GetString(bytes)
FS.Close()
Else
Throw New Exception("Error: File Does Not Exist")
Return Nothing
Exit Function
End If
Dim eFDFType As FDFType
eFDFType = Me.Determine_Type(bytes)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(_defaultEncoding.GetString(bytes), FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(_defaultEncoding.GetString(bytes), FDFInitialize)
Case FDFType.XML
Return parseXML(_defaultEncoding.GetString(bytes), "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(bstrFileName, FDFInitialize, ownerPassword)
Case FDFType.XPDF
Return parseXFA(bstrFileName, FDFInitialize, ownerPassword)
Case FDFType.XDP
FDFDox.XDPData = _defaultEncoding.GetString(bytes)
Return parseXDP(_defaultEncoding.GetString(bytes), FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, ex)
Return Nothing
Exit Function
End Try
End Function
''' <summary>
''' PDFOpenFromURL opens an PDF Document from a File Location or URL
''' </summary>
''' <param name="PDFURL">PDF Data URL to parse</param>
''' <param name="FDFInitialize">Initialize FDFDoc Object</param>
''' <param name="AppendSaves">Appends Saves</param>
''' <param name="ownerPassword">Owner password for Original password protected documents</param>
''' <returns>FDFDoc_Class</returns>
''' <remarks></remarks>
Public Function PDFOpenFromURL(ByVal PDFURL As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
Try
FDFDox.DefaultEncoding = _defaultEncoding
Dim client As New WebClient
Dim bytes() As Byte = GetUsedBytesOnly(client.DownloadData(PDFURL))
Dim eFDFType As FDFType
eFDFType = Determine_Type(bytes, ownerPassword)
Select Case eFDFType
Case FDFType.FDF
Return FDFOpenWithiText(bytes, FDFInitialize, AppendSaves)
Case FDFType.xFDF
Return parseXFDF(_defaultEncoding.GetString(bytes), FDFInitialize)
Case FDFType.XML
Return parseXML(_defaultEncoding.GetString(bytes), "", FDFInitialize)
Case FDFType.PDF
Return parsePDF(PDFURL, FDFInitialize, ownerPassword)
Case FDFType.XPDF
Return parseXFA(PDFURL, FDFInitialize, ownerPassword)
Case FDFType.XDP
FDFDox.XDPData = _defaultEncoding.GetString(bytes)
Return parseXDP(_defaultEncoding.GetString(bytes), FDFInitialize)
End Select
Return Nothing
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.FDFOpenFromStr", 1)
Return Nothing
Exit Function
End Try
End Function
Public Function GetUsedBytesOnly(ByRef b() As Byte) As Byte()
Dim bytes As Byte() = b
Dim i As Integer = 0
For i = bytes.Length - 1 To 1 Step -1
If bytes(i) <> 0 Then
Exit For
End If
Next
Dim newBytes As Byte() = New Byte(i) {}
Array.Copy(bytes, newBytes, i + 1)
ReDim bytes(0)
bytes = Nothing
Return newBytes
End Function
Public Function GetUsedBytesOnly(ByRef s As Stream) As Byte()
Dim bytes(CInt(s.Length)) As Byte
If s.CanSeek Then
s.Seek(0, SeekOrigin.Begin)
End If
s.Read(bytes, 0, bytes.Length)
Return GetUsedBytesOnly(bytes)
End Function
Public Function GetUsedBytesOnly(ByRef s As String) As Byte()
If IsValidUrl(s.ToString & "") Then
Dim w As New System.Net.WebClient()
Dim bytes() As Byte = w.DownloadData(s.ToString)
Return GetUsedBytesOnly(bytes)
ElseIf File.Exists(s & "") Then
Dim bytes() As Byte = File.ReadAllBytes(s)
Return GetUsedBytesOnly(bytes)
ElseIf Not String.IsNullOrEmpty(s & "") Then
Dim bytes() As Byte = _defaultEncoding.GetBytes(s & "")
Return GetUsedBytesOnly(bytes)
Else
Return Nothing
End If
End Function
Private Function GetUsedBytesOnly(ByRef u As Uri) As Byte()
If IsValidUrl(u.ToString) Then
Dim w As New System.Net.WebClient()
Dim bytes() As Byte = w.DownloadData(u.ToString)
Return GetUsedBytesOnly(bytes)
Else
Return Nothing
End If
End Function
#End Region
#Region "PARSING"
Private Function parseXDP(ByVal FDF As String, Optional ByVal FDFInitialize As Boolean = False) As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
Dim cCntr As Integer = -1
Dim strFDF As String = ByteArrayToString(_defaultEncoding.GetBytes(FDF))
Dim str As String = ""
Dim PDFFileName As String = ""
If Not InStr(strFDF, "<root>", CompareMethod.Text) > 0 Then
Dim sb As StringBuilder = New StringBuilder
strFDF = strFDF.Replace(Chr(10) & ">", ">")
strFDF = strFDF.Replace(Chr(10) & "/>", "/>")
strFDF = strFDF.Replace(Chr(13) & ">", ">")
strFDF = strFDF.Replace(Chr(13) & "/>", "/>")
strFDF = strFDF.Replace(Environment.NewLine & ">", ">")
strFDF = strFDF.Replace(Environment.NewLine & "/>", "/>")
Dim XMLMeta As String = strFDF.Substring(0, strFDF.IndexOf("<xfa:data>", 0) + 10)
Dim XMLMetaEnd As String = strFDF.Substring(strFDF.IndexOf("</xfa:data>", 0), strFDF.Length - strFDF.IndexOf("</xfa:data>", 0))
Dim XMLMetaFix As String = "<?xml version=""1.0"" encoding=""UTF-8""?>"
Try
Dim XMLMeteEndPDF1 As Integer = strFDF.IndexOf("<pdf ", 0)
If XMLMeteEndPDF1 >= 0 Then
Dim XMLMeteEndPDF2 As Integer = strFDF.IndexOf("/>", XMLMeteEndPDF1 + 5) + 2
Dim XMLMetaFixEnd As String = strFDF.Substring(XMLMeteEndPDF1, XMLMeteEndPDF2 - XMLMeteEndPDF1)
Dim STARTINDEXOF As Integer = XMLMetaFixEnd.IndexOf("href=""", 0) + 6
Dim ENDINDEXOF As Integer = XMLMetaFixEnd.IndexOf("""", STARTINDEXOF + 7) + 1
PDFFileName = XMLMetaFixEnd.Substring(STARTINDEXOF, ENDINDEXOF - STARTINDEXOF)
PDFFileName = PDFFileName.TrimStart(""""c)
PDFFileName = PDFFileName.TrimEnd(""""c)
If Not PDFFileName.Length = 0 Then
FDFDox.FDFSetFile(PDFFileName)
End If
End If
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, ex)
Err.Clear()
End Try
strFDF = strFDF.Replace(XMLMeta, "")
strFDF = strFDF.Replace(XMLMetaEnd, "")
sb.Append(XMLMetaFix)
sb.Append("<root>")
strFDF = strFDF.Replace("xfa:contentType", "contenttype")
strFDF = strFDF.Replace("xfa:", "")
sb.Append(strFDF)
sb.Append("</root>")
strFDF = sb.ToString
End If
Return parseXML(strFDF, False)
Return FDFDox
End Function
Private Function parseXFA(ByVal FileNameorURL As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
Dim reader As iTextSharp.text.pdf.PdfReader
If String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(FileNameorURL)
Else
reader = New iTextSharp.text.pdf.PdfReader(FileNameorURL, _defaultEncoding.GetBytes(ownerPassword))
End If
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
If Not isXFA Then
reader.Close()
reader = Nothing
xfaFrm = Nothing
Return parsePDF(FileNameorURL, FDFInitialize)
Exit Function
End If
Dim xmlData() As Byte = GetXFAXML(FileNameorURL)
FDFDox = parseXDP(_defaultEncoding.GetString(xmlData), True)
FDFDox.FDFSetFile(FileNameorURL)
For Each fld As FDFApp.FDFDoc_Class.FDFField In FDFDox.XDPGetAllFields()
Select Case reader.AcroFields.GetFieldType(fld.FieldName)
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_TEXT
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldTextual
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_LIST
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldMultiSelect
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_CHECKBOX
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldTextual
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_COMBO
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldTextual
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_RADIOBUTTON
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldOption
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_PUSHBUTTON
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldButton
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_SIGNATURE
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_NONE
Case Else
End Select
Next
ContinueProcess:
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
FDFDox.XDPData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.XDP, True)
FDFDox.FDFSetFile(FileNameorURL)
reader.Close()
reader = Nothing
xfaFrm = Nothing
Return FDFDox
End Function
Public Function GetXFAXML(ByVal PDFBuffer As Byte(), Optional ByVal ownerPassword As String = "") As Byte()
Dim outputStream As New System.IO.MemoryStream()
Dim reader As iTextSharp.text.pdf.PdfReader
If String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(PDFBuffer)
Else
reader = New iTextSharp.text.pdf.PdfReader(PDFBuffer, _defaultEncoding.GetBytes(ownerPassword))
End If
Dim settings As System.Xml.XmlWriterSettings = New System.Xml.XmlWriterSettings
settings.Indent = True
Using writer As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(outputStream, settings)
reader.AcroFields.Xfa.DatasetsNode.WriteTo(writer)
End Using
If outputStream.CanSeek Then
outputStream.Seek(0, SeekOrigin.Begin)
End If
Return outputStream.ToArray()
End Function
Public Function GetXFAXML(ByVal PDFPath As String, Optional ByVal ownerPassword As String = "") As Byte()
Dim outputStream As New System.IO.MemoryStream()
Dim reader As iTextSharp.text.pdf.PdfReader
If String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(PDFPath)
Else
reader = New iTextSharp.text.pdf.PdfReader(PDFPath, _defaultEncoding.GetBytes(ownerPassword))
End If
Dim settings As System.Xml.XmlWriterSettings = New System.Xml.XmlWriterSettings
settings.Indent = True
Using writer As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(outputStream, settings)
reader.AcroFields.Xfa.DatasetsNode.WriteTo(writer)
End Using
If outputStream.CanSeek Then
outputStream.Seek(0, SeekOrigin.Begin)
End If
Return outputStream.ToArray()
End Function
Public Function GetXFAXML(ByVal PDFStream As Stream, Optional ByVal ownerPassword As String = "") As Byte()
Dim outputStream As New System.IO.MemoryStream()
If PDFStream.CanSeek Then
PDFStream.Seek(0, SeekOrigin.Begin)
End If
Dim reader As iTextSharp.text.pdf.PdfReader
If String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(PDFStream)
Else
reader = New iTextSharp.text.pdf.PdfReader(PDFStream, _defaultEncoding.GetBytes(ownerPassword))
End If
Dim settings As System.Xml.XmlWriterSettings = New System.Xml.XmlWriterSettings
settings.Indent = True
Using writer As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(outputStream, settings)
reader.AcroFields.Xfa.DatasetsNode.WriteTo(writer)
End Using
If outputStream.CanSeek Then
outputStream.Seek(0, SeekOrigin.Begin)
End If
Return outputStream.ToArray()
End Function
Private Function parseXFA(ByVal PDFBuffer As Byte(), Optional ByVal FDFInitialize As Boolean = False, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
Dim reader As iTextSharp.text.pdf.PdfReader
If String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(PDFBuffer)
Else
reader = New iTextSharp.text.pdf.PdfReader(PDFBuffer, _defaultEncoding.GetBytes(ownerPassword))
End If
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
If Not isXFA Then
reader.Close()
reader = Nothing
xfaFrm = Nothing
Return parsePDF(PDFBuffer, FDFInitialize)
Exit Function
End If
Dim xmlData() As Byte = GetXFAXML(PDFBuffer)
FDFDox = parseXDP(_defaultEncoding.GetString(xmlData), True)
For Each fld As FDFApp.FDFDoc_Class.FDFField In FDFDox.XDPGetAllFields()
Select Case reader.AcroFields.GetFieldType(fld.FieldName)
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_TEXT
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldTextual
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_LIST
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldMultiSelect
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_CHECKBOX
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldTextual
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_COMBO
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldTextual
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_PUSHBUTTON
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldButton
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_SIGNATURE
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_NONE
Case Else
End Select
Next
ContinueProcess:
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
FDFDox.XDPData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.XDP, True)
reader.Close()
reader = Nothing
xfaFrm = Nothing
Return FDFDox
End Function
Private Function parseXFA(ByVal PDFStream As Stream, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
Dim reader As iTextSharp.text.pdf.PdfReader
If String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(PDFStream)
Else
reader = New iTextSharp.text.pdf.PdfReader(PDFStream, _defaultEncoding.GetBytes(ownerPassword))
End If
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
If Not isXFA Then
reader.Close()
reader = Nothing
xfaFrm = Nothing
Return parsePDF(PDFStream, FDFInitialize)
Exit Function
End If
Dim xmlData() As Byte = GetXFAXML(PDFStream)
FDFDox = parseXDP(_defaultEncoding.GetString(xmlData), True)
For Each fld As FDFApp.FDFDoc_Class.FDFField In FDFDox.XDPGetAllFields()
Select Case reader.AcroFields.GetFieldType(fld.FieldName)
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_TEXT
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldTextual
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_LIST
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldMultiSelect
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_CHECKBOX
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldTextual
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_COMBO
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldTextual
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_PUSHBUTTON
FDFDox.XDPGetField(fld.FieldLevelLong).FieldType = FDFDoc_Class.FieldType.FldButton
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_SIGNATURE
Case iTextSharp.text.pdf.AcroFields.FIELD_TYPE_NONE
Case Else
End Select
Next
ContinueProcess:
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
FDFDox.XDPData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.XDP, True)
reader.Close()
reader = Nothing
xfaFrm = Nothing
Return FDFDox
End Function
Private Function parseFDFiB(ByVal FDF As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
FDFDox.FDFData = FDF
Dim reader As iTextSharp.text.pdf.FdfReader
reader = New iTextSharp.text.pdf.FdfReader(Me.StringToByteArray(FDF))
Dim fld As String
Dim vals As New iTextSharp.text.pdf.PdfDictionary
Dim form As iTextSharp.text.pdf.AcroFields
form = reader.AcroFields
Dim fspec As String = reader.FileSpec
Try
For Each fld In reader.Fields.Keys
Dim fieldName As String
fieldName = fld
Dim val As String = reader.GetFieldValue(fld.ToString)
Dim FldType As String = ""
val = reader.GetFieldValue(fieldName) & ""
Try
Dim arrVals As New System.Collections.Generic.List(Of String)
Dim arrDisplay As New System.Collections.Generic.List(Of String)
Dim arrExports As New System.Collections.Generic.List(Of String)
If DirectCast(reader.GetField(fld), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.V).IsArray Then
Try
If Not DirectCast(reader.GetField(fld), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.V) Is Nothing Then
Dim arV As iTextSharp.text.pdf.PdfArray = DirectCast(reader.GetField(fld), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.V)
For x123 As Integer = 0 To arV.Size - 1
Try
If Not arV.GetAsString(x123) Is Nothing Then
Dim strTemp As String = arV.GetAsString(x123).ToUnicodeString() & ""
If Not arrVals.Contains(strTemp) Then
arrVals.Add(strTemp)
End If
End If
Catch ex2 As Exception
Err.Clear()
End Try
Next
End If
Catch ex As Exception
Err.Clear()
End Try
Try
If DirectCast(reader.GetField(fld), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.OPT).IsArray Then
Dim arOpt As iTextSharp.text.pdf.PdfArray = DirectCast(reader.GetField(fld), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.OPT)
For x123 As Integer = 0 To arOpt.Size - 1
Try
If Not arOpt.GetAsArray(x123) Is Nothing Then
If arOpt.GetAsArray(x123).Size >= 2 Then
Dim strTempExport As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrExports.Contains(strTempExport) Then
arrExports.Add(strTempExport)
End If
Dim strTempDisplay As String = arOpt.GetAsArray(x123).GetAsString(1).ToUnicodeString() & ""
If Not arrDisplay.Contains(strTempDisplay) Then
arrDisplay.Add(strTempDisplay)
End If
Else
Dim strTempExport As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrExports.Contains(strTempExport) Then
arrExports.Add(strTempExport)
End If
Dim strTempDisplay As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrDisplay.Contains(strTempDisplay) Then
arrDisplay.Add(strTempDisplay)
End If
End If
End If
Catch ex2 As Exception
Err.Clear()
End Try
Next
FDFDox.FDFAddField(fieldName & "", arrVals.ToArray, arrDisplay.ToArray, arrExports.ToArray, FDFDoc_Class.FieldType.FldMultiSelect, True, True)
Else
If arrVals.Count > 0 Then
FDFDox.FDFAddField(fieldName & "", arrVals.ToArray, FDFDoc_Class.FieldType.FldMultiSelect, True, True)
Else
FDFDox.FDFAddField(fieldName & "", val & "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
End If
Catch ex As Exception
Err.Clear()
End Try
Else
FDFDox.FDFAddField(fieldName & "", val & "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
Catch ex As Exception
FDFDox.FDFAddField(fieldName & "", val & "", FDFDoc_Class.FieldType.FldTextual, True, True)
Err.Clear()
End Try
Next
FDFDox.FDFSetFile(reader.FileSpec.ToString)
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
reader.Close()
Return FDFDox
Catch ex As Exception
Try
reader.Close()
Return FDFDox
Catch ex2 As Exception
Return FDFDox
End Try
End Try
reader = Nothing
FDFDox.XDPAdjustSubforms()
Return FDFDox
End Function
Private Function parseFDFi(ByVal FDF As Byte(), Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
FDFDox.FDFData = ByteArrayToString(FDF)
Dim reader As iTextSharp.text.pdf.FdfReader
reader = New iTextSharp.text.pdf.FdfReader(FDF)
Dim fld As DictionaryEntry
Dim vals As New iTextSharp.text.pdf.PdfDictionary
Dim form As iTextSharp.text.pdf.AcroFields
form = reader.AcroFields
Dim fields As New Hashtable
fields = reader.Fields
Try
For Each fld In fields
Dim fieldName As String
fieldName = DirectCast(fld.Key, String)
Dim val() As String = New String() {} 'fld.ToString
Dim FldType As String = ""
val = reader.GetFieldValues(fieldName)
Try
Dim arrVals As New System.Collections.Generic.List(Of String)
Dim arrDisplay As New System.Collections.Generic.List(Of String)
Dim arrExports As New System.Collections.Generic.List(Of String)
If Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.V) Is Nothing Or Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.OPT) Is Nothing Then
Try
If Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.V) Is Nothing Then
Dim arV As iTextSharp.text.pdf.PdfArray = DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.V)
For x123 As Integer = 0 To arV.Size - 1
Try
Dim strTemp As String = arV.GetAsString(x123).ToUnicodeString() & ""
If Not arrVals.Contains(strTemp) Then
arrVals.Add(strTemp)
End If
Catch ex2 As Exception
Err.Clear()
End Try
Next
End If
Catch ex As Exception
Err.Clear()
End Try
Try
If Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.OPT) Is Nothing Then
If DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.OPT).IsArray Then
Dim arOpt As iTextSharp.text.pdf.PdfArray = DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.OPT)
For x123 As Integer = 0 To arOpt.Size - 1
Try
If Not arOpt.GetAsArray(x123) Is Nothing Then
If arOpt.GetAsArray(x123).Size >= 2 Then
Dim strTempExport As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrExports.Contains(strTempExport) Then
arrExports.Add(strTempExport)
End If
Dim strTempDisplay As String = arOpt.GetAsArray(x123).GetAsString(1).ToUnicodeString() & ""
If Not arrDisplay.Contains(strTempDisplay) Then
arrDisplay.Add(strTempDisplay)
End If
Else
Dim strTempExport As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrExports.Contains(strTempExport) Then
arrExports.Add(strTempExport)
End If
Dim strTempDisplay As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrDisplay.Contains(strTempDisplay) Then
arrDisplay.Add(strTempDisplay)
End If
End If
End If
Catch ex2 As Exception
Err.Clear()
End Try
Next
FDFDox.FDFAddField(fieldName & "", arrVals.ToArray, arrDisplay.ToArray, arrExports.ToArray, FDFDoc_Class.FieldType.FldMultiSelect, True, True)
Else
If arrVals.Count > 0 Then
FDFDox.FDFAddField(fieldName & "", arrVals.ToArray, FDFDoc_Class.FieldType.FldMultiSelect, True, True)
Else
FDFDox.FDFAddField(fieldName & "", val, FDFDoc_Class.FieldType.FldTextual, True, True)
End If
End If
Else
If arrVals.Count > 0 Then
FDFDox.FDFAddField(fieldName & "", arrVals.ToArray, FDFDoc_Class.FieldType.FldMultiSelect, True, True)
Else
FDFDox.FDFAddField(fieldName & "", val, FDFDoc_Class.FieldType.FldTextual, True, True)
End If
End If
Catch ex As Exception
Err.Clear()
End Try
Else
FDFDox.FDFAddField(fieldName & "", val, FDFDoc_Class.FieldType.FldTextual, True, True)
End If
Catch ex As Exception
FDFDox.FDFAddField(fieldName & "", val, FDFDoc_Class.FieldType.FldTextual, True, True)
Err.Clear()
End Try
Next
FDFDox.FDFSetFile(reader.FileSpec.ToString)
FDFDox.XDPAdjustSubforms()
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
reader.Close()
Return FDFDox
Catch ex As Exception
Try
reader.Close()
Return FDFDox
Catch ex2 As Exception
Return FDFDox
End Try
End Try
reader = Nothing
FDFDox.XDPAdjustSubforms()
Return FDFDox
End Function
Private Function FDFGetFileiText(ByVal FDFData As String) As String
Dim reader As iTextSharp.text.pdf.FdfReader
Try
reader = New iTextSharp.text.pdf.FdfReader(_defaultEncoding.GetBytes(FDFData))
Return reader.FileSpec.ToString & ""
Catch ex As Exception
Return ""
End Try
End Function
Private Function parseFDFi(ByVal FDF As Stream, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
Dim reader As iTextSharp.text.pdf.FdfReader
reader = New iTextSharp.text.pdf.FdfReader(FDF)
Dim fld As DictionaryEntry
Dim vals As New iTextSharp.text.pdf.PdfDictionary
Dim form As iTextSharp.text.pdf.AcroFields
form = reader.AcroFields
Dim fields As New Hashtable
fields = reader.Fields
Try
For Each fld In fields
Dim fieldName As String
fieldName = DirectCast(fld.Key, String)
Dim val As String = "" 'fld.ToString
Dim FldType As String = ""
val = reader.GetFieldValue(fieldName) & ""
Try
Dim arrVals As New System.Collections.Generic.List(Of String)
Dim arrDisplay As New System.Collections.Generic.List(Of String)
Dim arrExports As New System.Collections.Generic.List(Of String)
If Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.V) Is Nothing Or Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.OPT) Is Nothing Then
Try
If Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.V) Is Nothing Then
Dim arV As iTextSharp.text.pdf.PdfArray = DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.V)
For x123 As Integer = 0 To arV.Size - 1
Try
Dim strTemp As String = arV.GetAsString(x123).ToUnicodeString() & ""
If Not arrVals.Contains(strTemp) Then
arrVals.Add(strTemp)
End If
Catch ex2 As Exception
Err.Clear()
End Try
Next
End If
Catch ex As Exception
Err.Clear()
End Try
Try
If Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.OPT) Is Nothing Then
Dim arOpt As iTextSharp.text.pdf.PdfArray = DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.OPT)
For x123 As Integer = 0 To arOpt.Size - 1
Try
If Not arOpt.GetAsArray(x123) Is Nothing Then
If arOpt.GetAsArray(x123).Size >= 2 Then
Dim strTempExport As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrExports.Contains(strTempExport) Then
arrExports.Add(strTempExport)
End If
Dim strTempDisplay As String = arOpt.GetAsArray(x123).GetAsString(1).ToUnicodeString() & ""
If Not arrDisplay.Contains(strTempDisplay) Then
arrDisplay.Add(strTempDisplay)
End If
Else
Dim strTempExport As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrExports.Contains(strTempExport) Then
arrExports.Add(strTempExport)
End If
Dim strTempDisplay As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrDisplay.Contains(strTempDisplay) Then
arrDisplay.Add(strTempDisplay)
End If
End If
End If
Catch ex2 As Exception
Err.Clear()
End Try
Next
FDFDox.FDFAddField(fieldName & "", arrVals.ToArray, arrDisplay.ToArray, arrExports.ToArray, FDFDoc_Class.FieldType.FldMultiSelect, True, True)
Else
If arrVals.Count > 1 Then
FDFDox.FDFAddField(fieldName & "", arrVals.ToArray, FDFDoc_Class.FieldType.FldMultiSelect, True, True)
Else
FDFDox.FDFAddField(fieldName & "", val & "", FDFDoc_Class.FieldType.FldTextual, True, True)
'FDFDox.FDFAddField(fieldName & "", arrVals(0) & "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
End If
Catch ex As Exception
Err.Clear()
End Try
Else
FDFDox.FDFAddField(fieldName & "", val & "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
Catch ex As Exception
FDFDox.FDFAddField(fieldName & "", val & "", FDFDoc_Class.FieldType.FldTextual, True, True)
Err.Clear()
End Try
Next
FDFDox.FDFSetFile(reader.FileSpec.ToString)
FDFDox.XDPAdjustSubforms()
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
reader.Close()
Return FDFDox
Catch ex As Exception
Try
reader.Close()
Return FDFDox
Catch ex2 As Exception
Return FDFDox
End Try
End Try
reader = Nothing
FDFDox.XDPAdjustSubforms()
Return FDFDox
End Function
Private Function parseFDFi(ByVal FileNameorURL As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
Dim reader As iTextSharp.text.pdf.FdfReader
reader = New iTextSharp.text.pdf.FdfReader(FileNameorURL)
Dim fld As DictionaryEntry
Dim vals As New iTextSharp.text.pdf.PdfDictionary
Dim form As iTextSharp.text.pdf.AcroFields
form = reader.AcroFields
Dim fields As New Hashtable
fields = reader.Fields
Try
For Each fld In fields
Dim fieldName As String
fieldName = DirectCast(fld.Key, String)
Dim val As String = "" 'fld.ToString
Dim FldType As String = ""
val = reader.GetFieldValue(fieldName) & ""
Try
Dim arrVals As New System.Collections.Generic.List(Of String)
Dim arrDisplay As New System.Collections.Generic.List(Of String)
Dim arrExports As New System.Collections.Generic.List(Of String)
If Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.V) Is Nothing Or Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.OPT) Is Nothing Then
Try
If Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.V) Is Nothing Then
Dim arV As iTextSharp.text.pdf.PdfArray = DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.V)
For x123 As Integer = 0 To arV.Size - 1
Try
Dim strTemp As String = arV.GetAsString(x123).ToUnicodeString() & ""
If Not arrVals.Contains(strTemp) Then
arrVals.Add(strTemp)
End If
Catch ex2 As Exception
Err.Clear()
End Try
Next
End If
Catch ex As Exception
Err.Clear()
End Try
Try
If Not DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).Get(iTextSharp.text.pdf.PdfName.OPT) Is Nothing Then
Dim arOpt As iTextSharp.text.pdf.PdfArray = DirectCast(reader.GetField(fieldName), iTextSharp.text.pdf.PdfDictionary).GetAsArray(iTextSharp.text.pdf.PdfName.OPT)
For x123 As Integer = 0 To arOpt.Size - 1
Try
If Not arOpt.GetAsArray(x123) Is Nothing Then
If arOpt.GetAsArray(x123).Size >= 2 Then
Dim strTempExport As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrExports.Contains(strTempExport) Then
arrExports.Add(strTempExport)
End If
Dim strTempDisplay As String = arOpt.GetAsArray(x123).GetAsString(1).ToUnicodeString() & ""
If Not arrDisplay.Contains(strTempDisplay) Then
arrDisplay.Add(strTempDisplay)
End If
Else
Dim strTempExport As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrExports.Contains(strTempExport) Then
arrExports.Add(strTempExport)
End If
Dim strTempDisplay As String = arOpt.GetAsArray(x123).GetAsString(0).ToUnicodeString() & ""
If Not arrDisplay.Contains(strTempDisplay) Then
arrDisplay.Add(strTempDisplay)
End If
End If
End If
Catch ex2 As Exception
Err.Clear()
End Try
Next
FDFDox.FDFAddField(fieldName & "", arrVals.ToArray, arrDisplay.ToArray, arrExports.ToArray, FDFDoc_Class.FieldType.FldMultiSelect, True, True)
Else
If arrVals.Count > 1 Then
FDFDox.FDFAddField(fieldName & "", arrVals.ToArray, FDFDoc_Class.FieldType.FldMultiSelect, True, True)
Else
FDFDox.FDFAddField(fieldName & "", val & "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
End If
Catch ex As Exception
Err.Clear()
End Try
Else
FDFDox.FDFAddField(fieldName & "", val & "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
Catch ex As Exception
FDFDox.FDFAddField(fieldName & "", val & "", FDFDoc_Class.FieldType.FldTextual, True, True)
Err.Clear()
End Try
Next
FDFDox.FDFSetFile(reader.FileSpec.ToString)
FDFDox.XDPAdjustSubforms()
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
reader.Close()
Return FDFDox
Catch ex As Exception
Try
reader.Close()
Return FDFDox
Catch ex2 As Exception
Return FDFDox
End Try
End Try
reader = Nothing
FDFDox.XDPAdjustSubforms()
Return FDFDox
End Function
Private Function parseFDF(ByVal FDF As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal AppendSaves As Boolean = True) As FDFDoc_Class
Dim tmpFDF As String = FDF
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
Try
If Has_Kids(0, FDF.Length - 1, FDF) Then
Return parseFDFiB(FDF, FDFInitialize, AppendSaves)
Exit Function
End If
FDF = ByteArrayToString(_defaultEncoding.GetBytes(FDF))
Dim strFields(4) As String
Dim FldStart As Integer, FldEnd As Integer
Dim intField(7) As Integer
FldStart = FDF.ToLower.IndexOf("/fields")
If FDF.IndexOf("[", FldStart + 7, 2) > 0 Then
FldStart = FldStart + 1
FldEnd = FDF.ToLower.IndexOf("endobj", FldStart + 8)
Else
Dim strFieldsObject_Start As String
strFieldsObject_Start = FDF.Substring(FldStart + 7, FDF.IndexOf(" R", FldStart + 7) - (FldStart + 7))
strFieldsObject_Start = strFieldsObject_Start.TrimStart(" "c)
strFieldsObject_Start = strFieldsObject_Start.TrimEnd("/"c)
strFieldsObject_Start = strFieldsObject_Start.TrimEnd(" "c)
strFieldsObject_Start = strFieldsObject_Start.TrimEnd("R"c)
strFieldsObject_Start = strFieldsObject_Start & " obj"
FldStart = FDF.IndexOf(strFieldsObject_Start, FldStart)
FldEnd = FDF.ToLower.IndexOf("endobj", FldStart + 8)
End If
intField(0) = FldStart
Dim strFix As String
Try
Dim FldSubStr As String = ""
intField(1) = FDF.ToLower.IndexOf("/doc ", 1) + 5
If intField(1) > 5 Then
intField(1) = FDF.ToLower.IndexOf("[", intField(1)) + 1
intField(2) = FDF.ToLower.IndexOf("]", intField(1))
strFields(3) = FDF.Substring(intField(1), intField(2) - intField(1))
strFields(3) = strFields(0).TrimStart(" "c)
strFields(3) = strFields(0).TrimEnd(" "c)
Dim strDocScripts() As String
strDocScripts = strFields(3).Split(CStr(")(").ToCharArray)
Dim result As Integer
Dim intTmpScript As Integer = 0, strTmpScript As String = ""
result = CInt(strDocScripts.Length / 2)
If result > 0 Then
For intTmpScript = 0 To strDocScripts.Length - 1 Step 2
strDocScripts(intTmpScript).TrimStart(" "c)
strDocScripts(intTmpScript).TrimStart("("c)
strDocScripts(intTmpScript).TrimEnd(" "c)
strDocScripts(intTmpScript).TrimEnd(")"c)
strDocScripts(intTmpScript + 1).TrimStart(" "c)
strDocScripts(intTmpScript + 1).TrimStart("("c)
strDocScripts(intTmpScript + 1).TrimEnd(" "c)
strDocScripts(intTmpScript + 1).TrimEnd(")"c)
Next
intTmpScript = 0
If result > 2 Then
For intTmpScript = 0 To strDocScripts.Length - 1 Step 2
FDFDox.FDFAddDocJavaScript(strDocScripts(intTmpScript), strDocScripts(intTmpScript + 1))
Next
ElseIf result = 2 Then
FDFDox.FDFAddDocJavaScript(strDocScripts(intTmpScript), strDocScripts(intTmpScript + 1))
End If
End If
End If
intField(0) = FldStart
Do While intField(0) < FldEnd
intField(0) = FDF.ToLower.IndexOf("<<", intField(0)) + 2
intField(5) = FDF.ToLower.IndexOf(">>", intField(0))
If intField(5) + 3 >= FldEnd Then
Exit Do
End If
FldSubStr = FDF.Substring(intField(0), intField(5) - intField(0))
Dim xit As Boolean = False
If (FldSubStr.ToLower.IndexOf("/t", 0) + 2 < FldSubStr.ToLower.IndexOf("/v", 0) + 2) Then
intField(1) = FldSubStr.ToLower.IndexOf("/t", 0) + 2
intField(1) = FldSubStr.ToLower.IndexOf("(", intField(1)) + 1
intField(2) = FldSubStr.ToLower.IndexOf(")", intField(1))
If FldSubStr.ToLower.IndexOf("/v", intField(1)) + 2 > 5 And FldSubStr.ToLower.IndexOf("/v", intField(2)) + 2 > FldSubStr.Length Then
intField(3) = FldSubStr.ToLower.IndexOf("/v", intField(2)) + 2
intField(4) = FldSubStr.Length
ElseIf FldSubStr.ToLower.IndexOf("/v/", intField(2), FldSubStr.Length - intField(2)) > 2 Then
intField(3) = FldSubStr.ToLower.IndexOf("/v/", intField(2)) + 3
intField(4) = FldSubStr.Length
If intField(4) > FldSubStr.Length Then
If FldSubStr.ToLower.IndexOf("/", intField(3)) > intField(3) And FldSubStr.ToLower.IndexOf("/", intField(3)) < FldSubStr.Length Then
intField(3) = FldSubStr.ToLower.IndexOf("/", intField(3)) + 1
intField(4) = FldSubStr.ToLower.IndexOf(">>", intField(4)) - 2
End If
End If
ElseIf FldSubStr.ToLower.IndexOf("/v /", intField(2), FldSubStr.Length - intField(2)) > 2 Then
intField(3) = FldSubStr.ToLower.IndexOf("/v/", intField(2)) + 3
intField(4) = FldSubStr.Length
If intField(4) > FldSubStr.Length Then
If FldSubStr.ToLower.IndexOf("/", intField(3)) > intField(3) And FldSubStr.ToLower.IndexOf("/", intField(3)) < FldSubStr.Length Then
intField(3) = FldSubStr.ToLower.IndexOf("/", intField(3)) + 1
intField(4) = FldSubStr.ToLower.IndexOf(">>", intField(4)) - 2
End If
End If
ElseIf FldSubStr.ToLower.IndexOf("/v/", intField(2), FldSubStr.Length - intField(2)) > 2 Then
intField(3) = FldSubStr.ToLower.IndexOf("/v/", intField(2)) + 3
intField(4) = FldSubStr.Length
If intField(4) > FldSubStr.Length Then
If FldSubStr.ToLower.IndexOf("/", intField(3)) > intField(3) And FldSubStr.ToLower.IndexOf("/", intField(3)) < FldSubStr.Length Then
intField(3) = FldSubStr.ToLower.IndexOf("/", intField(3)) + 1
intField(4) = FldSubStr.ToLower.IndexOf(">>", intField(4)) - 2
End If
End If
Else
intField(3) = FldSubStr.ToLower.IndexOf("/v", intField(2)) + 2
intField(3) = FldSubStr.ToLower.IndexOf("(", intField(3))
intField(4) = InStrRev(FldSubStr, ")", FldSubStr.Length, CompareMethod.Text)
If intField(4) > FldSubStr.Length Then
If FldSubStr.ToLower.IndexOf("/", intField(3)) > intField(3) And FldSubStr.ToLower.IndexOf("/", intField(3)) < FldSubStr.Length Then
intField(3) = FldSubStr.ToLower.IndexOf("/", intField(3)) + 1
intField(4) = FldSubStr.ToLower.IndexOf(">>", intField(4)) - 2
End If
End If
End If
Else
intField(1) = FldSubStr.ToLower.IndexOf("/v", 0) + 2
intField(1) = FldSubStr.ToLower.IndexOf("(", intField(1)) + 1
intField(2) = FldSubStr.ToLower.IndexOf(")", intField(1))
If FldSubStr.ToLower.IndexOf("/v", 0) + 2 > 5 And FldSubStr.ToLower.IndexOf("/v", 0) + 2 > FldSubStr.Length Then
intField(3) = FldSubStr.ToLower.IndexOf("/v", 0) + 2
intField(4) = FldSubStr.Length
ElseIf FldSubStr.ToLower.IndexOf("/v/", 0) > 1 Then
intField(3) = FldSubStr.ToLower.IndexOf("/v/", 0) + 3
intField(4) = FldSubStr.ToLower.IndexOf("/t", intField(3))
If intField(4) > FldSubStr.Length Then
If FldSubStr.ToLower.IndexOf("/", intField(3)) > intField(3) And FldSubStr.ToLower.IndexOf("/", intField(3)) < FldSubStr.Length Then
intField(3) = FldSubStr.ToLower.IndexOf("/", intField(3)) + 1
intField(4) = intField(1) - 2
End If
End If
ElseIf FldSubStr.ToLower.IndexOf("/v /", 0) > 0 Then
intField(3) = FldSubStr.ToLower.IndexOf("/v/", 0) + 4
intField(4) = FldSubStr.ToLower.IndexOf("/t", intField(3))
If intField(4) > FldSubStr.Length Then
If FldSubStr.ToLower.IndexOf("/", intField(3)) > intField(3) And FldSubStr.ToLower.IndexOf("/", intField(3)) < FldSubStr.Length Then
intField(3) = FldSubStr.ToLower.IndexOf("/", intField(3)) + 1
intField(4) = intField(1) - 2
End If
End If
ElseIf FldSubStr.ToLower.IndexOf("/v /", 0) > 0 Then
intField(3) = FldSubStr.ToLower.IndexOf("/v/", 0) + 5
intField(4) = FldSubStr.ToLower.IndexOf("/t", intField(3))
If intField(4) > FldSubStr.Length Then
If FldSubStr.ToLower.IndexOf("/", intField(3)) > intField(3) And FldSubStr.ToLower.IndexOf("/", intField(3)) < FldSubStr.Length Then
intField(3) = FldSubStr.ToLower.IndexOf("/", intField(3)) + 1
intField(4) = intField(1) - 2
End If
End If
Else
intField(3) = FldSubStr.ToLower.IndexOf("/v", intField(2)) + 2
intField(3) = FldSubStr.ToLower.IndexOf("(", intField(3))
intField(4) = InStrRev(FldSubStr, ")", FldSubStr.Length - 1, CompareMethod.Text)
If intField(4) > FldSubStr.Length Then
If FldSubStr.ToLower.IndexOf("/", intField(3)) > intField(3) And FldSubStr.ToLower.IndexOf("/", intField(3)) < intField(1) Then
intField(3) = FldSubStr.ToLower.IndexOf("/", intField(3)) + 1
intField(4) = intField(1) - 2
End If
End If
End If
intField(1) = FldSubStr.ToLower.IndexOf("/t", 0) + 2
intField(1) = FldSubStr.ToLower.IndexOf("(", intField(1)) + 1
intField(2) = FldSubStr.ToLower.IndexOf(")", intField(1))
End If
xit = False
Dim lngFldFound As Long
lngFldFound = FldSubStr.ToLower.IndexOf("\)", intField(3)) + 2
Do While xit = False
If intField(4) = lngFldFound Then
intField(4) = FldSubStr.ToLower.IndexOf(")", CInt(lngFldFound)) + 1
lngFldFound = FldSubStr.ToLower.IndexOf("\)", intField(4)) + 2
xit = False
Else
xit = True
End If
Loop
If (Not intField(3) > FldSubStr.Length) And intField(3) > 3 Then
strFields(0) = FldSubStr.Substring(intField(1), intField(2) - intField(1))
strFields(1) = FldSubStr.Substring(intField(3), intField(4) - intField(3))
strFields(0) = strFields(0).TrimStart(" "c)
strFields(0) = strFields(0).TrimEnd(" "c)
strFields(1) = strFields(1).TrimStart(" "c)
strFields(1) = strFields(1).TrimEnd(" "c)
If strFields(1).StartsWith("("c) And strFields(1).EndsWith(")"c) Then
If InStrRev(FldSubStr, "<body", FldSubStr.Length, CompareMethod.Text) > intField(2) Then
intField(3) = InStrRev(FldSubStr, "<body", FldSubStr.Length, CompareMethod.Text) + 5
intField(3) = FldSubStr.IndexOf(">", intField(3)) + 1
intField(4) = InStrRev(FldSubStr, "</body>", FldSubStr.Length, CompareMethod.Text) - 1
strFields(0) = FldSubStr.Substring(intField(1), intField(2) - intField(1))
strFields(1) = FldSubStr.Substring(intField(3), intField(4) - intField(3))
Else
strFields(0) = strFields(0).TrimStart("("c)
strFields(0) = strFields(0).TrimEnd(")"c)
strFields(1) = strFields(1).Remove(0, 1)
strFields(1) = strFields(1).Remove(strFields(1).Length - 1, 1)
End If
strFix = strFields(1)
strFields(1) = strFix
intField(4) = intField(5) + 2
FDFDox.FDFAddField(CStr(strFields(0)), CStr(FDFCheckCharReverse(strFields(1))), FDFDoc_Class.FieldType.FldTextual, True)
ElseIf strFields(1).StartsWith("["c) And strFields(1).EndsWith("]"c) Then
strFields(0) = strFields(0).TrimStart("("c)
strFields(0) = strFields(0).TrimEnd(")"c)
strFields(1) = strFields(1).TrimStart("["c)
strFields(1) = strFields(1).TrimEnd("]"c)
intField(4) = intField(5) + 2
FDFDox.FDFAddField(CStr(strFields(0)), CStr(FDFCheckCharReverse(strFields(1))), FDFDoc_Class.FieldType.FldMultiSelect)
ElseIf strFields(1).StartsWith("/"c) Then
strFields(0) = strFields(0).TrimStart("("c)
strFields(0) = strFields(0).TrimEnd(")"c)
strFields(1) = strFields(1).TrimStart("/"c)
strFields(1) = strFields(1).Substring(0, strFields(1).IndexOf(">>"))
intField(4) = intField(5) + 2
FDFDox.FDFAddField(strFields(0), FDFCheckCharReverse(strFields(1) & ""), FDFDoc_Class.FieldType.FldTextual)
ElseIf FldSubStr.ToLower.IndexOf("/v/", intField(2), FldSubStr.Length - intField(2)) > 2 Then
strFix = strFields(1)
strFields(1) = strFix
FDFDox.FDFAddField(CStr(strFields(0)), CStr(FDFCheckCharReverse(strFields(1))), FDFDoc_Class.FieldType.FldOption)
intField(4) = intField(5) + 2
Else
intField(4) = intField(5) + 2
End If
Else
If intField(3) > FldSubStr.Length Then
strFields(0) = FDF.Substring(intField(1), intField(2) - intField(1))
strFields(1) = FDF.Substring(intField(3), intField(4) - intField(3))
strFields(0) = strFields(0).TrimStart(" "c)
strFields(0) = strFields(0).TrimEnd(" "c)
If FDF.ToLower.IndexOf("/a ", intField(2)) > 1 Then
intField(3) = FDF.ToLower.IndexOf("/javascript /js ", intField(1)) + 16
If intField(3) <= 16 Then
intField(3) = FDF.ToUpper.IndexOf("/URI /URI ", intField(1)) + 10
End If
If intField(3) <= 16 Then
GoTo NO_SCRIPT
End If
intField(4) = FDF.ToLower.IndexOf(">>", intField(3))
strFields(1) = FDF.Substring(intField(3), intField(4) - intField(3))
strFields(1) = strFields(1).TrimStart(" "c)
strFields(1) = strFields(1).TrimStart("("c)
strFields(1) = strFields(1).TrimEnd(" "c)
strFields(1) = strFields(1).TrimEnd(")"c)
FDFDox.FDFSetJavaScriptAction(strFields(0), FDFDoc_Class.FDFActionTrigger.FDFUp, strFields(1))
ElseIf FDF.ToLower.IndexOf("/aa ", intField(2)) > 1 Then
intField(3) = FDF.ToLower.IndexOf("/aa << /", intField(2)) + 8
intField(4) = FDF.ToLower.IndexOf(" <<", intField(3))
intField(5) = FDF.ToLower.IndexOf("/javascript /js ", intField(1)) + 16
If intField(5) <= 16 Then
intField(5) = FDF.ToUpper.IndexOf("/URI /URI ", intField(1)) + 10
End If
If intField(5) <= 16 Then
GoTo NO_SCRIPT
End If
intField(6) = FDF.ToLower.IndexOf(">>", intField(3))
strFields(1) = FDF.Substring(intField(3), intField(4) - intField(3))
strFields(1) = strFields(1).TrimStart(" "c)
strFields(1) = strFields(1).TrimStart("("c)
strFields(1) = strFields(1).TrimEnd(" "c)
strFields(1) = strFields(1).TrimEnd(")"c)
strFields(2) = FDF.Substring(intField(5), intField(6) - intField(5))
strFields(2) = strFields(2).TrimStart(" "c)
strFields(2) = strFields(2).TrimStart("("c)
strFields(2) = strFields(2).TrimEnd(" "c)
strFields(2) = strFields(2).TrimEnd(")"c)
FDFDox.FDFSetJavaScriptAction(strFields(0), ReturnTriggerString(strFields(1)), strFields(2))
Else
intField(4) = FDF.ToLower.IndexOf(">>", intField(2))
End If
End If
NO_SCRIPT:
If FDF.ToLower.IndexOf("/t", intField(0)) < 5 Then
intField(3) = FldEnd + 1
End If
End If
intField(0) = intField(5) + 2
If intField(0) + 4 >= FldEnd Then
Exit Do
ElseIf intField(5) + 4 >= FldEnd Then
Exit Do
End If
Loop
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, ex.Message, "FDFApp.parseFDF", 1)
Return FDFDox
End Try
Try
intField(1) = FDF.ToLower.IndexOf("/f ") + 3
If intField(1) <= 3 Then
intField(1) = FDF.ToLower.IndexOf("/f(") + 3
End If
If intField(1) <= 3 Then
intField(1) = FDF.ToLower.IndexOf("/f")
If intField(1) = FDF.ToLower.IndexOf("/fields") Then
intField(1) = FDF.ToLower.IndexOf("/f", intField(1)) + 2
End If
End If
If intField(1) > 3 Then
intField(2) = FDF.IndexOf(")", intField(1))
strFields(0) = FDF.Substring(intField(1), intField(2) - intField(1)) & ""
strFields(0) = strFields(0).Replace("(", "")
strFields(0) = strFields(0).Replace(")", "")
strFields(0) = strFields(0).TrimStart(" "c)
strFields(0) = strFields(0).TrimEnd(" "c)
FDFDox.FDFSetFile(strFields(0) & "")
End If
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, ex.Message, "FDFApp.parseFDF", 2)
Return FDFDox
End Try
Try
If String_IsNullOrEmpty(FDFDox.FDFGetFile) Then
FDFDox.FDFSetFile(FDFGetFileiText(tmpFDF))
End If
Catch ex As Exception
End Try
Try
If AppendSaves Then
FDFDox = FDFImportAppendSaves(FDF, False)
End If
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & ex.Message, "FDFApp.parseFDF", 3)
Return FDFDox
End Try
FDFDox.FDFData = FDF
FDFDox.XDPAdjustSubforms()
Return FDFDox
Catch Ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, Ex)
Return Nothing
End Try
End Function
Private Function parsePDF(ByVal PDF As Byte(), Optional ByVal FDFInitialize As Boolean = False, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
If Not PDF Is Nothing Then
FDFDox.PDFData = PDF
End If
Dim reader As iTextSharp.text.pdf.PdfReader
If String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(PDF)
Else
reader = New iTextSharp.text.pdf.PdfReader(PDF, _defaultEncoding.GetBytes(ownerPassword))
End If
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
If isXFA Then
reader.Close()
reader = Nothing
xfaFrm = Nothing
Return parseXFA(PDF, FDFInitialize)
Exit Function
End If
Dim af As iTextSharp.text.pdf.PRAcroForm
af = reader.AcroForm
Dim fld As iTextSharp.text.pdf.AcroFields.Item ' iTextSharp.text.pdf.PRAcroForm.FieldInformation
Dim flds As iTextSharp.text.pdf.AcroFields = reader.AcroFields
On Error Resume Next
For Each fieldName As String In flds.Fields.Keys
If InStr(fieldName, "].") > 0 Then
Dim fldstart As Integer = fieldName.LastIndexOf("].")
fieldName = fieldName.Substring(fldstart + 2, fieldName.Length - fldstart - 2)
End If
Dim val As String = ""
val = flds.GetField(fieldName) & ""
If flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_TEXT Or flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_CHECKBOX Then
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val, FDFDoc_Class.FieldType.FldTextual, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_COMBO Then
Dim disp() As String, vals() As String, exp() As String
exp = flds.GetListOptionExport(fieldName)
disp = flds.GetListOptionDisplay(fieldName)
vals = flds.GetListSelection(fieldName)
FDFDox.FDFAddField(fieldName, vals, disp, exp, FDFDoc_Class.FieldType.FldMultiSelect, True, False)
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_LIST Then
Dim disp() As String, vals() As String, exp() As String
exp = flds.GetListOptionExport(fieldName)
disp = flds.GetListOptionDisplay(fieldName)
vals = flds.GetListSelection(fieldName)
FDFDox.FDFAddField(fieldName, vals, disp, exp, FDFDoc_Class.FieldType.FldMultiSelect, True, False)
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_RADIOBUTTON Then
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val.TrimStart("/"c), FDFDoc_Class.FieldType.FldOption, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldOption, True, True)
End If
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_PUSHBUTTON Then
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val.TrimStart("/"c), FDFDoc_Class.FieldType.FldButton, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldButton, True, True)
End If
Else
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val, FDFDoc_Class.FieldType.FldTextual, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
End If
Next
Dim streamPDF As New MemoryStream
Dim stp As New iTextSharp.text.pdf.PdfStamper(reader, streamPDF)
stp.Close()
streamPDF.Read(FDFDox.PDFData, 0, CInt(streamPDF.Length))
FDFDox.XDPAdjustSubforms()
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
stp = Nothing
reader = Nothing
xfaFrm = Nothing
Return FDFDox
End Function
Private Function getAcroFields(ByVal pathDoc As String) As iTextSharp.text.pdf.AcroFields
Dim pdfReader As New iTextSharp.text.pdf.PdfReader(pathDoc)
Dim fields As iTextSharp.text.pdf.AcroFields = pdfReader.AcroFields
pdfReader.Close()
Return fields
End Function
Private Function getAcroFields(ByVal PDF() As Byte) As iTextSharp.text.pdf.AcroFields
Dim pdfReader As New iTextSharp.text.pdf.PdfReader(PDF)
Dim fields As iTextSharp.text.pdf.AcroFields = pdfReader.AcroFields
pdfReader.Close()
Return fields
End Function
Public Function getXFAFieldNames(ByVal path As String) As System.Collections.Generic.List(Of String)
Dim Keys As New System.Collections.Generic.List(Of String) 'System.Collections.Generic.Dictionary(Of String, String)
Select Case Determine_Type(path)
Case FDFType.PDF
Dim af As iTextSharp.text.pdf.AcroFields = getAcroFields(path)
For Each fld As String In af.Fields.Keys
Keys.Add(fld) ', af.GetField(fld))
Next
Case FDFType.XFA
Return Keys
Case FDFType.XPDF
Dim af As iTextSharp.text.pdf.AcroFields = getAcroFields(path)
Dim xfa As iTextSharp.text.pdf.XfaForm = af.Xfa
If xfa.XfaPresent Then
Dim n As System.Xml.XmlNode = xfa.DatasetsNode.FirstChild
For Each f As String In xfa.DatasetsSom.Order.ToArray
If f.Contains("."c) Then
f = f.Substring(f.LastIndexOf("."c) + 1, f.Length - f.LastIndexOf("."c) - 1)
End If
Keys.Add(f)
Next
End If
Case Else
Return Keys
End Select
Return Keys
End Function
Public Function getXFAFieldNames(ByVal PDF() As Byte) As System.Collections.Generic.List(Of String)
Dim Keys As New System.Collections.Generic.List(Of String) 'System.Collections.Generic.Dictionary(Of String, String)
Select Case Determine_Type(PDF)
Case FDFType.PDF
Dim af As iTextSharp.text.pdf.AcroFields = getAcroFields(PDF)
For Each fld As String In af.Fields.Keys
Keys.Add(fld) ', af.GetField(fld))
Next
Case FDFType.XFA
Return Keys
Case FDFType.XPDF
Dim af As iTextSharp.text.pdf.AcroFields = getAcroFields(PDF)
Dim xfa As iTextSharp.text.pdf.XfaForm = af.Xfa
If xfa.XfaPresent Then
Dim n As System.Xml.XmlNode = xfa.DatasetsNode.FirstChild
For Each f As String In xfa.DatasetsSom.Order.ToArray
If f.Contains("."c) Then
f = f.Substring(f.LastIndexOf("."c) + 1, f.Length - f.LastIndexOf("."c) - 1)
End If
Keys.Add(f)
Next
End If
Case Else
Return Keys
End Select
Return Keys
End Function
Public Function GetPushButtonFieldNames(ByVal PDF As Byte()) As String()
FDFDox.DefaultEncoding = _defaultEncoding
If Not PDF Is Nothing Then
FDFDox.PDFData = PDF
End If
Dim reader As iTextSharp.text.pdf.PdfReader
reader = New iTextSharp.text.pdf.PdfReader(PDF)
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
Dim af As iTextSharp.text.pdf.PRAcroForm
af = reader.AcroForm
Dim fld As iTextSharp.text.pdf.PRAcroForm.FieldInformation
Dim flds As iTextSharp.text.pdf.AcroFields = reader.AcroFields
Dim fields As ArrayList = af.Fields
On Error Resume Next
Dim FieldNames As New System.Collections.Generic.List(Of String)
For Each fld In fields
Dim fieldName As String = fld.Name
If InStr(fieldName, "].") > 0 Then
Dim fldstart As Integer = fieldName.LastIndexOf("].")
fieldName = fieldName.Substring(fldstart + 2, fieldName.Length - fldstart - 2)
End If
Dim val As String = ""
val = flds.GetField(fieldName) & ""
If flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_PUSHBUTTON Then
FieldNames.Add(fieldName)
End If
Next
Return FieldNames.ToArray
End Function
Private Function parsePDF(ByVal FileNameorURL As String, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
If IsValidUrl(FileNameorURL) Then
Dim wClient As New Net.WebClient
Dim strPDF As New MemoryStream
FDFDox.PDFData = wClient.DownloadData(FileNameorURL)
ElseIf File.Exists(FileNameorURL) Then
Dim fs As New FileStream(FileNameorURL, FileMode.Open)
ReDim FDFDox.PDFData(CInt(fs.Length))
fs.Read(FDFDox.PDFData, 0, CInt(fs.Length))
fs.Close()
Else
Return Nothing
End If
Dim reader As iTextSharp.text.pdf.PdfReader
If Not FDFDox.PDFData Is Nothing Then
If String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(FDFDox.PDFData)
Else
reader = New iTextSharp.text.pdf.PdfReader(FDFDox.PDFData, _defaultEncoding.GetBytes(ownerPassword))
End If
Else
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, "Error: " & "PDF File Empty", "FDFApp.ParsePDF", 1)
Return Nothing
Exit Function
End If
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
If isXFA Then
reader.Close()
reader = Nothing
xfaFrm = Nothing
Return parseXFA(FileNameorURL, FDFInitialize)
Exit Function
Else
FDFDox.FDFSetFile(FileNameorURL)
End If
Dim af As iTextSharp.text.pdf.PRAcroForm
af = reader.AcroForm
Dim fld As iTextSharp.text.pdf.AcroFields.Item ' iTextSharp.text.pdf.PRAcroForm.FieldInformation
Dim flds As iTextSharp.text.pdf.AcroFields = reader.AcroFields
On Error Resume Next
For Each fieldName As String In flds.Fields.Keys
If InStr(fieldName, "].") > 0 Then
Dim fldstart As Integer = fieldName.LastIndexOf("].")
fieldName = fieldName.Substring(fldstart + 2, fieldName.Length - fldstart - 2)
End If
Dim val As String = ""
val = flds.GetField(fieldName) & ""
If flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_TEXT Or flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_CHECKBOX Then
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val, FDFDoc_Class.FieldType.FldTextual, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_COMBO Then
Dim disp() As String, vals() As String, exp() As String
exp = flds.GetListOptionExport(fieldName)
disp = flds.GetListOptionDisplay(fieldName)
vals = flds.GetListSelection(fieldName)
FDFDox.FDFAddField(fieldName, vals, disp, exp, FDFDoc_Class.FieldType.FldMultiSelect, True, False)
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_LIST Then
Dim disp() As String, vals() As String, exp() As String
exp = flds.GetListOptionExport(fieldName)
disp = flds.GetListOptionDisplay(fieldName)
vals = flds.GetListSelection(fieldName)
FDFDox.FDFAddField(fieldName, vals, disp, exp, FDFDoc_Class.FieldType.FldMultiSelect, True, False)
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_RADIOBUTTON Then
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val.TrimStart("/"c), FDFDoc_Class.FieldType.FldOption, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldOption, True, True)
End If
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_PUSHBUTTON Then
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val.TrimStart("/"c), FDFDoc_Class.FieldType.FldButton, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldButton, True, True)
End If
Else
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val, FDFDoc_Class.FieldType.FldTextual, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
End If
Next
Dim streamPDF As New MemoryStream
Dim stp As New iTextSharp.text.pdf.PdfStamper(reader, streamPDF)
stp.Close()
streamPDF.Read(FDFDox.PDFData, 0, CInt(streamPDF.Length))
FDFDox.XDPAdjustSubforms()
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
FDFDox.FDFSetFile(FileNameorURL)
stp = Nothing
reader = Nothing
xfaFrm = Nothing
Return FDFDox
End Function
Private Function parsePDF(ByVal PDFStream As Stream, Optional ByVal FDFInitialize As Boolean = False, Optional ByVal ownerPassword As String = "") As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
FDFDox.DefaultEncoding = _defaultEncoding
Dim reader As iTextSharp.text.pdf.PdfReader
If String_IsNullOrEmpty(ownerPassword) Then
reader = New iTextSharp.text.pdf.PdfReader(PDFStream)
Else
reader = New iTextSharp.text.pdf.PdfReader(PDFStream, _defaultEncoding.GetBytes(ownerPassword))
End If
If PDFStream.Length > 0 Then
If PDFStream.CanSeek Then
PDFStream.Position = 0
End If
PDFStream.Read(FDFDox.PDFData, 0, FDFDox.PDFData.Length)
End If
Dim xfaFrm As New iTextSharp.text.pdf.XfaForm(reader)
Dim isXFA As Boolean = False
isXFA = xfaFrm.XfaPresent
If isXFA Then
reader.Close()
reader = Nothing
xfaFrm = Nothing
Return parseXFA(PDFStream, FDFInitialize)
Exit Function
End If
Dim af As iTextSharp.text.pdf.PRAcroForm
af = reader.AcroForm
Dim fld As iTextSharp.text.pdf.AcroFields.Item ' iTextSharp.text.pdf.PRAcroForm.FieldInformation
Dim flds As iTextSharp.text.pdf.AcroFields = reader.AcroFields
On Error Resume Next
For Each fieldName As String In flds.Fields.Keys
If InStr(fieldName, "].") > 0 Then
Dim fldstart As Integer = fieldName.LastIndexOf("].")
fieldName = fieldName.Substring(fldstart + 2, fieldName.Length - fldstart - 2)
End If
Dim val As String = ""
val = flds.GetField(fieldName) & ""
If flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_TEXT Or flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_CHECKBOX Then
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val, FDFDoc_Class.FieldType.FldTextual, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_COMBO Then
Dim disp() As String, vals() As String, exp() As String
exp = flds.GetListOptionExport(fieldName)
disp = flds.GetListOptionDisplay(fieldName)
vals = flds.GetListSelection(fieldName)
FDFDox.FDFAddField(fieldName, vals, disp, exp, FDFDoc_Class.FieldType.FldMultiSelect, True, False)
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_LIST Then
Dim disp() As String, vals() As String, exp() As String
exp = flds.GetListOptionExport(fieldName)
disp = flds.GetListOptionDisplay(fieldName)
vals = flds.GetListSelection(fieldName)
FDFDox.FDFAddField(fieldName, vals, disp, exp, FDFDoc_Class.FieldType.FldMultiSelect, True, False)
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_RADIOBUTTON Then
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val.TrimStart("/"c), FDFDoc_Class.FieldType.FldOption, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldOption, True, True)
End If
ElseIf flds.GetFieldType(fieldName) = iTextSharp.text.pdf.AcroFields.FIELD_TYPE_PUSHBUTTON Then
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val.TrimStart("/"c), FDFDoc_Class.FieldType.FldButton, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldButton, True, True)
End If
Else
If Not String_IsNullOrEmpty(val & "") Then
FDFDox.FDFAddField(fieldName, val, FDFDoc_Class.FieldType.FldTextual, True, True)
Else
FDFDox.FDFAddField(fieldName, "", FDFDoc_Class.FieldType.FldTextual, True, True)
End If
End If
Next
Dim streamPDF As New MemoryStream
Dim stp As New iTextSharp.text.pdf.PdfStamper(reader, streamPDF)
stp.Close()
streamPDF.Read(FDFDox.PDFData, 0, CInt(streamPDF.Length))
FDFDox.FDFData = FDFDox.FDFSavetoStr(FDFDoc_Class.FDFType.FDF, True)
stp = Nothing
reader = Nothing
xfaFrm = Nothing
Return FDFDox
End Function
''' <summary>
''' GOOD VERSION
''' </summary>
''' <param name="FDF"></param>
''' <param name="PDFFileName"></param>
''' <param name="FDFInitialize"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function parseXML(ByVal FDF As String, ByVal PDFFileName As String, Optional ByVal FDFInitialize As Boolean = False) As FDFDoc_Class
If FDFInitialize Then FDFDox.Initialize(_defaultEncoding)
If String_IsNullOrEmpty(PDFFileName) Then
If String_IsNullOrEmpty(FDFDox.XDPGetFile) Then
PDFFileName = FDFDox.XDPGetFile & ""
End If
Else
FDFDox.FDFSetFile(PDFFileName)
End If
FDFDox.DefaultEncoding = _defaultEncoding
Dim memFDF As New MemoryStream
Dim previousFieldAdded As String = ""
Dim _f As New FDFDoc_Class.FDFDoc_Class
Try
FDF = FDF.Replace("<xfa:", "<")
FDF = FDF.Replace("</xfa:", "</")
FDF = FDF.Replace("xfa:", "")
FDF = FDF.Replace(":xfa", "")
FDF = FDF.Replace(Chr(10) & ">", ">")
FDF = FDF.Replace(Chr(10) & "/>", "/>")
FDF = FDF.Replace(Chr(13) & ">", ">")
FDF = FDF.Replace(Chr(13) & "/>", "/>")
FDF = FDF.Replace(Environment.NewLine & ">", ">")
FDF = FDF.Replace(Environment.NewLine & "/>", "/>")
FDF = FDF.Replace(" xmlns=""http://www.xfa.org/schema/xfa-data/1.0/""", "")
Dim strFDF As New StringReader(FDF)
Dim ds As New DataSet
FDFDox.DefaultEncoding = _defaultEncoding
Dim Name As String = "", Value As String = ""
Dim FormName As String = "", ContentType As String = "", Href As String = ""
Dim PreviousSubFormDepth As Integer = 0, PreviousSubFormName As String = "", SubFormNames As String() = {}, CurDepth As Integer = 0
Dim _xml As New XmlDocument
FDF = FDF.Replace(" xmlns=""http://www.xfa.org/schema/xfa-data/1.0/""", "")
_xml.PreserveWhitespace = True
_xml.LoadXml(FDF.Trim())
FormName = _xml.Name
ReDim Preserve SubFormNames(CurDepth)
SubFormNames(CurDepth) = FormName
Dim subFormLevel As String = String.Join("/", getParentLevel(_xml))
If _xml.HasChildNodes Then
If _xml.ChildNodes.Count > 0 Then
For Each chld As XmlNode In _xml.ChildNodes
Try
If chld.HasChildNodes Then
_f = New FDFDoc_Class.FDFDoc_Class
_f.FormName = chld.Name
_f.DocType = FDFDoc_Class.FDFDocType.XDPForm
_f.FormLevel = String.Join("/", getParentLevel(chld))
_f.FormLevel = _f.FormLevel.TrimStart("/"c)
_f.FormLevel = _f.FormLevel.TrimEnd("/"c)
_f.FormLevel = _f.FormLevel.Replace("//", "/")
_f.FileName = FDFDox.FDFGetFile()
_f.struc_FDFFields.AddRange(parseXMLChildItems(chld))
FDFDox.XDPAddField(_f, _f.FormName, _f.FormLevel.ToString.Split(("/"c)), True, False)
End If
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, ex)
Err.Clear()
End Try
PreviousSubFormDepth = CurDepth
PreviousSubFormName = FormName
CurDepth += 1
Next
PreviousSubFormDepth = CurDepth
PreviousSubFormName = FormName
CurDepth += 1
End If
End If
FOUNDIMAGE:
FDFDox.XDPAdjustSubforms()
Return FDFDox
Catch Ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, Ex)
Return Nothing
End Try
End Function
Private Function getParentFormNames(ByVal formNames() As String) As String()
Dim lst As New System.Collections.Generic.List(Of String)
Try
lst.AddRange(formNames)
If lst.Count > 1 Then
lst.RemoveAt(lst.Count - 1)
Return lst.ToArray
Else
Return New String() {""}
End If
Catch ex As Exception
_FDFErrors.FDFAddError(FDFErrors.FDFErc.FDFErcInternalError, ex)
Err.Clear()
End Try
Return formNames
End Function
' Private Function parseXMLChildItems(ByVal _xml As XmlNode) As FDFApp.FDFDoc_Class.FDFField()
' Dim PDFFileName As String = ""
' Dim memFDF As New MemoryStream
' Dim previousFieldAdded As String = ""
' Dim _f As New FDFDoc_Class.FDFDoc_Class
' Dim Name As String = "", Value As String = ""
' Dim FormName As String = "", ContentType As String = "", Href As String = "", ImageFieldStr As String
' Dim PreviousSubFormDepth As Integer = 0, PreviousSubFormName As String = "", SubFormNames As String() = {}, CurDepth As Integer = 0
' Dim flds As New System.Collections.Generic.List(Of FDFApp.FDFDoc_Class.FDFField)
' For Each c As Xml.XmlNode In _xml.ChildNodes
' Select Case c.NodeType
' Case XmlNodeType.Text
' If Not String_IsNullOrEmpty(c.ParentNode.Name) And c.HasChildNodes = False Then
' Name = c.ParentNode.Name
' If Not String_IsNullOrEmpty(Name & "") Then
' Value = c.Value & ""
' flds.Add(New FDFDoc_Class.FDFField(Name & "", XMLCheckCharReverse(Value & ""), FDFDoc_Class.FieldType.FldTextual))
' previousFieldAdded = Name
' Value = ""
' Name = ""
' End If
' End If
' Case XmlNodeType.Element
' Name = c.Name
' If c.Attributes.Count > 0 Then
' For Each a As XmlAttribute In c.Attributes
' Select Case a.Name.ToLower
' Case "root"
' Case "version=""1.0"" encoding=""UTF-8"
' Case "version"
' Case "standalone"
' Case "xml"
' Case "xmlns"
' Case "encoding"
' Case "pdf"
' Case "xmlns:xdp"
' Case "xmlns:xfa"
' Case "xmlns"
' Case "xml:space"
' Case "xmlns"
'