首页 文章

使用XDP填充PDF

提问于
浏览
2

我有一个填充PDF,过去常常使用一个简单的XFDF文件来填充 . 使用VS.NET 2010我读入了XFDF文档并填充了所有必要的信息,并使用ds.WriteXML(XFDFName)填充PDF . XFDF通过Process.Start(XFDFName)编写和启动 . 这都在WinForms应用程序中 . 这种方法几年来一直像冠军一样 . 到现在...

我遇到的问题是由于文件是在Adobe LiveCycle中创建的,我无法将数据导出为XFDF格式 . 我注意到导出选项是(1)XML或(2)XDP . 在过去,我已经能够出口到XFDF . 没想到,只是另一种格式 . 但是,我一直在努力解决这两个问题 . 经过一番商议后,我决定使用XDP格式 .

我有我需要的所有信息构建的数据集,我在使用Process.Start(XDPName)打开新创建的XDP时收到错误 . 阅读器打开,我收到以下错误:"Adobe Reader could not open 'GUID_HERE.xdp' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."

我尝试使用直接href到PDF,这也不起作用 . 所以我选择在序列中将序列化的PDF粘贴在XDP中 .

此XDP文件如下所示(thanks Dean J):

<?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>
           XML is here - matching the dynamic fields in the PDF.
        </xfa:data>
    </xfa:datasets>
    <pdf xmlns=\"http://ns.adobe.com/xdp/pdf/\"><document>
       <chunk>
          Base64 encoded PDF
       </chunk>
    </document></pdf>
</xdp:xdp>

我认为我生成的XDP是假的 - 但是为了进一步复杂化 - 如果我打开Reader,请单击工具>表单>更多表单选项>管理表单数据>导入数据并选择我生成的XDP文件,所有字段按我预期的那样填充 .

所以基本上,某处显然存在脱节:我有一个XDP文件,其中包含我需要的所有信息 . 我有一个PDF表单,我需要填充XDP文件 . XDP中的信息正确匹配PDF中的所有控件名称 . 但是,当我启动XDP文件时,Reader告诉我它已损坏/不受支持 . 据我了解,当你启动XDP文件时,它应该使用Reader正确启动/填充,对吗?

任何信息都会帮助我 . 谢谢 .

3 回答

  • 0

    我也遇到了这个问题......

    在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
    

    函数EncodeByte(ByVal bt()As Byte)As String Dim enc As String enc = System.Convert.ToBase64String(bt)return enc End Function

  • 0

    我还要感谢Dean J的出色答案 . 我之前使用它,它为商业iText许可证或LiveCycle服务器节省了大量的时间和金钱 . 在引用的代码中,有一个转义的字符串:

    <pdf xmlns=\"http://ns.adobe.com/xdp/pdf/\">
    

    请注意双引号前的反斜杠 . 那些不应该在你的XML中,因为它会使它无效 . 有可能Dean J实际上拥有C#或PHP中的所有代码,因此需要为他转义引号 .

  • 0

    不确定这是否相关,但是在不同情况下在VBA中处理合并子例程时,我在打开XDP文件方面存在不一致 . 有时它会起作用,有时则不行 .

    最终我注意到当Adobe Acrobat(正确 - 不是Reader)已经打开或设置为PDF的默认设置时发生这种情况,并且无论出于什么原因试图打开XDP而不是Adobe Reader .

    以下XML适用于我:

    <?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>
    

相关问题