Huge Collections of Software Manuals and Knowledgebase

GreatManuals.com
Huge Collections of Software Manuals and Knowledgebase

 
Home Contact us Request to publish your help manuals Request to remove your help manuals Buy Now
Introduction
» J2PrinterWorks
» Print Samples and Screen Shots
» Sample Programs and Sample Code
» Installing and Uninstalling
» Pageable and Flowable
Using J2PrinterWorks
» J2Printer
» J2Printer14
» J2PrinterWebStart
» J2TextPrinter
» J2TablePrinter
» J2TreePrinter
» J2ListPrinter
» J2PanelPrinter
» J2ComponentPrinter
» J2FlowPrinter
» Working with HTML
» Utility Classes
» Converting from 1.x
» Class Diagram
» Removed Methods
Support Details
» Known Problems and Bug Reporting
» Frequently Asked Questions
» Technical Support
 
Buy J2PrinterWorks Online! Buy J2PrinterWorks Online!

J2TextPrinter

Overview

J2TextPrinter is a Java 2 component for printing multi-page JTextPane documents. J2TextPrinter converts any JTextPane, JEditorPane, or JTextArea or subclass thereof into a Java Pageable, suitable for printing by the J2Printer class (or any Java PrinterJob). It also implements Flowable for any JTextPane, JEditorPane, or JTextArea, so that it may be used with J2FlowPrinter as part of a series of Flowables printed back-to-back.

JTextPane, JEditorPane, and JTextArea are all subclasses of JTextComponent. JTextArea is used in Java to represent simple, multiple-line text in a single font. JEditorPane and.JTextPane are used in Java to represent rich text documents, including multiple fonts, sizes, styles, colors, alignment, spacing, tabs, indentation, etc. In addition, JTextPane is also capable of including embedded graphics and embedded components into the middle of a rich text document.

photo unerase digital picture recovery flash data recovery
best data recovery software download data recovery tool group sms
repair usb drive usb drive restore files recovery usb drive

Since JTextPane is the most general JTextComponent supported by J2TextPrinter, we focus on it as the primary Java component used for forming and printing text documents. The underlying model (data) for a JTextPane is an instance of the class StyledDocument. It can be formed programmatically by calling JTextPane methods, or by reading in HTML or RTF formatted data (subject to the limits of Java's support for these standards).

J2TextPrinter Pagination

When J2TextPrinter paginates the JTextPane, it breaks pages vertically on line boundaries. J2TextPrinter will reflow (rewrap) the contents of the JTextPane to fit the width of the page, taking the current page size and margins into account. Alternatively, you can turn on "WYSIWYG" mode to cause the printed pages to retain the exact line layout of the specified JTextPane. J2TextPrinter then calculates the maximum number of lines that will fit in the remaining space on each page. If a \f (form feed) character is encountered before this point, then a page break is inserted and the entire line containing the form feed character is omitted. If the calculated page break occurs in the middle of an HTML table, the exact boundary between HTML table rows is determined for the actual page break.

J2TextPrinter never paginates horizontally. If the JTextPane contains content that is too wide for the page (such as a wide image, a wide row of an HTML table, or too much text on a line in WYSIWYG mode), it will automatically shrink-to-fit the entire JTextPane so that the widest content fits the available page width.

If an embedded graphic (e.g. image), embedded component, HTML table row, or very large font character is encountered that does not fit in the remaining space on the page, special fallback heuristics are used to determine where to break the page. First, J2TextPrinter reads the value of getMaximumPaginationGap(), default is 0.2 or 20%. If the remaining space on the page is less than that percentage of the full page height, then printing skips to the top of the next page (this controls the largest amount of space that will be wasted in order to keep content intact). If this occurs within an HTML table row, the characters are examined one at a time to find a possible break between text lines that does fit (this handles the case of many lines of text within a single HTML table cell). Otherwise, the graphic, component, HTML table row, or large character is sliced like an image ("tiled") at the exact pixel boundary that exactly fits the remaining space on the page.

Programming

You will find it useful to begin your program with:

import com.wildcrest.j2printerworks.*;

rather than spell out the full package name for all J2PrinterWorks classes.

J2TextPrinter can instantiated with a zero-argument constructor:

J2TextPrinter textPrinter = new J2TextPrinter();

This creates a J2TextPrinter object and initializes all values to their defaults (see the J2TextPrinter Javadoc documentation ). To specify the JTextPane to be printed by J2TextPrinter, you can use the J2TextPrinter method setPane:
textPrinter.setPane(yourJTextPane);
At this point textPrinter is a Pageable suitable for printing by J2Printer.

Alternatively, you can use the single-argument J2TextPrinter constructor:
J2TextPrinter textPrinter = new J2TextPrinter(yourJTextPane);

The following is a simple but complete Java program (J2TextPrinterSimplestTest.java ) that displays and prints a JTextPane using J2TextPrinter:

import javax.swing.*;
import com.wildcrest.j2printerworks.*;

class J2TextPrinterSimplestTest{
static public void main(String args[]){
JTextPane pane = new JTextPane();
pane.setContentType("text/html");
pane.setText("<html>Here are two lines of <b>HTML text</b>"
+ "<br>that <i>will</i> be printed</html>");

JFrame frame = new JFrame("J2TextPrinter test");
frame.getContentPane().add(pane);
frame.setSize(300,200);
frame.setVisible(true);

J2Printer printer = new J2Printer();
printer.setSeparatePrintThread(false);
J2TextPrinter textPrinter = new J2TextPrinter(pane);
printer.addPageable(textPrinter);
printer.print();

System.exit(0);
}
}

Most of the methods of J2TextPrinter are set and get methods for controlling its property values. The full list of J2TextPrinter methods, what they do, and their default values are given in the J2TextPrinter Javadoc documentation.

»

Buy J2PrinterWorks Online! Buy J2PrinterWorks Online!
Home | Contact Us | Request to publish your help manuals | Request to remove your help manuals