| |
| 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
|
<%@ Page language="c#" Codebehind="Insert2.aspx.cs" AutoEventWireup="false"
Inherits="Aspose.Pdf.Kit.Demos.Insert2"
MasterPageFile="~/tpl/Demo.Master"
Title="Insert Pages into 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 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"> Insert Pages into 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> Inserts </b> Pages from one Pdf document into another, based on user input.
<br><br>Using <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/aspose.pdf.kit.pdffileeditor.insert_overloads.html> Insert </a> method in <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/aspose.pdf.kit.pdffileeditor.html> PdfFileEditor</a> class of Aspose.Pdf.Kit component, developers can insert pages at any location of the PDF document.
<br><br>
Fore more information, please visit <a href=http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/insert-pages-into-a-pdf-document.html>Insert Pages into a PDF Document. </a><br><br><br></span>
<p class="componentDescriptionTxt">
Click <b>Insert</b> to see how demo takes <a href="./resources/Aspose.Pdf.Kit.pdf">document 1</a>
and <a href="./resources/Aspose.Pdf.pdf">document 2</a> inserting pages from
one document into the other based on user input. Results of this operation can be donwloaded by user for review.
</p>
<table class="genericTable">
<tr>
<td>Pags chosen from Pdf file2.</td>
<td>Position in Pdf file1.</td>
</tr>
<tr>
<td>
<asp:CheckBoxList id="CheckBoxList1" runat="server" CssClass="genericList">
<asp:ListItem Value="1" Selected="True">page 1 of file2</asp:ListItem>
<asp:ListItem Value="2">page 2 of file2</asp:ListItem>
<asp:ListItem Value="3">page 3 of file2</asp:ListItem>
<asp:ListItem Value="4">page 4 of file2</asp:ListItem>
<asp:ListItem Value="5">page 5 of file2</asp:ListItem>
</asp:CheckBoxList>
</td>
<td>
<asp:RadioButtonList id="RadioButtonList1" runat="server" CssClass="genericList">
<asp:ListItem Value="0" Selected="True">at 1st page</asp:ListItem>
<asp:ListItem Value="1">at 2nd page</asp:ListItem>
<asp:ListItem Value="2">at 3rd page</asp:ListItem>
<asp:ListItem Value="3">at 4th page</asp:ListItem>
<asp:ListItem Value="4">at 5th page</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</table>
<asp:Button id="Button1" runat="server" Text="Insert" ToolTip="Click to insert"></asp:Button>
pages chosen from Pdf file2 into Pdf file1.
</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
|
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;
namespace Aspose.Pdf.Kit.Demos
{
/// <summary>
/// Summary of Insert2 .
/// </summary>
public class Insert2 : BasePage
{
protected System.Web.UI.HtmlControls.HtmlForm KitDemo;
protected System.Web.UI.HtmlControls.HtmlGenericControl Div1;
protected System.Web.UI.HtmlControls.HtmlGenericControl H41;
protected System.Web.UI.HtmlControls.HtmlGenericControl P1;
protected System.Web.UI.WebControls.CheckBoxList CheckBoxList1;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
protected System.Web.UI.WebControls.Button Button1;
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)
{
string path = MapPath(".");
path = path.Substring(0, path.LastIndexOf("\\"));
//get number of page chosen from pdf file2
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;
}
//get the position at pdf file1
int position = 1;
for(int i =0;i<RadioButtonList1.Items.Count; i++)
{
if(RadioButtonList1.Items[i].Selected)
{
position = i +1;
}
}
// Pdf file in which pages need to be inserted
string inputfile1 = GetResource("Aspose.Pdf.Kit.pdf");
// pdf file from which pages will be insterted
string inputfile2 = GetResource("Aspose.Pdf.pdf");
// Create an object of InsertDemo class
InsertDemo ins = new InsertDemo();
// Call Insert method of InsertDemo class to insert pages from source to target pdf
ins.Insert(inputfile1,inputfile2,pages,position,Response);
}
}
}
|
| 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
|
using System;
using System.IO;
using System.Web;
using Aspose.Pdf.Kit;
namespace Aspose.Pdf.Kit.Demos
{
/// <summary>
/// Summary of InsertDemo.
/// </summary>
public class InsertDemo
{
public InsertDemo()
{
#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 void Insert(string inputfile1,string inputfile2,int[] pages,int position,HttpResponse response)
{
// Pdf file to which pages will be inserted
FileStream inStream1 = File.Open(inputfile1,FileMode.Open,FileAccess.Read,FileShare.Read);
// Stream of Pdf file for pages
FileStream inStream2 = File.Open(inputfile2,FileMode.Open,FileAccess.Read,FileShare.Read);
//new a PdfFileEditor object
PdfFileEditor pdfEditor = new PdfFileEditor();
//generate new Pdf file output stream
MemoryStream outStream = new MemoryStream();
//Call Insert method of PdfFileEditor object to insert pages in input streams at specific location
pdfEditor.Insert(inStream1,position,inStream2,pages,outStream);
// 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();
}
}
}
|
|
|
|