Pre-requisites

Please make sure you have completed the steps mentioned on How to extend Spring.Northwind to generate different Northwind reports?

Customer Labels using Aspose.Pdf

Please follow the following steps to add Customer Labels report using Aspose.Pdf

    1. Add sample "CustomerLabels.xml" file in "Spring.Northwind.Web\App_Data\xml" folder. You can find this file in Download package/Source code of this project.
    2. Open "Web.xml" file on the root of "Spring.Northwind.Web" and add the following lines inside objects node
      
        <object type="Pdf/CustomerLabels.aspx">
          <property name="CustomerDao" ref="CustomerDao" />
        </object>
      
    3. Add a new folder named "Pdf" in Spring.Northwind.Web.2010
    4. Add a new ASP.NET page named "CustomerLabels.aspx" in Spring.Northwind.Web.2010\Pdf folder.
    5. Add a link to this "CustomerLabels.aspx" on "Default.aspx" so that you can access it when run the project in browser.
    6. Replace the html with
      
      
      <%@ Page Title="" Language="C#" MasterPageFile="~/Shared/MasterPage.master" AutoEventWireup="true" CodeBehind="CustomerLabels.aspx.cs" Inherits="Spring.Northwind.Web.Pdf.CustomerLabels" %>
      
      <asp:Content ID="Content1" ContentPlaceHolderID="content" runat="server">
      
          <h2>Create Customer Labels report using Aspose.Pdf for .NET</h2>
          <div class="componentDescriptionTxt">
              This demo illustrates how to create a well formatted Customer Labels report by using <a href="http://www.aspose.com/.net/pdf-component.aspx">Aspose.Pdf for .NET.</a>
              <ul class="noPaddingUl">
                  <li>Aspose.Pdf component gives you the agility to report your data in a variety of ways.</li>
                  <li>Aspose.Pdf component is fully functional for creating all types of reports.</li>
                  <li>You may customize the size and appearance of everything on a report. </li>
                  <li>You can display the information the way you want to see it.</li>
              </ul>
              The demo generates a printed report
              <ul class="noPaddingUl">
                  <li>It has a two-page report header and uses photos for each category. </li>
                  <li>Spring.NET NHibernate is used to retrieve the data from the Customers table of Northwind database, to generate the report </li>
                  <li>You can either open the resulting PDF file into your PDF reader or save directly to your disk. </li>
              </ul>
              Click Process to see how example Prints customers' company names and addresses on 3-up labels. 
          </div>
          <br />
      
          <asp:Button ID="btnProcess" runat="server" Text="Process" OnClick="btnProcess_Click" />
      
      </asp:Content>
      
      
    7. Replace the code-behind with
      
      
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using Aspose.Pdf.Generator;
      using System.Data;
      using Spring.Northwind.Dao;
      using Spring.Northwind.Domain;
      
      namespace Spring.Northwind.Web.Pdf
      {
          public partial class CustomerLabels : System.Web.UI.Page
          {
              private ICustomerDao customerDao;
      
              public ICustomerDao CustomerDao
              {
                  set { this.customerDao = value; }
              }
      
              protected void Page_Load(object sender, EventArgs e)
              {
      
              }
      
              protected void btnProcess_Click(object sender, EventArgs e)
              {
                  Aspose.Pdf.Generator.Pdf pdf = GetCustomerLabels();
                  pdf.Save("customerlabels.pdf", SaveType.OpenInAcrobat, Response);
                  Response.End();
              }
      
              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 = Server.MapPath("~/App_Data/xml/CustomerLabels.xml");
                  pdf.BindXML(xmlFile, null);
      
                  Section section = pdf.Sections["section1"];
                  Aspose.Pdf.Generator.Table table1 = (Aspose.Pdf.Generator.Table)section.Paragraphs["table1"];
                             
                  IList customersList = customerDao.GetAll();
      
                  string[] strArr = new string[customersList.Count];
      
                  for (int i = 0; i < customersList.Count; i++)
                  {
                      strArr[i] = customersList[0].CompanyName.ToString() + "#$NL" + customersList[1].Address.ToString() + "#$NL" +
                          customersList[2].City.ToString() + " " + (customersList[3].Region == null ? string.Empty : customersList[3].Region.ToString()) + " " +
                          customersList[4].PostalCode.ToString() + "#$NL" + customersList[5].Country.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;
                      }
                  }
      
                  return pdf;
              }
          }
      }
      
      
    8. Run the project using F5 and open CustomerLabels.aspx page. Click 'Process' button to generate the report.

Last edited Feb 28, 2014 at 3:03 PM by asposemarketplace, version 4