Advanced Features > The Generic Printing Framework > The Printing Framework > Example 2: An IlvDocument with a Flow of Text

Here is a second example that creates a document and fills it with text. This example uses the IlvFlow class instance associated with a document to set the text.

The example shows how to:

 // 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());

Code Sample 3.2 Creating a Document with a Text Flow

Here is what you get on the screen:

images/flow.gif

Figure 3.8 Document with Text Flow