.net 用XDP填充PDF

.net 用XDP填充PDF,.net,winforms,pdf,adobe,xdp-pdf,.net,Winforms,Pdf,Adobe,Xdp Pdf,我有一个填充PDF,它使用一个简单的XFDF文件来填充。使用VS.NET2010,我阅读了XFDF文档,填充了所有必要的信息,并使用ds.WriteXML(XFDFName)填充了PDF。XFDF是通过Process.Start(XFDFName)编写和启动的。这些都在WinForms应用程序中。几年来,这种方法一直很有效。直到现在 我遇到的问题是无法将数据导出为XFDF格式,因为该文件是在Adobe LiveCycle中创建的。我注意到导出选项是(1)XML或(2)XDP。在过去,我能够导出到

我有一个填充PDF,它使用一个简单的XFDF文件来填充。使用VS.NET2010,我阅读了XFDF文档,填充了所有必要的信息,并使用ds.WriteXML(XFDFName)填充了PDF。XFDF是通过Process.Start(XFDFName)编写和启动的。这些都在WinForms应用程序中。几年来,这种方法一直很有效。直到现在

我遇到的问题是无法将数据导出为XFDF格式,因为该文件是在Adobe LiveCycle中创建的。我注意到导出选项是(1)XML或(2)XDP。在过去,我能够导出到XFDF。我想没什么大不了的,只是另一种形式。然而,我一直在为这两种选择而挣扎。经过深思熟虑,我决定使用XDP格式

我已经用我需要的所有信息构建了数据集,当使用Process.Start(XDPName)打开新创建的XDP时,我收到一个错误。读卡器打开,我遇到以下错误:

我试着用一个直接指向PDF的href,但也没用。因此,我选择将序列化PDF粘贴在部分的XDP中

此XDP文件如下所示():


XML在这里-匹配PDF中的动态字段。
Base64编码PDF
我会认为我生成的XDP是假的,但更复杂的是,如果我打开Reader,单击工具>表单>更多表单选项>管理表单数据>导入数据,并选择我生成的XDP文件,所有字段都会按我预期的方式填充

因此,基本上,在某些地方显然存在着脱节: 我有一个XDP文件,里面有我需要的所有信息。 我有一个PDF表单,我需要用XDP文件填充它。 XDP中的信息与PDF中的所有控件名称正确匹配。 但当我启动XDP文件时,读者告诉我它已损坏/不受支持。据我所知,当您启动XDP文件时,它应该使用Reader正确启动/填充,对吗


任何信息都会对我大有裨益。谢谢。

我在完成这项工作时也遇到了问题

在VB.net中做类似的事情

使用chunk时似乎不起作用,但如果我使用href和本地文件,它确实起作用

测试示例

Public Sub BuildContent(ByVal slno As String)

    Dim strXML As String

    Dim fs As System.IO.FileStream = Nothing
    Dim bw As System.IO.BinaryWriter = Nothing
    Dim Buffer() As Byte
    'fs = New System.IO.FileStream("kpiAlert10.pdf", IO.FileMode.Create)
    'bw = New System.IO.BinaryWriter(fs)
    'Response.ContentType = "application/vnd.adobe.xdp+xml"
    '
    ' Constant XPD Header
    '
    strXML = "<?xml version='1.0' encoding='UTF-8'?>"
    strXML = strXML & "<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>"
    strXML = strXML & "<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>"
    strXML = strXML & "<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>"
    strXML = strXML & "<xfa:data>"
    '
    ' Place code here to get the current Logged in user ID
    ' and perform a query to the back end database and filter by ID
    ' then generate the following XML Data using the resultant Recordset ...etc.
    '

    strXML = strXML & "<transaction><kpi><name>Ego ille</name><data><sn>Si manu vacuas</sn><amt>Apros tres et quidem</amt><delta>Mirum est</delta></data></kpi></transaction>"
    '
    '
    '
    strXML = strXML & "</xfa:data>"
    strXML = strXML & "</xfa:datasets>"
    '
    ' Point the XPD to the PDF Form created under Adobe LiveCycle Desinger
    '
    Dim contents As String

    contents = EncodeFile("kpiAlert.pdf")
    'Buffer = Convert.FromBase64String(contents)
    strXML = strXML & "<pdf xmlns='http://ns.adobe.com/xdp/pdf/'>"
    strXML = strXML & "<document>"
    strXML = strXML & "<chunk>" & contents & "=</chunk>"
    strXML = strXML & "</document>"
    strXML = strXML & "</pdf>"

    'strXML = strXML & "<pdf href='C:/kpiAlert.pdf' xmlns='http://ns.adobe.com/xdp/pdf/' />"
    '
    ' Close the XPD File
    '
    strXML = strXML & "</xdp:xdp>"

    Using outfile As New StreamWriter("kpiAlert_" & slno & ".pdf")
        outfile.Write(strXML.ToString())
    End Using

