iTextSharp的 - XFA填充日期/时间字段 [英] iTextSharp - XFA fill date/time field

查看:220
本文介绍了iTextSharp的 - XFA填充日期/时间字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的工作流程是这样的:


  1. 我们下载一个模板的形式,这将是静态的预填充值,导出XML模板

  2. 在分析XML与.NET应用程序的形式,动态值添加

  3. 生成的XML需要被重新导入PDF模板

一切顺利的使用以及对iTextSharp的的MergeXfaData方法,但是由于某些原因,日期/时间字段没有被填充(文本框和复选框工作确定)。想不通为什么。搜索通过论坛,我发现有人说:XFA仅适用于文本框。这是为什么,以及如何解决?

All goes well using the MergeXfaData method on iTextSharp, however for some reason, date/time fields are not being filled in (textfields and checkboxes work ok). Cannot figure out why. Searching through forums I discovered someone saying XFA only works for textfields. Why is this and how to work around?

另外,作为下一步我将需要一个附件附加到PDF格式。附件也PDF但iTextSharp的不重视他们。已搜查许多论坛,但没有一个提到的方法为我工作。

Also as a next step I will need to attach an attachment to the PDF form. The attachments are also PDF but iTextSharp would not attach them. Have searched many forums but none of the mentioned methods works for me.

感谢您的答案

推荐答案

@Yuri,我只是一个日期/时间字段试了一下它完美地工作。我创建在Live周期一个简单的PDF有两个字段,1文本和1日期/时间,和两个按钮,提交和打印。样本PDF是这里

@Yuri, I just tried it with a date/time field and it worked perfectly. I create a simple PDF in Live Cycle with two fields, 1 text and 1 date/time, and two buttons, Submit and Print. The sample PDF is here:

我填了表格,得到这个为XML:

I filled out the form and got this for XML:

<?xml version="1.0" encoding="UTF-8"?>
<topmostSubform>
    <Text1>Chris</Text1>
    <DateTimeField1>2012-04-12</DateTimeField1>
</topmostSubform>

当我导入到PDF和观看在Acrobat PDF中的日期/时间域充满了。我使用iTextSharp的5.0.5.0用下面的代码:

When I imported it into the PDF and viewed the PDF in Acrobat the date/time field was filled out. I'm using iTextSharp 5.0.5.0 with the following code:

Option Explicit On
Option Strict On

Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.IO

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim PDF_Input_File As String = Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "Input.pdf")
        Dim PDF_Output_File As String = Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "Export.pdf")

        ''//Create our reader
        Dim reader As New PdfReader(PDF_Input_File)
        ''//Create our file stream to output to
        Using FS As New System.IO.FileStream(PDF_Output_File, FileMode.Create, FileAccess.Write, FileShare.Read)
            ''//Create the stamper
            Dim stamper As New PdfStamper(reader, FS)

            ''//Just loading the XML raw instead of reading from disk, less files to attach to the post
            Dim Bytes = System.Text.Encoding.UTF8.GetBytes("<?xml version=""1.0"" encoding=""UTF-8""?><topmostSubform><Text1>Chris</Text1><DateTimeField1>2012-04-12</DateTimeField1></topmostSubform>")
            Using MS As New MemoryStream(Bytes)
                ''//Fill out the form
                stamper.AcroFields.Xfa.FillXfaForm(MS)
            End Using

            stamper.Close()
        End Using

        reader.Close()


        Me.Close()
    End Sub
End Class

这篇关于iTextSharp的 - XFA填充日期/时间字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