Vb.net Google Chrome自动填充PDF在打印预览中复制字段数据
您好,我正在和我的团队其他成员一起努力找出一个问题,我们在谷歌Chrome PDF浏览器中使用预填充PDF表单单击打印图标时遇到了这个问题。单击打印图标时,将显示打印预览,字段中输入的数据将在字段所在的同一列中复制(下面的屏幕截图)。我们基本上预先填写从数据库中选择和提取的特定客户机的信息。我们获取这些信息并构建一个adobe FDF字符串Vb.net Google Chrome自动填充PDF在打印预览中复制字段数据,vb.net,google-chrome,pdf,printing,Vb.net,Google Chrome,Pdf,Printing,您好,我正在和我的团队其他成员一起努力找出一个问题,我们在谷歌Chrome PDF浏览器中使用预填充PDF表单单击打印图标时遇到了这个问题。单击打印图标时,将显示打印预览,字段中输入的数据将在字段所在的同一列中复制(下面的屏幕截图)。我们基本上预先填写从数据库中选择和提取的特定客户机的信息。我们获取这些信息并构建一个adobe FDF字符串 Public Function BuildFDF(ByVal arrObj() As IBuildFDF, ByVal sPDF As String, B
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
然后,我们将pdf表单读入DOC变量,获取新获取的pdf的字段名,并使用键值对列表中的相应字段值填充它们
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
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
请查看我们在这些字段中输入数据时发生的情况的屏幕截图
单击打印预览之前
打印预览后
如果有人对这种情况的发生有任何想法,ant反馈将不胜感激。有没有办法阻止这种情况发生?有没有办法阻止这种情况发生?