End Sub

Function EncodeFile(ByVal srcFile As String) As String

    Dim srcBT As Byte()
    Dim dest As String
    Dim sr As New IO.FileStream(srcFile, IO.FileMode.Open)
    ReDim srcBT(sr.Length)
    sr.Read(srcBT, 0, sr.Length)
    sr.Close()
    dest = EncodeByte(srcBT)
    Return dest

End Function

enter code here
公共子构建内容(ByVal slno作为字符串)
将strXML设置为字符串
Dim fs As System.IO.FileStream=无
Dim bw As System.IO.BinaryWriter=无
Dim Buffer()作为字节
'fs=New System.IO.FileStream(“kpilert10.pdf”,IO.FileMode.Create)
'bw=新的System.IO.BinaryWriter(fs)
'Response.ContentType=“application/vnd.adobe.xdp+xml”
'
'常数XPD头
'
strXML=“”
strXML=strXML&“
strXML=strXML&“
strXML=strXML&“
strXML=strXML&“
'
'在此处放置代码以获取当前登录的用户ID
'并对后端数据库执行查询并按ID进行筛选
'然后使用结果记录集生成以下XML数据…等等。
'
strXML=strXML&“我爱我,我爱我,我爱我”
'
'
'
strXML=strXML&“
strXML=strXML&“
'
'将XPD指向在Adobe LiveCycle Designer下创建的PDF表单
'
将内容设置为字符串
contents=EncodeFile(“kpiAlert.pdf”)
'Buffer=Convert.FromBase64String(内容)
strXML=strXML&“
strXML=strXML&“
strXML=strXML&&contents&=
strXML=strXML&“
strXML=strXML&“
'strXML=strXML&“”
'
'关闭XPD文件
'
strXML=strXML&“
将outfile用作新的StreamWriter(“kpilert_u3;”和slno&“.pdf”)
Write(strXML.ToString())
终端使用
端接头
函数EncodeFile(ByVal srcFile作为字符串)作为字符串
Dim srcBT作为字节()
将dest变暗为字符串
将sr作为新的IO.FileStream(srcFile、IO.FileMode.Open)
ReDim srcBT(sr.长度)
sr.Read(srcBT,0,sr.Length)
高级关闭()
dest=EncodeByte(srcBT)
返回目的地
端函数
在这里输入代码
函数EncodeByte(ByVal bt()作为字节)作为字符串 作为字符串的Dim enc enc=System.Convert.tobase64字符串(bt) 返回enc
结束函数

完成此操作时,我也遇到了问题

在VB.net中做类似的事情

使用chunk时似乎不起作用,但如果我使用href和本地文件,它确实起作用

测试示例

