Creating an IlvDocument with a flow of text

This is an example to explain how to use the printing framework with a text flow.
To print the text flow example:
  1. Create an IlvPrintableDocument object.
  2. Create the IlvFlow object.
  3. Add text and image to the IlvFlow object.
  4. Set the text style and paragraph alignment.
  5. Create and use the printing controller.
  6. Use the user interface components to preview the document you created.
The example code is as follows.
Creating a document with a text flow
 // Creates the document.
 IlvPrintableDocument document 
= new IlvPrintableDocument("A Test Document");
   
// Gets the flow to add text and images.
IlvFlow flow = document.getFlow();

// Sets the style of text and paragraph alignment
// for the title.
IlvFlow.TextStyle style = new IlvFlow.TextStyle();
style.setFont(new Font("Helvetica", Font.BOLD, 20));
style.setAlignment(IlvFlow.TextStyle.CENTER_ALIGNMENT);
flow.setTextStyle(style);

// Adds the title text.
flow.add("The Printing Framework Document Model");

flow.newLine();

// Sets the style of text for the next paragraph.
style.setAlignment(IlvFlow.TextStyle.LEFT_ALIGNMENT);
style.setFont(new Font("Helvetica", Font.PLAIN, 16));
flow.setTextStyle(style);

flow.newLine();
flow.add("The document model provides a structure to define a multiple-page document to be printed. The document model allows you to concentrate your efforts on creating your printable document without worrying about how the document is previewed and printed. The printing framework previews and prints the document for you.");
 
flow.newLine();
flow.newLine();
flow.add("The following figure shows the relationship between the main classes in the document model:");
flow.newLine();

try {
  
    // Loads an image to add.
    Image image = IlvUtil.GetImageFromFile(Class.forName("demos.print.PrintExample"), "model.gif");

    // Adds the image to the flow.
    flow.add(image, IlvFlow.TOP_ALIGNMENT);

  } catch (Exception e) {
}

// Creates the print controller.
IlvPrintingController controller = new IlvPrintingController(document);
    
// Previews the document.
controller.setPreviewMode(IlvPrintPreviewPanel.CONTINUOUS_MODE);
controller.printPreview(JOptionPane.getRootFrame());
Here is what you get on the screen:
flow.gif
Document with text flow