| |
 |
Fill PDF Form using XML - Aspose.Pdf.Kit |
 |
This demo shows, how to Fill form Fields by importing contents of XML document.
Using ImportXml method in Form class of Aspose.Pdf.Kit component, developers can import values from XML file to fill form fields over Pdf document.
For more related information, please visit Import and Export into XML
Click Import to see how demo takes input PDF document
and fills its form fields by importing a XML File. Results
of this operation can be donwloaded by user for review.
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<%@ Page Language="C#" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="ImportXml.aspx.cs" Inherits="Aspose.Pdf.Kit.Demos.ImportXml"
Title="Fill Pdf Form using XML - Aspose.Pdf.Kit Demos" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table width="90%" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="19"><img src="../../../../Common/images/heading_lft.jpg" alt="" width="19" height="41" /></td>
<td width="100%" class="demos-heading-bg"><h2 class="demos-heading-bg"> Fill PDF Form using XML - Aspose.Pdf.Kit</h2></td>
<td width="19"><img src="../../../../Common/images/heading_rt.jpg" alt="" width="19" height="41" /></td>
</tr>
<tr> </tr>
</table>
<p class="MsoNormal"><font size=2 face="Arial" ><span style="color:black" >This demo shows, how to <b> Fill form Fields</b> by importing contents of XML document.
<br><br>Using <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/aspose.pdf.kit.form.importxml.html> ImportXml </a> method in <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/aspose.pdf.kit.form.html> Form </a> class of Aspose.Pdf.Kit component, developers can import values from XML file to fill form fields over Pdf document.
<br><br>
For more related information, please visit <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/import-and-export-into-xml.html>Import and Export into XML </a><br><br><br></span>
<p class="componentDescriptionTxt">
Click <b>Import</b> to see how demo takes <a href="./resources/student.pdf">input PDF document</a>
and fills its form fields by importing a <a href="./resources/student.xml">XML File</a>. Results
of this operation can be donwloaded by user for review.
</p>
<asp:Button ID="btnImport" runat="server" Text="Import" OnClick="btnImport_Click" />
<p><br><br><br><br><br><br><br><br><br></p>
</asp:Content>
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Aspose.Pdf.Kit.Demos
{
public partial class ImportXml : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnImport_Click(object sender, EventArgs e)
{
// input pdf file that contains form fields
string templatePdf = GetResource(@"student.pdf");
string xml = GetResource(@"student.xml");
//Add a new HTML header and value to the response sent to the client
Response.AddHeader("content-disposition", "inline; filename=" + "studentOut.pdf");
// Specify the HTTP content type for response as Pdf
Response.ContentType = "application/pdf";
// call ImportXml method of FormDemos class to fill the form fields with values from input xml file
FormDemos.ImportXml(templatePdf, xml, Response.OutputStream);
//end the processing of the current page to ensure that no other HTML content is sent
Response.End();
}
}
}
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
using System;
using System.IO;
using Aspose.Pdf.Kit;
namespace Aspose.Pdf.Kit.Demos
{
public class FormDemos
{
public FormDemos()
{
#if SITE_BUILD
// NOTE that in production you would want to call
// new License().SetLicense("path-to-license-file")
try
{
Aspose.Demos.Common.WebOperationsBridge.InitLicense(new License());
}catch
{
;
}
#endif
}
public static void FillFields(string path, string templatePdf, System.IO.Stream outputStream)
{
Form form = new Form(templatePdf, outputStream);
//Fill the field "Name" with "Mike".
form.FillField("Name","Mike");
//Choose the field "Gender" with "Male".
form.FillField("Gender","Male");
//Fill the field "Telephone".
form.FillField("Telephone","888.277.6734");
//Fill the field "Address".
form.FillField("Address","41, Lily Street, Hurstville, NSW, 2220 Australia ");
//Choose the item "GradeTwo" of the Combo field "Grade".
form.FillField("Grade","GradeTwo");
//use case for checking the checkbox "Lodging".
//form.FillField("Lodging","Yes");
//use case for unchecking the checkbox "Lodging".
form.FillField("Lodging","Off");
//Fill the image button field.
form.FillImageField("Photo", BasePage.GetResource(@"lovely.jpg"));
form.Save();
}
public static void ImportFdf(string templatePdf, string fdf,System.IO.Stream outputStream)
{
//Assign an input pdf file.
Form form = new Form(templatePdf, outputStream);
//Open an existed fdf file.
System.IO.FileStream fdfInputStream = new FileStream(fdf, FileMode.Open);
//Export all the pdf fields' value into the fdf file.
form.ImportFdf(fdfInputStream);
form.Save();
fdfInputStream.Close();
}
public static void ExportFdf(string templatePdf, System.IO.Stream outputStream)
{
//Assign an input pdf file.
Form form = new Form(templatePdf);
//Export all the pdf fields' value into the fdf file.
form.ExportFdf(outputStream);
}
public static void ImportXml(string templatePdf, string xml, System.IO.Stream outputStream)
{
//Assign an input pdf file.
Form form = new Form(templatePdf, outputStream);
//Open an existed fdf file.
System.IO.FileStream xmlInputStream = new FileStream(xml, FileMode.Open);
//Export all the pdf fields' value into the fdf file.
form.ImportXml(xmlInputStream);
form.Save();
xmlInputStream.Close();
}
public static void ExportXml(string templatePdf, System.IO.Stream outputStream)
{
//Assign an input pdf file.
Form form = new Form(templatePdf);
//Export all the pdf fields' value into the fdf file.
form.ExportXml(outputStream);
}
}
}
|
|
|
|