| |
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
|
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CatalogSubreport.aspx.cs" Inherits="Aspose.Pdf.Demos.NorthwindForms.CatalogSubreportForm" MasterPageFile="~/tpl/Demo.Master"
Title="Catalog Subreport - 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 product catalog sub-report 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 CatalogSubreportForm : 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;
CatalogSubreport catalogSubreport = new CatalogSubreport(path);
pdf = catalogSubreport.GetCatalogSubreport();
pdf.Save("catalogsubreport.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
|
/////////////////////////////////////////////////////////////////////////
// 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.Data;
using System.Data.OleDb;
using System.Globalization;
namespace Aspose.Pdf.Demos
{
/// <summary>
/// Summary description for CatalogSubreport.
/// </summary>
public class CatalogSubreport
{
private OleDbCommand oleDbSelectCommand1;
private OleDbDataAdapter oleDbDataAdapter1;
private OleDbConnection oleDbConnection;
private DataTable dataTable1;
string path;
NumberFormatInfo format;
public CatalogSubreport(string curPath)
{
path = curPath;
format = new NumberFormatInfo();
format.CurrencyPositivePattern = 0;
format.CurrencySymbol = "$";
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 GetCatalogSubreport()
{
string queryString = "SELECT DISTINCTROW Products.ProductName, Products.ProductID, " +
"Products.QuantityPerUnit, Products.UnitPrice FROM Categories INNER JOIN Products ON " +
"Categories.CategoryID = Products.CategoryID ORDER BY Products.ProductName;";
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\\CatalogSubreport.xml";
pdf.BindXML(xmlFile, null);
Section section = pdf.Sections["section1"];
Table table1 = (Table)section.Paragraphs["table1"];
this.oleDbSelectCommand1.CommandText = queryString ;
dataTable1 = new DataTable();
this.oleDbDataAdapter1.Fill(dataTable1);
table1.DefaultCellTextInfo.FontSize = 10;
table1.DefaultCellPadding.Top = 5;
table1.ImportDataTable(dataTable1,false,0,0);
foreach(Row curRow in table1.Rows)
{
double price = Convert.ToDouble(((Aspose.Pdf.Generator.Text)curRow.Cells[3].Paragraphs[0]).Segments[0].Content);
((Aspose.Pdf.Generator.Text)curRow.Cells[3].Paragraphs[0]).Segments[0].Content = price.ToString("C", format);
((Aspose.Pdf.Generator.Text)curRow.Cells[3].Paragraphs[0]).TextInfo.Alignment = AlignmentType.Right;
((Aspose.Pdf.Generator.Text)curRow.Cells[0].Paragraphs[0]).Segments[0].TextInfo.FontName = "Times-Bold";
}
this.oleDbDataAdapter1.Dispose();
this.oleDbConnection.Close();
return pdf;
}
}
}
|
|
|
|