To add a text object to a report

Adding a text object to a report lets you create custom headings or display information that is not included in the report data. A text object is a collection of paragraph objects, and each paragraph object is a collection of paragraph elements. Paragraphs and paragraph elements are customizable, giving you control over how your text object appears in the report.
  1. Create a new IParagraphTextElement object, and then call the setText and setKind methods to set the text and kind of the object.
    Replace My text with your paragraph text.
    IParagraphTextElement paragraphTextElement = new ParagraphTextElement();
    paragraphTextElement.setText("My text");
    paragraphTextElement.setKind(ParagraphElementKind.text);
  2. Add the IParagraphTextElement object to a new ParagraphElements object collection.
    ParagraphElements paragraphElements = new ParagraphElements();
    paragraphElements.add(paragraphTextElement);
  3. Add the ParagraphElements object collection to a new Paragraphobject.
    Paragraph paragraph = new Paragraph();
    paragraph.setParagraphElements(paragraphElements);
  4. Add the Paragraph object to a new Paragraphs object.
    Paragraphs paragraphs = new Paragraphs();
    paragraphs.add(paragraph);
  5. Add the Paragraphs object to a new TextObject object, and set the properties of the text object.
    In this sample the position and the width of the text object are set.
    TextObject textObject = new TextObject();
    textObject.setParagraphs(paragraphs);
    textObject.setLeft(1440);
    textObject.setWidth(4320);
  6. Use the ReportDefController object to add the text object to the report.
    In this sample the text object is added to the report header.
    ReportDefController reportDefController = rcd.getReportDefController();
    ISection sectionToAddTo = reportDefController.getReportDefinition().getReportHeaderArea().getSections().getSection(0);
    reportDefController.getReportObjectController().add(textObject, sectionToAddTo, 0);
Example: 
This sample adds a text object to a report.
void addTextObject(ReportClientDocument rcd) throws ReportSDKException
{
  IParagraphTextElement paragraphTextElement = new ParagraphTextElement();
  paragraphTextElement.setText("My text");
  paragraphTextElement.setKind(ParagraphElementKind.text);
       
  ParagraphElements paragraphElements = new ParagraphElements();
  paragraphElements.add(paragraphTextElement);
       
  IParagraph paragraph = new Paragraph();
  paragraph.setParagraphElements(paragraphElements);
       
  Paragraphs paragraphs = new Paragraphs();
  paragraphs.add(paragraph);
       
  TextObject textObject = new TextObject();
  textObject.setParagraphs(paragraphs);
  textObject.setLeft(1440);
  textObject.setWidth(4320);
       
  ReportDefController reportDefController = rcd.getReportDefController();
  ISection sectionToAddTo = reportDefController.getReportDefinition().getReportHeaderArea().getSections().getSection(0);
  reportDefController.getReportObjectController().add(textObject, sectionToAddTo, 0);
}
This list includes the classes used by the sample code:
  • com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
  • com.crystaldecisions.sdk.occa.report.application.ReportDefController
  • com.crystaldecisions.sdk.occa.report.definition.IParagraph
  • com.crystaldecisions.sdk.occa.report.definition.IParagraphTextElement
  • com.crystaldecisions.sdk.occa.report.definition.ISection
  • com.crystaldecisions.sdk.occa.report.definition.ITextObject
  • com.crystaldecisions.sdk.occa.report.definition.Paragraph
  • com.crystaldecisions.sdk.occa.report.definition.ParagraphElementKind
  • com.crystaldecisions.sdk.occa.report.definition.ParagraphElements
  • com.crystaldecisions.sdk.occa.report.definition.ParagraphTextElement
  • com.crystaldecisions.sdk.occa.report.definition.Paragraphs
  • com.crystaldecisions.sdk.occa.report.definition.TextObject
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKException