Getting Started > Your first Report

Your first Report

Let’s build a simple report that will get you started with the SharpLeaf class for reporting.

Basic routine

As seen in a first chart tutorial, a typical SharpPlot script iteratively set up parameters and then draws. We can use the same approach to produce a simple report by iteratively adjusting settings then appending text. The following script uses the aplparas variable.

   lf = new SharpLeaf();

   lf.Style.Font.Size=24; // change font size;
   lf.Style.Alignment=Alignment.Center; // change alignment;
   lf.AddParagraphs("My Report Title");  // Flow title

   lf.IncludeSpace(36);  // Bump down by half an inch
   lf.Style.Font.Size=12; // change font size;
   lf.Style.Alignment=Alignment.Left; // change alignment;
   lf.Style.SpaceAfter=12; // 12 points of free space after each paragraph;
   lf.AddParagraphs(aplparas);  // Flow text

   lf.SavePdf("myfirstreport.pdf");

Spicing it up

Because a SharpLeaf script typically has many calls to methods control the flow and append content into the report, settings are generally available as structures, so that a typical SharpLeaf script will have two phases:

Which is pretty similar to modern web design of segregating style (CSS) from content (HTML).

Using that mindset, we can make a nicer report with a cleaner script:

  // Set up paragraph styles
   title = new ParagraphStyle();
   title.Font = new FontType("Garamond",18,FontStyle.Bold,Color.Navy);
   title.Alignment = Alignment.Center;
   title.SpaceAfter = 36;  // Half an inch of free space below titles
   title.BookmarkLevel = 1;  // Automatically bookmark titles at top level

   body = new ParagraphStyle();
   body.IndentFirst = 36;
   body.IndentFirstAfterChange = false;  // Enforce typographical etiquette

  // Flow content
   lf.AddParagraphs("My Report Title",title);
  // Include an image on the right, scaling it to fit two inches
   lf.IncludeImage("dyalog.jpg","dyalog.jpg",BoxFlow.Right,144,144);
  // Start next paragraph with a dropped capital on three lines
   lf.SetCap(3);
   lf.AddParagraphs(aplparas,body);

  // Render report
   lf.SavePdf("myfirstreport.pdf");

See also ...

Getting Started | SharpLeaf Tutorials | SharpPlot in different Languages


Send comments on this topic
© Dyalog Ltd 2021