Public Sub BuildContent(ByVal slno As String)

    Dim strXML As String

    Dim fs As System.IO.FileStream = Nothing
    Dim bw As System.IO.BinaryWriter = Nothing
    Dim Buffer() As Byte
    'fs = New System.IO.FileStream("kpiAlert10.pdf", IO.FileMode.Create)
    'bw = New System.IO.BinaryWriter(fs)
    'Response.ContentType = "application/vnd.adobe.xdp+xml"
    '
    ' Constant XPD Header
    '
    strXML = "<?xml version='1.0' encoding='UTF-8'?>"
    strXML = strXML & "<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>"
    strXML = strXML & "<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>"
    strXML = strXML & "<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>"
    strXML = strXML & "<xfa:data>"
    '
    ' Place code here to get the current Logged in user ID
    ' and perform a query to the back end database and filter by ID
    ' then generate the following XML Data using the resultant Recordset ...etc.
    '

    strXML = strXML & "<transaction><kpi><name>Ego ille</name><data><sn>Si manu vacuas</sn><amt>Apros tres et quidem</amt><delta>Mirum est</delta></data></kpi></transaction>"
    '
    '
    '
    strXML = strXML & "</xfa:data>"
    strXML = strXML & "</xfa:datasets>"
    '
    ' Point the XPD to the PDF Form created under Adobe LiveCycle Desinger
    '
    Dim contents As String

    contents = EncodeFile("kpiAlert.pdf")
    'Buffer = Convert.FromBase64String(contents)
    strXML = strXML & "<pdf xmlns='http://ns.adobe.com/xdp/pdf/'>"
    strXML = strXML & "<document>"
    strXML = strXML & "<chunk>" & contents & "=</chunk>"
    strXML = strXML & "</document>"
    strXML = strXML & "</pdf>"

    'strXML = strXML & "<pdf href='C:/kpiAlert.pdf' xmlns='http://ns.adobe.com/xdp/pdf/' />"
    '
    ' Close the XPD File
    '
    strXML = strXML & "</xdp:xdp>"

    Using outfile As New StreamWriter("kpiAlert_" & slno & ".pdf")
        outfile.Write(strXML.ToString())
    End Using

End Sub

Function EncodeFile(ByVal srcFile As String) As String

    Dim srcBT As Byte()
    Dim dest As String
    Dim sr As New IO.FileStream(srcFile, IO.FileMode.Open)
    ReDim srcBT(sr.Length)
    sr.Read(srcBT, 0, sr.Length)
    sr.Close()
    dest = EncodeByte(srcBT)
    Return dest

End Function

enter code here
公共子构建内容(ByVal slno作为字符串)
将strXML设置为字符串
Dim fs As System.IO.FileStream=无
Dim bw As System.IO.BinaryWriter=无
Dim Buffer()作为字节
'fs=New System.IO.FileStream(“kpilert10.pdf”,IO.FileMode.Create)
'bw=新的System.IO.BinaryWriter(fs)
'Response.ContentType=“application/vnd.adobe.xdp+xml”
'
'常数XPD头
'
strXML=“”
strXML=strXML&“
strXML=strXML&“
strXML=strXML&“
strXML=strXML&“
'
'在此处放置代码以获取当前登录的用户ID
'并对后端数据库执行查询并按ID进行筛选
'然后使用结果记录集生成以下XML数据…等等。
'
strXML=strXML&“我爱我,我爱我,我爱我”
'
'
'
strXML=strXML&“
strXML=strXML&“
'
'将XPD指向在Adobe LiveCycle Designer下创建的PDF表单
'
将内容设置为字符串
contents=EncodeFile(“kpiAlert.pdf”)
'Buffer=Convert.FromBase64String(内容)
strXML=strXML&“
strXML=strXML&“
strXML=strXML&&contents&=
strXML=strXML&“
strXML=strXML&“
'strXML=strXML&“”
'
'关闭XPD文件
'
strXML=strXML&“
将outfile用作新的StreamWriter(“kpilert_u3;”和slno&“.pdf”)
Write(strXML.ToString())
终端使用
E
<pdf xmlns=\"http://ns.adobe.com/xdp/pdf/\">
<?xml version="1.0" encoding="UTF-8"?>
<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
  <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
    <xfa:data>
      <PlannedCycles>999</PlannedCycles>
      <cyclenumber>1</cyclenumber>
      <ConsultantName>Dr Jonathon Hogan-Doran</ConsultantName>
      <Name>SMITH, Bob</Name>
      <URN>9795240</URN>
      <DOB>14/04/1901</DOB>
      <ward>CDCO</ward>
      <ht>100</ht>
      <wt>99</wt>
      <Diagnosis>Metastatic Adenocarcinoma</Diagnosis>
      <chemoD1>17/06/2015</chemoD1>
    </xfa:data>
  </xfa:datasets>
  <pdf xmlns="http://ns.adobe.com/xdp/pdf/" href="\\xxxxxxx.gov.au\Medical Oncology\Chemotherapy Scripts\S\SMITH, Bob- (75240) - dob 14.04.1901 - Capecitabine with Bevacizumab - Cycle 1.pdf"/>
</xdp:xdp>