SharpLeaf Reference > SharpLeaf Class

SharpLeaf Class

The SharpLeaf class allows the creation of automated reports.

public class SharpLeaf


A SharpLeaf report is generally accomplished in 3 phases:

  1. Set up the document layout (master pages) and the paragraph styles
  2. Flow content into frames
  3. Render report to image
   para = "Here's a dummy paragraph of text. As the qualifier suggests its content is "+
            "not particularly interesting, but it still reaches its goal of being long "+
            "enough to take up more than one line.";

  // Define document layouts
   page = new PageLayout(PaperSize.Landscape(PaperSize.A5));
   page.Add(new Frame("Main",36,36,-36,-36));  // Half-inch margin all around invisible frame
   layout = new DocumentLayout(page);

  // Define paragraph styles
   body = new ParagraphStyle();
   body.IndentFirst = 36;
   body.SpaceAfter = -1;  // Equivalent of one empty line of text after each paragraph
   title = body.Clone();  // take a deep copy
   title.Font = new FontType("Garamond",15,FontStyle.Bold,Color.Navy);
   title.SpaceBefore = -2;  // Leave room before a title - unless at top of frame
   title.BookmarkLevel = 1;  // Automatically bookmark titles at top level

  // Start flowing
   lf = new SharpLeaf(layout);
   lf.AddParagraphs("First title",title);
   lf.AddParagraphs(new string[]{para,para},body);
   lf.AddParagraphs("Second title",title);
   lf.AddParagraphs(new string[]{para,para,para},body);

  // Render

Have a look at the SharpLeaf tutorials for more examples.


SharpLeaf Instance Properties

ArgumentListSubstitution values for {1} ... {99} in TextBlock captions
BulletCountNext value for numbered lists
CapFontFont for dropped capitals (default is null for paragraph font)
DecimalDecimal separator used by Alignment.Decimal (defaults to ‘.’)
EllipsisCharacter that marks text clipping (default is ‘…’ – Unicode 0x2026 – code point 8230 – set to ‘ ‘ to disable)
FrameHeightHeight of current frame (excluding gutter) (ReadOnly)
FrameIdIdentifier of the current Frame (ReadOnly)
FrameLeftLeft of current frame (excluding gutter) (ReadOnly)
FrameTopTop of current frame (excluding gutter) (ReadOnly)
FrameWidthWidth of current frame (excluding gutter) (ReadOnly)
PageNumber of current page, starting at 1 (ReadOnly)
PagesNumber of non-empty pages of the report so far (ReadOnly)
PaperSizePaper size of current page (ReadOnly)
SoftHyphenCharacter marking silent word break (default is Unicode standard ‘­’ – U+0x00AD – code point 173)
StyleWorking ParagraphStyle
TitleDocument title
VersionGet SharpLeaf Version (ReadOnly)
YPositionCurrent position on page (ReadOnly)

SharpLeaf Methods

AddBookmarkReferenceFlow text into the current paragraph that will point to a named bookmark (earlier or later set with SetBookmark)
AddHtmlAppend text with simple HTML tags to the current paragraph
AddHyperlinkFlow text that will point to a URL
AddParagraphsFlow new paragraphs of texts into the current frame with optional style
AddRichTextRun a vector of "WordPad" Rich Text Format into frame as new paragraphs. This is specific to "old-style" RTF, and not a general RTF parser.
AddSubscriptAppend subscripted text to the current paragraph
AddSuperscriptAppend superscripted text to the current paragraph
AddTextAppend text to the current paragraph
DrawArrowLow-level routine to draw an arrow with specified parameters
DrawElementDraw an arbitrary PageElement on current page
GetCharsetsReturn the list of used characters for each used font
GetRemainingHeightGet remaining height in current frame (from current point to bottom)
GetRemainingWidthGet available width in current frame
GetTextHeightMeasure the height taken by a paragraph of text, interpreting linebreaks, possibly wrapping inside a specified width.
GetTextWidthMeasure the width taken by a paragraph of text, interpreting newline characters (but not tab characters)
IncludeChartAdd a SharpPlot chart to a report, with optional scaling and wraparound
IncludeImageAdd a picture to a report, with optional scaling and wraparound
IncludeRuleRule line across frame – unless at the top of a frame
IncludeSpaceInclude empty space within text flow
IncludeTableFlow a table within current frame
NextClearMove down to the closest spot with a clear margin on the left and/or the right hand side.
NextFrameSkip flow to a new Frame – may imply a new page.
NextLineSkip to next line – optionally skipping several
NextPageForce page throws
NextParagraphSkip to next paragraph – does nothing if already in a new paragraph
NextTabSkip a number of tabstops
PopStyleRestore the ParagraphStyle used before the last PushStyle
PushStyleTemporarily change the current ParagraphStyle, while pushing previous on to the style stack – undone by PopStyle
RenderDocumentReturn completed report as a Document instance
RenderLogReturn report as a readable log
RenderPSReturn report rendered as raw PostScript
RenderPdfReturn report as a PDF stream
RenderSvgReturn report rendered as SVG
RenderXamlReturn report rendered as a XAML Canvas
SaveLogSave completed report as a readable log file
SavePSSave report to named file as raw PostScript
SavePdfSave report to named file as PDF
SaveSvgSave report to named file as SVG
SaveXamlSave report to named file as a XAML Canvas
SetArgumentSet a specific argument in the ArgumentList
SetBookmarkCreate a bookmark entry for upcoming element (paragraph, text, includes, etc.)
SetBoxStart and stop boxing decorations around text
SetCapSet up a dropped capital on upcoming paragraph
SetLayoutChange master page layout, closing any started page.

See also

SharpLeaf Tutorials | Text Flow Tutorials


Namespace: Causeway

Assembly: SharpPlot (in sharpplot.dll)

Send comments on this topic
© Dyalog Ltd 2016