Adding, Deleting and Rearranging Columns in PDF Reports

If you are not satisfied with the column layout of your PDF report, there are two approaches to configuring your report:

  1. Modify the button-specific .report file

  2. Override the button click handler method

Modifying the button-specific .report file

First, open the associated button-specific .report file and locate the appropriate <Column> section you wish to modify.

          <Columns>

              <Column>

                   <Width>100</Width>

                   <Header>

                        <Value>Company Name</Value>

                        <Style>

                        <BorderWidth>

                             <Left>0pt</Left>

                             <Right>0pt</Right>

                             <Top>0pt</Top>

                             <Bottom>2pt</Bottom>

                        </BorderWidth>

                        <BorderColor>

                             <Left>000000</Left>

                             <Right>000000</Right>

                             <Top>000000</Top>

                             <Bottom>dcbb4a</Bottom>

                        </BorderColor>

                        <Font>

                             <Color>333333</Color>

                             <Size>7pt</Size>

                             <FileName>Arial.ttf</FileName>

                             <Bold>True</Bold>

                             <Italic>False</Italic>

                             <Underline>False</Underline>

                             <RightToLeft>CulturalDefault</RightToLeft>

                             <Encoding>CulturalDefault</Encoding>

                        </Font>

                        <VerticalAlign>Middle</VerticalAlign>

                        <HorizontalAlign>Default</HorizontalAlign>

                        <Padding>

                             <Left>5pt</Left>

                             <Right>5pt</Right>

                             <Top>5pt</Top>

                             <Bottom>5pt</Bottom>

                        </Padding>

                        <BackgroundColor>dcbb4a</BackgroundColor>

                        </Style>

                   </Header>

                  

    

                   <Detail>

                        <Value>${Customers.CompanyName}</Value>

                        <Style>

                             <BorderWidth>

                                  <Left>0pt</Left>

                                  <Right>0pt</Right>

                                  <Top>0pt</Top>

                                  <Bottom>1pt</Bottom>

                             </BorderWidth>

                             <BorderColor>

                                  <Left>000000</Left>

                                  <Right>000000</Right>

                                  <Top>000000</Top>

                                 <Bottom>cccccc</Bottom>

                             </BorderColor>

                             <Font>

                                  <Color>666666</Color>

                                  <Size>7pt</Size>

                                  <FileName>Arial.ttf</FileName>

                                  <Bold>False</Bold>

                                  <Italic>False</Italic>

                                  <Underline>False</Underline>

                                  <RightToLeft>CulturalDefault</RightToLeft>

                                  <Encoding>CulturalDefault</Encoding>

                             </Font>

                             <VerticalAlign>Top</VerticalAlign>

                             <HorizontalAlign>Default</HorizontalAlign>

                             <Padding>

                                  <Left>5pt</Left>

                                  <Right>5pt</Right>

                                 <Top>5pt</Top>

                                  <Bottom>5pt</Bottom>

                             </Padding>

                             <BackgroundColor>ffffff</BackgroundColor>

                        </Style>

    

                  

                        <AltStyle>                                                                     

                             <FontColor>666666</FontColor>

                             <BackgroundColor>d9e3eb</BackgroundColor>

                        </AltStyle>

                    </Detail>

              </Column>

          More column nodes...

          </Columns>

By default, the content is wrapped in comment tags (“<!—“ and “à”) so the section is ignored while your application is creating the PDF report.  Remove these comment tags to active this section.  In addition, the Style and AltStyle tags do not have to be present in this file.  If you are not working on any advanced setting such as changing alignment, border, padding, etc, you can remove these tags.  After removing these tags, you should get the following:

          <Columns>

              <Column>

                   <Width>100</Width>

                   <Header>

                        <Value>Company Name</Value>

                   </Header>

                  

    

                   <Detail>

                        <Value>${Customers.CompanyName}</Value>

                   </Detail>

              </Column>

          More column nodes...

          </Columns>

