| |
 |
Stamp Watermark to PDF - Aspose.Pdf.Kit |
 |
 
This demo Stamps Image or Text, over the input Pdf document, based over users selection.
Using AddStamp method in PdfFileStamp class of Aspose.Pdf.Kit component, developers can add watermark in the form of image (Jpg, Gif and Png) on each page/selected pages of Pdf file, at any specified location. Not even images, PdfFileStamp provides the flexibility to add Formatted text String as Logo over each page/selected pages of the PDF document, at any specified location.
Using PdfFileStamp, image can also be set as background to the Pdf document. Set the value for IsBackground property to True before calling AddStamp.
For more information, on how to add Text Logo, please visit Add Logo.
For more information, on how to set watermark, please visit Add Watermark.
For more information, on how to set background, please visit Add Background.
Choose text, message size and placement and/or image placement details and click
Submit to see how demo takes input PDF file
stamping it with text and/or image
and sends the resulting document to 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
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
|
<%@ Page language="c#" Codebehind="Stamp.aspx.cs" AutoEventWireup="false"
Inherits="Aspose.Pdf.Kit.Demos.PdfStamp"
MasterPageFile="~/tpl/Demo.Master"
Title="Stamp Watermark to Pdf - Aspose.Pdf.Kit Demos"
%>
<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"> Stamp Watermark 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> Stamps </b> Image or Text, over 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.pdffilestamp.addstamp.html> AddStamp </a> method in <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/aspose.pdf.kit.pdffilestamp.html> PdfFileStamp </a> class of Aspose.Pdf.Kit component, developers can add watermark in the form of image (Jpg, Gif and Png) on each page/selected pages of Pdf file, at any specified location. Not even images, PdfFileStamp provides the flexibility to add Formatted text String as Logo over each page/selected pages of the PDF document, at any specified location.
<br>
Using PdfFileStamp, image can also be set as background to the Pdf document. Set the value for <b> IsBackground </b> property to <b>True </b> before calling AddStamp.
<br><br>
For more information, on how to add Text Logo, please visit <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/add-logo.html>Add Logo.</a>
<br>
For more information, on how to set watermark, please visit <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/add-watermark.html>Add Watermark.</a>
<br>
For more information, on how to set background, please visit <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/add-background.html>Add Background.</a></span>
<p class="componentDescriptionTxt">
Choose text, message size and placement and/or image placement details and click
<b>Submit</b> to see how demo takes <a href="./resources/Aspose.Pdf.Kit.pdf">input PDF file</a>
stamping it with text and/or <a href="./resources/butterfly.jpg">image</a>
and sends the resulting document to user for review.
</p>
<table class="genericTable">
<tr>
<td colspan="2">
An
<asp:HyperLink id="HyperLink1" runat="server" NavigateUrl="..\Resources\butterfly.jpg">image</asp:HyperLink> and
a text are added as watermark, logo or background on the input
<asp:HyperLink id="HyperLink2" runat="server" NavigateUrl="..\Resources\Aspose.Pdf.Kit.pdf">pdf</asp:HyperLink>
here,
</td>
</tr>
<tr>
<td align="left" valign="top">
<asp:RadioButton id="RadioButton1"
runat="server" Checked="True" Text="Add a watermark(layed on top of page)" GroupName="type"></asp:RadioButton>
<br />
<asp:RadioButton id="RadioButton2" runat="server" Text="Add a background(layed behind page)" GroupName="type"></asp:RadioButton>
<br />
<asp:RadioButton id="RadioButton3" runat="server" Checked="True" Text="From the previewed image" GroupName="source"></asp:RadioButton><br />
<asp:Image id="Image1" Height="136px" runat="server" Width="216px" ImageUrl="..\Resources\butterfly.jpg" BorderWidth="2px"></asp:Image>
<br />
<asp:RadioButton id="RadioButton4" runat="server" Width="182px" Text="From text" GroupName="source"></asp:RadioButton><br />
<asp:TextBox id="TextBox1" runat="server" Width="216px" Height="45px">Hello World!</asp:TextBox>
<br />
<asp:Label id="Label7" runat="server" Width="104px" Font-Names="Times New Roman">Page range</asp:Label>
<br />
<asp:CheckBoxList id="CheckBoxList1" runat="server" Width="248px" Height="54px" TextAlign="Left"
BorderStyle="Solid" BorderWidth="1px" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Selected="True">Page 1</asp:ListItem>
<asp:ListItem Value="2" Selected="True">Page 2</asp:ListItem>
<asp:ListItem Value="3" Selected="True">Page 3</asp:ListItem>
<asp:ListItem Value="4" Selected="True">Page 4</asp:ListItem>
<asp:ListItem Value="5" Selected="True">Page 5</asp:ListItem>
</asp:CheckBoxList>
</td>
<td align="left" valign="top">
<table class="genericTable">
<tr>
<td><asp:Label id="Label1" runat="server">Rotation</asp:Label></td>
<td><asp:TextBox id="TextBox2" runat="server" Width="56px">15</asp:TextBox></td>
</tr>
<tr>
<td><asp:Label id="Label2" runat="server">Origin X</asp:Label></td>
<td><asp:TextBox id="TextBox3" runat="server" Width="56px">150</asp:TextBox>px</td>
</tr>
<tr>
<td><asp:Label id="Label3" runat="server">Origin Y</asp:Label></td>
<td><asp:TextBox id="TextBox4" runat="server" Width="56px">200</asp:TextBox>px</td>
</tr>
<tr>
<td colspan="2"><asp:CheckBox id="CheckBox1" runat="server" Text="Using original size"></asp:CheckBox></td>
</tr>
<tr>
<td colspan="2"><asp:Label id="Label14" runat="server">Specified with</asp:Label></td>
</tr>
<tr>
<td><asp:Label id="Label4" runat="server">Width</asp:Label></td>
<td><asp:TextBox id="TextBox5" runat="server" Width="56px">100</asp:TextBox></td>
</tr>
<tr>
<td><asp:Label id="Label5" runat="server">Height</asp:Label></td>
<td><asp:TextBox id="TextBox6" runat="server" Width="56px">100</asp:TextBox></td>
</tr>
<tr>
<td><asp:Label id="Label6" runat="server">Fontsize</asp:Label></td>
<td><asp:TextBox id="TextBox7" runat="server" Width="56px">30</asp:TextBox></td>
</tr>
</table>
</td>
</tr>
</table>
<asp:Button id="Button1" runat="server" Text="Submit" ToolTip="click to submit"></asp:Button>
</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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
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.Globalization;
using System.IO;
using Aspose.Pdf.Kit;
namespace Aspose.Pdf.Kit.Demos
{
/// <summary>
/// PdfStamp demo
/// </summary>
public class PdfStamp : BasePage
{
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.RadioButton RadioButton3;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.RadioButton RadioButton4;
protected System.Web.UI.WebControls.RadioButton RadioButton1;
protected System.Web.UI.WebControls.RadioButton RadioButton2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.CheckBoxList CheckBoxList1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.TextBox TextBox7;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.Label Label13;
protected System.Web.UI.WebControls.CheckBox CheckBox1;
protected System.Web.UI.WebControls.Label Label14;
protected System.Web.UI.HtmlControls.HtmlGenericControl Font1;
private void Page_Load(object sender, System.EventArgs e)
{
}
#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);
}
private void InitializeComponent()
{
this.RadioButton2.CheckedChanged += new System.EventHandler(this.RadioButton2_CheckedChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.CheckBox1.CheckedChanged += new System.EventHandler(this.CheckBox1_CheckedChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
// the input file over which pdf stamp will be applied
string inFile = GetResource("Aspose.Pdf.Kit.pdf");
// the image to be applied as pdf stamp
string imageFile = GetResource("butterfly.jpg");
CultureInfo enCulture = new CultureInfo("");
float d = Single.Parse("0.78431", enCulture);
//Read the input pdf file
FileStream inStream = new FileStream(inFile, FileMode.Open, FileAccess.Read, FileShare.Read);
//generate new Pdf file output stream
MemoryStream outStream = new MemoryStream();
// create an instance of PdfFileStamp class that will be used to add stamp to pdf file
PdfFileStamp stamper = new PdfFileStamp(inStream, outStream);
//Create a Stamp object
Stamp aStamp = new Stamp();
if (RadioButton3.Checked)
{
// add image file as stamp content
aStamp.BindImage(imageFile);
}
else if (RadioButton4.Checked)
{
// add text as stamp content
float fontsize = Convert.ToSingle(TextBox7.Text, enCulture);
aStamp.BindLogo(new FormattedText(TextBox1.Text, new FontColor(180, 0, 0), FontStyle.TimesItalic,
EncodingType.Winansi, false, fontsize));
}
if (RadioButton2.Checked)
{
// bool value indicates that content is stamped as background
aStamp.IsBackground = true;
}
else
{
// Stamped content is layed at top
aStamp.IsBackground = false;
}
if (TextBox2.Text != null)
{
float rotation = Convert.ToSingle(TextBox2.Text, enCulture);
// set the rotation value for stamp content
aStamp.Rotation = rotation;
}
if ((TextBox3.Text != null) && (TextBox4.Text != null))
{
float originX = Convert.ToSingle(TextBox3.Text, enCulture);
float originY = Convert.ToSingle(TextBox4.Text, enCulture);
// set the lower-left coordinates of a rectangle which contains stamp content layed on the pages
aStamp.SetOrigin(originX, originY);
}
if ((!CheckBox1.Checked) && (TextBox5.Text != null) && (TextBox6.Text != null))
{
float width = Convert.ToSingle(TextBox5.Text, enCulture);
float height = Convert.ToSingle(TextBox6.Text, enCulture);
// Resizes the image which is bound as stamp content
aStamp.SetImageSize(width, height);
}
int[] pages = null;
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);
}
// pages on which stamp content is added
aStamp.Pages = pages;
//add the Stamp object
stamper.AddStamp(aStamp);
stamper.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();
}
private void RadioButton2_CheckedChanged(object sender, System.EventArgs e)
{
}
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
}
}
}
|
|
|
|