| |
 |
Adhere Text/Image to PDF - Aspose.Pdf.Kit |
 |
This demo Adheres Image and Text, to the input Pdf document, based over users selection.
Using AddText method in PdfFileMend class of Aspose.Pdf.Kit component, developers can adhere formatted text to any page of the PDF document, at any specified location. Using AddImage it also enables developers to adhere image (in Jpg, Gif or Png formats) at any specified location in a specified page number of the PDF document.
For more information, on how to Adhere Text, please visit Adhere Text.
For more information, on how to Adhere Image, please visit Adhere Image.
Click Adhere to see how demo takes inpurt PDF file
and adds text and an image, sending
resulting document to user for review.
the image and text at specified pages.
| 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
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
107
108
109
110
111
112
113
114
115
116
|
<%@ Page language="c#" Codebehind="PdfFileMend.aspx.cs" AutoEventWireup="false"
Inherits="Aspose.Pdf.Kit.Demos.PdfFileMendDemo"
MasterPageFile="~/tpl/Demo.Master"
Title="Adhere Text/Image to Pdf - Aspose.Pdf.Kit Demos"
%>
<%@ Register TagPrefix="dem" Assembly="Aspose.Demos.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ab721518795be73e" Namespace="Aspose.Demos.Common.HtmlControls" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
<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"> Adhere Text/Image to PDF - 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 <b> Adheres</b> Image and Text, to the input Pdf document, based over users selection.
<br><br>Using <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/aspose.pdf.kit.pdffilemend.addtext_overloads.html> AddText </a> method in <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/aspose.pdf.kit.pdffilemend.html> PdfFileMend </a> class of Aspose.Pdf.Kit component, developers can adhere formatted text to any page of the PDF document, at any specified location. Using <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/aspose.pdf.kit.pdffilemend.addimage_overloads.html> AddImage </a> it also enables developers to adhere image (in Jpg, Gif or Png formats) at any specified location in a specified page number of the PDF document.
<br><br>
For more information, on how to Adhere Text, please visit <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/adhere-text.html>Adhere Text.</a>
<br>
For more information, on how to Adhere Image, please visit <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/adhere-image.html>Adhere Image.</a> <br></span>
<p class="componentDescriptionTxt">
Click <b>Adhere</b> to see how demo takes <a href="./resources/Aspose.Pdf.Kit.pdf">inpurt PDF file</a>
and adds text and an <a href="./resources/butterfly.jpg">image</a>, sending
resulting document to user for review.
</p>
<table class="genericTable">
<tr>
<td>
<asp:label id="Label1" runat="server">Coordinates of the</asp:label>
<dem:HyperLinkRes id="HyperLink1" runat="server" NavigateUrl="..\resources\imglogopdfkit.gif">image</dem:HyperLinkRes>
</td>
<td>
<asp:label id="Label2" runat="server">Coordinates of</asp:label>
<asp:textbox id="TextBox5" runat="server" Width="174px">Aspose.Pdf.Kit-PdfFileMend</asp:textbox>
</td>
<td>
<asp:label id="Label3" runat="server" Width="185px">At which pages are added</asp:label>
</td>
</tr>
<tr>
<td>
<table class="genericTable" id="Table1" width="230" align="center" border="1">
<tr>
<th scope="col" width="96">
Coordinates ff</th>
<th scope="col" width="88">
Value</th></tr>
<tr>
<td><em><strong>LowerLeftX</strong></em></td>
<td><asp:textbox id="LowLeftX1" tabIndex="1" runat="server" ToolTip="Please input your new Title"
Width="129px" AutoPostBack="True">100</asp:textbox></td>
</tr>
<tr>
<td><em><strong>LowerLeftY</strong></em></td>
<td><asp:textbox id="LowLeftY1" tabIndex="2" runat="server" ToolTip="Please input your new Author"
Width="128px" AutoPostBack="True">100</asp:textbox></td>
</tr>
<tr>
<td><em><strong>UpperRightX</strong></em></td>
<td><asp:textbox id="UpRightX1" tabIndex="3" runat="server" ToolTip="Please input your new Subject"
Width="126px" AutoPostBack="True">150</asp:textbox></td>
</tr>
<tr>
<td><em><strong>UpperRightY</strong></em></td>
<td><asp:textbox id="UpRightY1" tabIndex="4" runat="server" ToolTip="Please input your new Keywords"
Width="128px" AutoPostBack="True">150</asp:textbox></td>
</tr>
</table>
</td>
<td>
<table class="genericTable" id="Table2" width="230" align="center" border="1">
<tr>
<th scope="col" width="96">
Coordinates</th>
<th scope="col" width="88">
Value</th></tr>
<tr>
<td><em><strong>LowerLeftX</strong></em></td>
<td><asp:textbox id="LowLeftX2" tabIndex="1" runat="server" ToolTip="Please input your new Title"
Width="129px" AutoPostBack="True">200</asp:textbox></td>
</tr>
<tr>
<td><em><strong>LowerLeftY</strong></em></td>
<td><asp:textbox id="LowLeftY2" tabIndex="2" runat="server" ToolTip="Please input your new Author"
Width="128px" AutoPostBack="True">200</asp:textbox></td>
</tr>
<tr>
<td><em><strong>UpperRightX</strong></em></td>
<td><asp:textbox id="UpRightX2" tabIndex="3" runat="server" ToolTip="Please input your new Subject"
Width="126px" AutoPostBack="True">400</asp:textbox></td>
</tr>
<tr>
<td><em><strong>UpperRightY</strong></em></td>
<td><asp:textbox id="UpRightY2" tabIndex="4" runat="server" ToolTip="Please input your new Keywords"
Width="128px" AutoPostBack="True">220</asp:textbox></td>
</tr>
</table>
</td>
<td>
<asp:checkboxlist id="CheckBoxList1" runat="server" CssClass="genericList">
<asp:ListItem Value="1" Selected="True">at page 1</asp:ListItem>
<asp:ListItem Value="2">at page 2</asp:ListItem>
<asp:ListItem Value="3">at page 3</asp:ListItem>
<asp:ListItem Value="4">at page 4</asp:ListItem>
<asp:ListItem Value="5">at page 5</asp:ListItem>
</asp:checkboxlist>
</td>
</tr>
</table>
<asp:button id="Button1" runat="server" Text="Adhere" ToolTip="Click to insert" Width="58px"></asp:button> the image and text at specified pages.
</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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Globalization;
using Aspose.Pdf.Kit;
namespace Aspose.Pdf.Kit.Demos
{
/// <summary>
/// PdfFileMend demo
/// </summary>
public class PdfFileMendDemo : BasePage
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.CheckBoxList CheckBoxList1;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox LowLeftX2;
protected System.Web.UI.WebControls.TextBox LowLeftY2;
protected System.Web.UI.WebControls.TextBox UpRightX2;
protected System.Web.UI.WebControls.TextBox UpRightY2;
protected System.Web.UI.WebControls.TextBox LowLeftX1;
protected System.Web.UI.WebControls.TextBox LowLeftY1;
protected System.Web.UI.WebControls.TextBox UpRightX1;
protected System.Web.UI.WebControls.TextBox UpRightY1;
protected System.Web.UI.HtmlControls.HtmlGenericControl Font1;
private void Page_Load(object sender, System.EventArgs e)
{
//Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
//CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
// input file to which Image and Text will be adhered
string inFile = GetResource("Aspose.Pdf.Kit.pdf");
FileStream inStream = new FileStream(inFile, FileMode.Open, FileAccess.Read, FileShare.Read);
MemoryStream outStream = new MemoryStream();
// Create and instance of PdfFileMend which is used to adhere text and Image to pdf
PdfFileMend mend = new PdfFileMend(inStream, outStream);
//at which pages are added
int[] pages;
ArrayList pageList = new ArrayList();
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
pageList.Add(i + 1);
}
}
if (pageList.Count > 0)
{
pages = new int[pageList.Count];
pageList.CopyTo(pages);
}
else
{
return;
}
CultureInfo enCulture = new CultureInfo("");
float d = Single.Parse("0.78431", enCulture);
//add image
float lowLeftX1 = Convert.ToSingle(LowLeftX1.Text, enCulture);
float lowLeftY1 = Convert.ToSingle(LowLeftY1.Text, enCulture);
float upRightX1 = Convert.ToSingle(UpRightX1.Text, enCulture);
float upRightY1 = Convert.ToSingle(UpRightY1.Text, enCulture);
// Image file that will be adhered to pdf
string inImage = GetResource("imgLogoPDFKit.gif");
FileStream imageStream = new FileStream(inImage, FileMode.Open, FileAccess.Read, FileShare.Read);
// Adhere Image to specified of input pdf file over specified coordinates
mend.AddImage(imageStream, pages, lowLeftX1, lowLeftY1, upRightX1, upRightY1);
//add text
float lowLeftX2 = Convert.ToSingle(LowLeftX2.Text, enCulture);
float lowLeftY2 = Convert.ToSingle(LowLeftY2.Text, enCulture);
float upRightX2 = Convert.ToSingle(UpRightX2.Text, enCulture);
float upRightY2 = Convert.ToSingle(UpRightY2.Text, enCulture);
// Formated Text to be adhered
FormattedText fText = new FormattedText(TextBox5.Text, new FontColor(0, 0, 200), FontStyle.TimesRoman,
EncodingType.Winansi, false, 15);
// Adhere text to specified pages of input pdf file over specified coordinated
mend.AddText(fText, pages, lowLeftX2, lowLeftY2, upRightX2, upRightY2);
//close
mend.Close();
// create a byte array that will hold the output pdf
byte[] outBuf = outStream.GetBuffer();
// specify the duration of time before a page,cached on a browser expires
Response.Expires = 0;
// Specify the property to buffer the output page
Response.Buffer = true;
// Erase any buffered HTML output
Response.ClearContent();
//Add a new HTML header and value to the response sent to the client
Response.AddHeader("content-disposition", "inline; filename=" + "output.pdf");
// Specify the HTTP content type for response as Pdf
Response.ContentType = "application/pdf";
// Write specified information of current HTTP output to Byte array
Response.BinaryWrite(outBuf);
// close the output stream
outStream.Close();
//end the processing of the current page to ensure that no other HTML content is sent
Response.End();
}
}
}
|
|
|
|