Next, change the Value and Width tags.  The Width tag represents relative width of the column.  You should specify a number here.  The first Value tag represents the text of the column header.  The second Value tag represents the the text of each row, and you should place substitution parameters here.  If you want to know what substitution parameters are available, you can go to the button click handler method.  Within this method is code similar to:

report.AddData("${CustomerCustomerDemoTable.CustomerID.Name}", record.Format(CustomerCustomerDemoTable.CustomerID), ReportEnum.Align.Left)

The first parameter tells you that "${CustomerCustomerDemoTable.CustomerID.Name}" is a substitution parameter you can use.  After configuring the first column, follow the same procedure to configure the other columns.

Overriding the button click handler method

Copy the code in the button click handler method from section 2 and paste it to the overridden method in section 1.  Here is a representative version:

     try {

          DbUtils.StartTransaction();

          PDFReport report = new PDFReport();

          report.SpecificReportFileName = Page.Server.MapPath("ShowCustomersTable.CustomersPDFButton.report");

          report.Title = "Customers";

          report.AddColumn(CustomersTable.CustomerID.Name, ReportEnum.Align.Left, "${CustomersTable.CustomerID.Name}",

              ReportEnum.Align.Left, 15);

          report.AddColumn(CustomersTable.CompanyName.Name, ReportEnum.Align.Left,

              "${CustomersTable.CompanyName.Name}", ReportEnum.Align.Left, 28);

          report.AddColumn(CustomersTable.ContactTitle.Name, ReportEnum.Align.Left, "${CustomersTable.ContactTitle.Name}",

              ReportEnum.Align.Left, 24);

 

          WhereClause whereClause = CreateWhereClause();

          OrderBy orderBy = CreateOrderBy();

          int rowsPerQuery = 1000;

          int pageNum = 0;

          int recordCount = 0;

          int totalRecords = CustomersTable.GetRecordCount(whereClause);

 

          report.Page = Page.GetResourceValue("Txt:Page", "MyApp31");

          report.ApplicationPath = this.Page.MapPath(Page.Request.ApplicationPath);

 

          ColumnList columns = CustomersTable.GetColumnList();

          CustomersRecord[] records = null;

          do

          {

              records = CustomersTable.GetRecords(whereClause, orderBy, pageNum, rowsPerQuery);

              if (records != null && records.Length > 0)

              {

                   foreach ( CustomersRecord record in records)

                   {

                        report.AddData("${CustomersTable.CustomerID.Name}", record.Format(CustomersTable.CustomerID),

                             ReportEnum.Align.Left);

                        report.AddData("${CustomersTable.CompanyName.Name}", record.Format(CustomersTable.CompanyName),

                              ReportEnum.Align.Left, 100);

                        report.AddData("${CustomersTable.ContactTitle.Name}", record.Format(CustomersTable.ContactTitle),

                             ReportEnum.Align.Left, 100);

 

                        report.WriteRow();

                   }

                   pageNum++;

                   recordCount += records.Length;

              }

          }

          while (records != null && recordCount < totalRecords);

          report.Close();

          BaseClasses.Utils.NetUtils.WriteResponseBinaryAttachment(this.Page.Response, report.Title + ".pdf",

              report.ReportInByteArray, 0, true);

          this.Page.CommitTransaction(sender);

     } catch (Exception ex) {

          this.Page.RollBackTransaction(sender);

          this.Page.ErrorOnPage = true;

   

          BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);

     } finally {

          DbUtils.EndTransaction();

     }

Next, modify the report.AddColumn method calls.  To remove a particular column from the PDF report, remove the corresponding report.AddColumn call.  If you want to add a column, please refer to PDF Report Alignment Configuration.

See Also

Customizing PDF Report Configuration Files

Text Substitution Parameters for Titles, Headers, Footers and Columns

PDF Report Alignment Configuration

PDF Report Language and Culture-Based Configuration

Adding, Deleting and Rearranging Columns in PDF Reports

Customizing PDF Report Code