| |
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
|
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerLabelsForm.aspx.cs" Inherits="Aspose.Pdf.Demos.NorthwindForms.CustomerLabelsForm" MasterPageFile="~/tpl/Demo.Master"
Title="Customer Labels - Aspose.Pdf Demos"%>
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server">
<p class="componentDescriptionTxt">
Click <b>Process</b> to see how example
generates document with customer labels based on Northwind database data
<br/>You can either open the resulting PDF file into your PDF reader
or save directly to your disk.
</p>
<asp:Button ID="btnProcess" runat="server" Text="Process" OnClick="btnProcess_Click" />
</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
|
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;
using Aspose.Pdf.Generator;
namespace Aspose.Pdf.Demos.NorthwindForms
{
public partial class CustomerLabelsForm : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnProcess_Click(object sender, EventArgs e)
{
string path = GetResource(string.Empty); // Database is under RESOURCES
Aspose.Pdf.Generator.Pdf pdf;
CustomerLabels customerLabels = new CustomerLabels(path);
pdf = customerLabels.GetCustomerLabels();
pdf.Save("customerlabels.pdf", SaveType.OpenInAcrobat, Response);
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
|
/////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2005 Aspose Pty Ltd. All rights reserved.
//
// This file is part of Aspose.Pdf. The source code in this file
// is only intended as a supplement to the documentation, and is provided
// "as is", without warranty of any kind, either expressed or implied.
/////////////////////////////////////////////////////////////////////////
using System;
using Aspose.Pdf.Generator;
using System.Data;
using System.Data.OleDb;
namespace Aspose.Pdf.Demos
{
/// <summary>
/// Summary description for CustomerLabels.
/// </summary>
public class CustomerLabels
{
private OleDbCommand oleDbSelectCommand1;
private OleDbDataAdapter oleDbDataAdapter1;
private OleDbConnection oleDbConnection;
private DataTable dataTable1;
string path;
public CustomerLabels(string curPath)
{
path = curPath;
this.oleDbConnection = new System.Data.OleDb.OleDbConnection();
this.oleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path +
"\\Database\\Northwind.mdb";
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand1.Connection = this.oleDbConnection;
this.oleDbDataAdapter1 = new OleDbDataAdapter();
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
this.oleDbConnection.Open();
}
public Aspose.Pdf.Generator.Pdf GetCustomerLabels()
{
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
pdf.IsTruetypeFontMapCached = false;
// If you have purchased a license,
// Set license like this:
// string licenseFile = MapPath("License") + "\\Aspose.Pdf.lic";
// Aspose.Pdf.License lic = new Aspose.Pdf.License();
// lic.SetLicense(licenseFile);
string xmlFile = path + "\\Xml\\CustomerLabels.xml";
pdf.BindXML(xmlFile, null);
Section section = pdf.Sections["section1"];
Table table1 = (Table)section.Paragraphs["table1"];
this.oleDbSelectCommand1.CommandText =
"SELECT CompanyName, Address, City, Region, PostalCode, Country, CustomerID FROM C" +
"ustomers ORDER BY Country, CompanyName";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
string[] strArr = new string[dataTable1.Rows.Count];
DataRow curRow;
for(int i=0; i<dataTable1.Rows.Count; i++)
{
curRow = dataTable1.Rows[i];
strArr[i] = curRow[0].ToString() + "#$NL" + curRow[1].ToString() + "#$NL" +
curRow[2].ToString() + " " + curRow[3].ToString() + " " +
curRow[4].ToString() + "#$NL" + curRow[5].ToString();
}
table1.DefaultCellTextInfo.FontSize = 10;
table1.ImportArray(strArr,0,0,false);
foreach(Row cRow in table1.Rows)
{
foreach(Cell curCell in cRow.Cells)
{
curCell.Padding = new MarginInfo();
curCell.Padding.Top = 10;
}
}
this.oleDbDataAdapter1.Dispose();
this.oleDbConnection.Close();
return pdf;
}
}
}
|
|
|
|