| |
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AlpabeticalListForm.aspx.cs" Inherits="Aspose.Pdf.Demos.NorthwindForms.AlpabeticalListForm" MasterPageFile="~/tpl/Demo.Master"
Title="Alphabetical List of Products - 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 alphabetical list of products 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
32
33
|
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 AlpabeticalListForm : 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;
AlphabeticalList alphabeticalList = new AlphabeticalList(path);
pdf = alphabeticalList.GetAlphabeticalList();
pdf.Save("alphabeticalList.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2011 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.Globalization;
using System.Data;
using System.Data.OleDb;
namespace Aspose.Pdf.Demos
{
/// <summary>
/// Summary description for AlphabeticalList.
/// </summary>
public class AlphabeticalList
{
private OleDbCommand oleDbSelectCommand1;
private OleDbDataAdapter oleDbDataAdapter1;
private OleDbConnection oleDbConnection;
private DataTable dataTable1;
string path;
public AlphabeticalList(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.oleDbDataAdapter1 = new OleDbDataAdapter();
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
this.oleDbSelectCommand1.Connection = this.oleDbConnection;
this.oleDbConnection.Open();
}
public Aspose.Pdf.Generator.Pdf GetAlphabeticalList()
{
char letter = 'A';
string queryString = "SELECT DISTINCTROW Products.ProductName as [Product Name:], " +
"Categories.CategoryName as [Category Name:], Products.QuantityPerUnit as " +
"[Quantity Per Unit:], Products.UnitsInStock as [Units In Stock:]" +
"FROM Categories INNER JOIN Products ON Categories.CategoryID=Products.CategoryID " +
"WHERE (((Products.Discontinued)=No) AND Left(Products.ProductName,1)='";
int num;
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\\AlphabeticalList.xml";
pdf.BindXML(xmlFile, null);
Section section = pdf.Sections["section1"];
Aspose.Pdf.Generator.Text dateText = (Aspose.Pdf.Generator.Text)section.Paragraphs["DateText"];
Segment dateSeg = dateText.Segments["DateSec"];
DateTime dateTime = DateTime.Now;
dateSeg.Content = dateTime.ToString("d",DateTimeFormatInfo.InvariantInfo);
for(num=0;num<26;num++)
{
letter = (char)((int)letter + (num==0?0:1));
this.oleDbSelectCommand1.CommandText = queryString + letter.ToString() +
"') ORDER BY Products.ProductName";
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
if(dataTable1.Rows.Count > 0)
AddTable(pdf,section,letter.ToString(),dataTable1);
}
this.oleDbDataAdapter1.Dispose();
this.oleDbConnection.Close();
return pdf;
}
private void AddTable(Aspose.Pdf.Generator.Pdf pdf, Section sec, string letter, DataTable dt)
{
Table newTable = new Table();
sec.Paragraphs.Add(newTable);
newTable.IsBroken = false;
newTable.DefaultCellTextInfo.FontSize = 10;
newTable.ColumnWidths = "50 160 90 110 70";
newTable.Border = new BorderInfo((int)(BorderSide.Top | BorderSide.Bottom),1F);
Row row1 = newTable.Rows.Add();
row1.Cells.Add(letter);
newTable.ImportDataTable(dt,true,1,1);
foreach(Row curRow in newTable.Rows)
{
if(newTable.Rows.IndexOf(curRow) == 1)
{
foreach(Cell curCell in curRow.Cells)
if(curCell.Paragraphs.Count != 0)
((Aspose.Pdf.Generator.Text)curCell.Paragraphs[0]).Segments[0].TextInfo.FontName = "Times-Bold";
}
if(newTable.Rows.IndexOf(curRow) > 0)
((Aspose.Pdf.Generator.Text)(curRow.Cells[4].Paragraphs[0])).TextInfo.Alignment = AlignmentType.Right;
}
}
}
}
|
|
|
|