Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
105
Add Title to pdf
posted

Hi,

 

I have webgrid that I populate with a csla data source  and export to pdf using UltraWebGridDocumentExporter. I try to add a title to the pdf through the BeginExport event of the UltraWebGridDocumentExporter. This event doesnlt seem to be firing. following is the code. Not sure what I am missing:

The End Export event fires but doesnlt seem to add the title as well

BtnRunReport_Click

{

UltraWebGridDocumentExporter1.DownloadName = "Best Scores";

UltraWebGridDocumentExporter1.ExportMode = Infragistics.WebUI.UltraWebGrid.Exporter.ExportMode.InBrowser;

UltraWebGridDocumentExporter1.Format = FileFormat.PDF;

UltraWebGridDocumentExporter1.Export(this.uwgReportGrid);

} 

protected void UltraWebGridDocumentExporter1_BeginExport(object sender, Infragistics.WebUI.UltraWebGrid.DocumentExport.DocumentExportEventArgs e)

{

e.Report.Info.Title = "Best Scores";

}

protected void UltraWebGridDocumentExporter1_EndExport(object sender, Infragistics.WebUI.UltraWebGrid.DocumentExport.EndExportEventArgs e)

{

e.Report.Info.Title = "Best Scores";

}

 I alterbatively tried this code in the BeginExport event:

Infragistics.Documents.Report.Section.ISectionHeader _Header = e.Section.AddHeader();

Infragistics.Documents.Report.Text.IText _Title = _Header.AddText(0, 0);

_Title.Caption = "Best Scores";

 Thanks, 

Himgauri

Parents
  • 1414
    posted

    Big SmileHimgauri,

    You ran into the same problems I did.  Basically, you submitted the grid via the .Export method with no parameters.  That sent the grid to whatever Infragistics black hole initiates the print stream.  Then you created a new section in the _BeginExport event which basically made a new report section which followed the section containing the grid.  Not exactly what you were looking for.  There are good examples, but it takes some searching.

    Here is the basic skinny. 

    1. You want to first create a blank report object. 
    2. Then you want to add a section to the report object
    3. Then you want to add a header to that section - watch out for the AddText method which is like using Microsoft Paint to position text
    4. AND THEN, you want to .Export the grid to the above section

    Obviously this cannot be accomplished after you are printing the grid in the default section (ie. the first one)

    While many are whining about this tool I am starting to think it is more powerful than even the authors know.  For example, you can use the AddContent and AddText methods to create put-it-here form reports.  I don't know how to get the results printing yet - but it should not be too hard.  I just saw a Publish method.  So while Infragistics intended this tool to be used for printing grids, me thinks I can do any type of printing with it.  Also, the section and grid management provides me a means of printing multiple grids.  And, the thang is fast...  I am thinking of dumping Crystal Reports if the ideas in this paragraph bear fruit.  And, no, I don't work for Infragistics. 

    Really bad code follows - but it illustrates the point and the fact that I am still rather ignorant in the use of this tool:

    protected void btnPrint_Click(object sender, EventArgs e)
    {

    System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;

    // configure exporter
    RightContent_DocumentExporter.Format = FileFormat.PDF;
    RightContent_DocumentExporter.DownloadName =
    "roster.pdf";
    RightContent_DocumentExporter.TargetPaperOrientation =
    PageOrientation.Landscape;

    // Create a new report
    Report report = new Report();
    report.Info.Title =
    this.txtGridHdr.Text;
    report.Info.Author = p.Identity.Name.ToString();
    report.Info.Subject =
    "Confidential Report printed by " + p.Identity.Name.ToString();

    //Add a Header to the report
    Infragistics.Documents.Report.Section.ISection gridSection = report.AddSection();
    Infragistics.Documents.Report.Section.
    ISectionHeader header = gridSection.AddHeader();
    header.Height = 80;
    ReportText.
    IText rptHeader = header.AddText(0, 0);
    ReportText.
    Style headingStyle = new ReportText.Style(new Font("Tahoma", 16), Brushes.Crimson);
    rptHeader.AddContent(
    "Client Counseling System (CCS)", headingStyle);
    rptHeader.AddLineBreak();
    ReportText.
    Style headingRptNameStyle = new ReportText.Style(new Font("Tahoma", 14), Brushes.Crimson);
    rptHeader.AddContent(this.txtGridHdr.Text + " Roster (" + wg.Rows.Count.ToString() + " Personnel)", headingRptNameStyle);
    rptHeader.AddLineBreak();
    ReportText.
    Style captionStyle = new ReportText.Style(new Font("Tahoma", 10), Brushes.Black);
    rptHeader.AddContent(
    "Security Status: Confidential", captionStyle);
    rptHeader.AddLineBreak();
    rptHeader.AddContent(
    "Printed By: " + p.Identity.Name.ToString(), captionStyle);
    rptHeader.AddLineBreak();
    rptHeader.AddContent(
    "Print Date: " + System.DateTime.Now.ToString(), captionStyle);
    rptHeader.AddLineBreak();

    gridSection.AddRule();

    //Size the grid columns and print the grid
    ToolBox.WebGrid.SetColumnWidthsByPercentage(wg);
    RightContent_DocumentExporter.Export(wg, gridSection);

    }

Reply Children
No Data