您好我正在和我的团队其他成员一起试图找出一个问题,当我点击Google Chrome PDF查看器中带有预先填写的PDF表单的打印图标时,我们遇到了这个问题。单击打印图标时,它会显示打印预览,并且字段中输入的数据将复制到字段所在的同一列中(下面的屏幕截图)。我们基本上预先填写从我们的数据库中选择和提取的特定客户的信息。我们获取该信息并构建adobe FDF字符串。
Public Function BuildFDF(ByVal arrObj() As IBuildFDF, ByVal sPDF As String, ByVal bLock As Boolean) As String
Dim i As Int32 = 0
Dim sb As New Text.StringBuilder
'build header
sb.Append("%FDF-1.2") : sb.Append(Chr(13))
sb.Append("1 0 obj") : sb.Append(Chr(13))
sb.Append("<<") : sb.Append(Chr(13))
sb.Append("/FDF") : sb.Append(Chr(13))
sb.Append("<< ") : sb.Append(Chr(13))
sb.Append("/Fields") : sb.Append(Chr(13))
sb.Append("[") : sb.Append(Chr(13))
'create fdf from objects in the array
For i = 0 To arrObj.Length - 1
sb.Append(arrObj(i).BuildFDF(bLock))
Next
'build trailer
sb.Append(Chr(13)) : sb.Append("]") : sb.Append(Chr(13))
sb.Append("/F ") : sb.Append("(" & sPDF & ")")
' put a popup message warning that there is autopopulated fields
sb.Append(Chr(13)) : sb.Append("/Status (There may be prepopulated fields on this form \(in bold type\). Please \ review.)")
'End If
sb.Append(Chr(13)) : sb.Append(">>")
sb.Append(Chr(13)) : sb.Append(" >> ")
sb.Append(Chr(13)) : sb.Append("endobj")
sb.Append(Chr(13)) : sb.Append("trailer ")
sb.Append(Chr(13)) : sb.Append("<< /Root 1 0 R >> ")
sb.Append(Chr(13)) : sb.Append("%%EOF")
Return sb.ToString
End Function
我们使用 ABCPdf 格式化FDF字符串中的值。然后将值添加到键值对列表中。
Dim theFDF As Doc = New Doc() 'ABCPdf WebSupergoo
Dim theDoc As Doc = New Doc() 'ABCPdf WebSupergoo
Dim pdfFile As String = ""
Dim theValues As String = ""
Dim theLastID As Integer
Dim theList As New Hashtable
Public Sub GetEasyFillData(ByVal sFDF As String, Optional ByVal spdf As String = "")
Dim encoding As New System.Text.UTF8Encoding()
theFDF.Read(encoding.GetBytes(sFDF))
theLastID = Convert.ToInt32(theFDF.GetInfo(0, "Count"))
For i As Integer = 0 To theLastID
Dim theType As String
theType = theFDF.GetInfo(i, "Type")
If theType = "anno" Then
If theFDF.GetInfo(i, "SubType") = "Text" Then
Dim theCont As String
theCont = theFDF.GetInfo(i, "Contents")
theValues = theValues + theCont + vbCrLf + vbCrLf
End If
End If
Next
For i As Integer = 0 To theLastID
Dim theNumber As Integer
theNumber = theFDF.GetInfoInt(i, "/FDF*/Fields*:Count")
Dim j As Integer
For j = 0 To theNumber - 1
Dim theName As String = theFDF.GetInfo(i, "/FDF*/Fields*[" & j & "]*/T:Text")
Dim theValue As String = theFDF.GetInfo(i, "/FDF*/Fields*[" & j & "]*/V:Text")
If theList.ContainsKey(theName) = False Then
theList.Add(theName, theValue)
End If
Next
Next
'Set location of pdf form to fill
If spdf = "" Then
pdfFile = theFDF.GetInfo(1, "FDF*/F:Text").ToString
Else
pdfFile = spdf
End If
End Sub
然后我们将pdf表格读入 theDoc 变量,获取新获取的pdf的字段名称,并使用键值对列表中的相应字段值填充它们。
Public Sub PopulatePDF()
With theDoc
.Read(pdfFile)
End With
Dim fieldNames As String() = theDoc.Form.GetFieldNames()
Dim fieldName As String
For Each fieldName In fieldNames
Dim theField As Field = theDoc.Form(fieldName)
If (theField IsNot Nothing) Then
If (theList.ContainsKey(theField.Name) = False) Then
theList.Add(theField.Name, theField.Value)
End If
theField.Value = CStr(theList.Item(theField.Name))
End If
Next
End Sub
然后我们将数据写入页面:
Private Sub AddPDFToPage()
Dim response As HttpResponse = HttpContext.Current.Response
With response
.ContentType = "application/pdf"
.AddHeader("content-disposition", "inline; filename=MyPDF.PDF")
'.AddHeader("content-length", theDoc.GetData.Length.ToString())
.BinaryWrite(theDoc.GetData())
End With
HttpContext.Current.ApplicationInstance.CompleteRequest()
End Sub
请查看我们在这些字段中输入数据时的内容截图
如果有人对此为何发生任何想法,我们将非常感谢蚂蚁反馈。