ElegantJBeans – Printer

 

 

Programmers’ Guide

 


 

Table of Content

 

1    Preface  4

1.1    Purpose of this document  4

1.2    Assumptions  4

1.3    Document Organization   4

1.4    Conventions Used   5

2    About ElegantJ Printer  6

2.1    What’s New    6

2.2    Toolkit  6

3    Product Features  7

3.1    Operational functionalities  7

3.2    Page and Print Setup features  7

4    Product Demo   8

4.1    Installing Demo   8

4.2    View Demo   8

5    Installation and Registration   10

5.1    Prerequisite  10

5.2    Installation Procedure  10

5.3    Using with Different IDEs  11

5.3.1    Borland JBuilder  11

5.3.2    Oracle JDeveloper  12

5.4    Getting Registered   12

5.4.1    How to Purchase  12

5.4.2    Using with Graphical User Interface of IDE  13

5.4.3    Using directly with source code  13

6    Programmers’ Guide  14

6.1    ElegantJ Printer  14

6.1.1    Creating an instance of ElegantJ Printer  14

6.1.2    Setting up Paper Type and Size  14

6.1.3    Setting up margins and header / footer  15

6.1.4    Setting page Orientation  16

6.1.5    Setting number of copies  16

6.1.6    Showing a line below header and above footer  16

6.1.7    Binding a component to Printer  16

6.1.8    Applying Scaling and Wrapping  16

6.1.9    Binding JTextArea, JTextPane, JTable, TextArea with Printer  17

6.1.10     Working with Page Setup Control Dialog  17

6.1.11     Opening Print Preview   17

6.1.12     Handling Bulk Print Jobs (by controlling spool size) 18

6.1.13     Implementing Printing - print methods for printing  18

6.1.14     Setting up port for direct printing on target port  19

6.1.15     Printer Listeners and Events  20

6.1.16     Extending Printing Support to your own component  20

6.1.17     Removing Header and footer  20

6.1.18     Removing line below header and above footer  21

6.1.19     Printing large component on single page with scaling down  21

6.1.20     Printing large component on multiple pages with wrapping  21

6.1.21     Keeping spool size small while printing large number of pages  21

6.1.22     Disabling Printing from Preview Dialog Box  22

7    Product and Support Information   23

 

 


 

1       Preface

This preface describes the document. The preface contains the following sections:

 

 

Section

Page

Purpose of this document

4

Assumptions

4

Document Organization

4

Conventions Used

5

 

 

1.1  Purpose of this document

The purpose of this document is to provide the fundamental skills necessary to productively install, program, integrate, and use the ElegantJ DataTree. This document provides both programmer and user perspective to the audience.

 

 

1.2  Assumptions

This manual assumes that readers are having reasonable level of exposure to fundamentals of Java programming and various architectures.

 

 

1.3  Document Organization

This document is organized as described in following tables.

Table 1 – Organization of the document

Chapter

Contents

About ElegantJ Printer

Ø       What’s New

Ø       Toolkit

Product Features

Ø       Operational functionalities

Ø       Page and Print Setup features

Product Demo

Ø       Installing Demo

Ø       View Demo

Installation and Registration

Ø       Prerequisite

Ø       Installation Procedure

Ø       Using with Different IDEs

Ø       Getting Registered

Programmers’ Guide

Ø       Core components and definitions for different printer beans

Ø       Programmer's guide to frequently asked questions

 

 

 

 

 

1.4  Conventions Used

 

File

Italic (slanted) type indicates variable values, instruction operands.

[ | ]

{ | }

In syntax definitions, brackets indicate items that are optional and braces indicate items that are required. Vertical bars separating items inside brackets or braces indicate that you choose one item from among those listed.

. . .

In syntax definitions, a horizontal ellipsis indicates that the preceding item can be repeated one or more times.

//

An explanation of a particular function performed by preceding code.

 


 

2       About ElegantJ Printer

Dynamic Java printing made simple, fast, easy and the most flexible. ElegantJ Printer Java Bean works with any Java component that does not have native support for printing.  Support for impact printers and non-impact printers.  Provide web-printing ability to your users. Printing with scaling as well as wrapping.  Special implementation for printing AWT TextArea, swing JTextArea, swing JTable and swing JTextPane.  Prints data directly on printer port for background printing of PRN file or files of other printable types.  Controllable spool size for efficiency in bulk printing.  Page setup and Page Preview dialog box to give edge to your application's printing capabilities.

 

 

2.1  What’s New

Ø       In case you are using evaluation, an Evaluation Dialog used to popup every 10 minutes. This dialog will now appear only once, making evaluation without interruption.

Ø       For printouts going across one page, you have option to scale it on a page or wrap on multiple pages.

Ø       Ready to use method to send print data to printer port - either from file, stream or bytes array

Ø       Specially for bulk printing - now you can dividing bulk print job in smaller batches (books) and print them individually to get rid of possible network congestion and long spooling time.

 

2.2  Toolkit

ElegantJ Printer Java Bean includes one set of beans:

 

Ø       ElegantJ Printer Bean: ElegantJ Printer (printer.jar)

 

 

 


 

3       Product Features

ElegantJ Printer Java Bean is implementation of Java printing and provides full printing functionality, including printing of any component, controlling spool size, background printing, configurable header and footer, preview and page setup. 

 

3.1  Operational functionalities

Ø       Highly Portable.  ElegantJ Printer Java Bean can be attached to any component irrespective of that component's support to printing in Java.

Ø       Provides special implementation for Java components - TextArea, JTextArea, JTextPane, Jtable

o        ElegantJ printer Java Bean provides special implementation for following components,

§         TextArea (Java AWT component)

§         JTextArea(Java swing component)

§         JTextPane(Java swing component)

§         JTable (Java swing component)

Ø       Support for Scaling as well as Wrapping.  ElegantJ Printer JavaBean makes it possible for you to decide to print / preview a big component on single page (by scaling it down) or by printing it on multiple pages (by wrapping).

Ø       You can have fast text printing on impact printers.

Ø       ElegantJ Printer Java Bean provides methods for background printing and to print on specific printer port, which accepts data from PRN file, bytes array and other input streams.

Ø       Provides facility to speed up printing by controlling spool size to avoid spooling delays and network congestions during bulk printing.

3.2  Page and Print Setup features

Ø       Customizable margins (top, bottom, left and right) in this Java Bean.

Ø       Support to set Page headers and footers with variable information.

o        Page headers and footers  

§         You can set content for left, center and right part of header and footer.

§         Supports variable information for header and footer.  e.g. current date, current time and page number.

§         ElegantJ Printer JavaBean allows customization of gaps (spaces) below header and above footer.

§         Using this Java Bean you can have a line below header and above footer.

Ø       Landscape and Portrait page orientation is available in this JavaBean.

Ø       You can set number of copies to print.

Ø       Print a specific page or a range of pages at a time.

Ø       Facility of Page Setup and Preview Dialog.

o        Page Setup and Preview Dialog

§         ElegantJ Printer Java Beans provides facility of Page Setup dialog box.  All the customizations that are available for this bean can be set using Page Setup dialog box.  This JavaBean also provides feature of Print Preview to view information on screen before it is sent to the printer.

Ø       This JavaBean supports all major standard paper types, including custom size.


 

4       Product Demo

 

4.1  Installing Demo

Extracted file(archive) contains demos directory.  All the demos are located in this demos directory.

 

Your classpath environment variables must be set correctly in order to run the demos.  For windows users we have provided rundemo.bat file which will run demo directly.  All Demo Applets contain HTML file to run an Applet associated with it.

 

For more information on how to set classpath, refer Installation procedure.

 

4.2  View Demo

Component printing demo applet

 

Description:  This demo applet demonstrates how to print components like JTable, JTextPane, JTextArea, TextArea and JComponent.

 

Run demo: To be able to run all the demo applets successfullly, you need to give "all permission" to the applet. This is done by adding line -

 

permission java.security.AllPermission;

 

as 1st line of grant code of "java.policy" file.

 

Some of the demo applets may not run successfully,

if above line is not present in grant block of "java.policy" file.

 

 

Component printing demo application

 

Description:  This demo application demonstrates how to print components like JTable, JTextPane, JTextArea, TextArea and JComponent.

 

Run demo: To run this demo application,

 

Go to ElegantJPrinter\demos\applications\printer_demo directory,

Then execute

java -jar printerapp.jar

Command

 

 

Fast printing demo application

 

Description: This demo application demonstrates how to write print data directly to printer for fast text printing.  It prints data from files check1.data, check2.data and check3.data to Port LPT1.

 

Run demo: To run this demo application,

 

Go to ElegantJPrinter\demos\applications\fast_printdirectory,

Then execute

java -jar printcheckdemo.jar

command

 

Note: Before running demo, please go through readme.txt available in ElegantJPrinter\demos\applications\fast_print directory.


 

5       Installation and Registration

 

5.1  Prerequisite

Before installing ElegantJBeans, please ensure that your computer system and development environment are setup and working as per expectations. Person evaluating ElegantJBeans is expected to be able to write and execute simple Java applications.

We provide free pre-purchase technical support to help you complete process of evaluation.  Mail to support@elegantJBeans.com for pre-purchase technical support.

 

To be able to use ElegantJBeans, your computer systems are required to have -

 

Ø       An IDE that supports Java 2 or higher, or

Ø       JDK 1.2.2 or higher

 

Please note that evaluation version of ElegantJBeans cannot be deployed for commercial, non-commercial or any other purpose in any possible way.  You may not build any software, applets or applications for distribution with evaluation version of ElegantJBeans.

 

This evaluation version is to be solely used by you to evaluate suitability of ElegantJbeans for your needs.  For more details please go through License Agreement.

 

5.2  Installation Procedure

On extracting ejprinter_v1.zip, following directories will be created inside ElegantJPrinter directory -

 

Directory [jars] contains Jar file(s)

Directory [demos] contains demo application(s) with source code

Directory [docs] contains path for document(s) access

 

 

Installing on Windows 95/98

 

To include ElegantJ Beanery in CLASSPATH, add following statement to your autoexec.bat file,

 

set CLASSPATH= %CLASSPATH%;C:\ELEGANTJ\<ELEGANTJ_BENARY_HOME>

\jars\<ELEGANTJ_BEAN>.jar;

 

Restart Windows to make changes effective.

 

 

Installing on Windows NT / 2000

 

Go to Control Panel and select System. You will find environment variables on Environment tab in Windows NT systems and on Advanced tab in Windows 2000 systems.

 

Find CLASSPATH environment variable or create it.

To include ElegantJ Beanary in the CLASSPATH, specify or add following value for variable -

 

[EXISTING-CLASSES];C:\<ELEGANTJ_BEANARY_HOME>\jars\<ELEGANTJ_BEAN>.jar

 

 

Installing on UNIX / Linux

 

Before you begin using ElegantJ Beanary, you must manually configure CLASSPATH environment variable.  CLASSPATH must point to the location of classes and installation directory.

 

For example, to set CLASSPATH for ElegantJ Beanary,

 

 

setenv CLASSPATH .:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/

<ELEGANTJ_BEAN>.jar:

 

If you are using Bourne Shell, commands are,

 

CLASSPATH= $CLASSPATH:.:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/

<ELEGANTJ_BEAN>.jar:export CLASSPATH

 

 

5.3  Using with Different IDEs

 

5.3.1Borland JBuilder

Follow the steps given below to create a new category and install Bean into Borland JBuilder.

 

Create a New Category

Ø       Click menu Tools > Configure Palette. It opens Palette Properties dialog box.

Ø       Click Add button. It opens Add Page Dialog box. Specify name (for example ElegantJ) and click OK.  New Category gets created.

 

Create New Library and Install / Import Bean

 

Ø       On Palette Properties dialog box, click Pages tab.  Select Newly created page (for example ElegantJ).

Ø       Click button Select Library. Select a Different Library dialog box opens.

Ø       Click New button on Select a Different Library dialog box. New Library Wizard dialog box opens.

Ø       Specify name for library and click Add button.  Select One or More Directory dialog box opens.

Ø       Select directory where jar files are located, or select jar file to be imported. Click OK. Dialog box gets closed and New Library Wizard dialog box appears in front.

Ø       Click OK on New Library Wizard. It opens Select a Different Library dialog box.

Ø       Confirm that newly created library is selected. Click OK. It opens Add Components under Palette Properties.

Ø       Click Add from Selected Libraries button.  It opens Results dialog box, click OK.

Ø       Results dialog box disappears.  Click OK on Palette Properties dialog box.

Ø       Beans are ready to use.

 

 

5.3.2Oracle JDeveloper

Follow the steps given below to import ElegantJBeans in Oracle JDeveloper.

 

To Import beans into a project

 

Ø       Click menu Project > Project Settings.  It opens Project Settings dialog box.

Ø       Click Libraries entry appearing on the pane on left side.

Ø       Click New button.  It opens New Library dialog box.

Ø       In Library Name entry box, specify Library name. In Location entry box, specify location where you want the library to be located.  In Class Path entry box, specify path of jar file of Bean. Browse the location by clicking Edit... button if required.

Ø       Click OK. The library you selected appears in Available Libraries list of Project Properties dialog box.

Ø       Select the library you want and click > button to add it to Selected Libraries list.

Ø       Click menu Tools > Configure Component Palette.  It opens Configure Component Palette dialog box.

Ø       To create a new palette page, click New Page... button.  It opens New Palette Page dialog box.  Specify Page Name and Page Type.  Click OK.  A new page with specified name will be created.

 

To add component to page

 

Ø       On Configure Component dialog box, from Pages list, select the page and click Add Component button.  It opens Add JavaBeans dialog box with available libraries.

Ø       Select a library from Library combo box.

Ø       Browse the hierarchy and select a component.  It displays preview of icon for selected component.  Click OK.  It shows Palette Confirmation dialog box.

Ø       Click Yes on Palette Confirmation dialog box to complete the process.

Ø       Beans are ready to use.

 

5.4  Getting Registered

 

5.4.1How to Purchase

You can purchase a license from our web site www.elegantJBeans.com

You can also contact our sales team sales@elegantJBeans.com

 

On purchasing a license, you will receive a mail having your license key.

 

License key can be applied to ElegantJ Java Bean using any of the following ways,

 

Ø       Using with Graphical User Interface of IDE

Ø       Using directly with source code

 

5.4.2Using with Graphical User Interface of IDE

While Designing an application or an applet graphically in an Integrated Development Environment, you will find a property named licensekey along with other properties of the bean.  Specify key (serial number) in LicenseKey Property.

 

Note: Instead of typing the license key, we suggest you to copy the license key from mail and paste it at required place.  Make sure that the selection does not have any leading or trailing spaces.

 

 

5.4.3Using directly with source code

 

When you use the Bean within code, you need to set the key by providing value in setLicenseKey Method.

 

Note: Instead of typing the license key, we suggest you to copy the license key from mail and paste it at required place.  Make sure that the selection does not have leading or trailing spaces.

 

 

ClassName object = new ClassName();

object.setLicenseKey("LICENSE_KEY");

 

 

Example

 

AWTTree awtTree = new AWTTree();

awtTree.setLicenseKey("LICENSE_KEY");

 

 


 

6       Programmers’ Guide

6.1  ElegantJ Printer

 

6.1.1Creating an instance of ElegantJ Printer

Ø       To create an instance of ElegantJ Printer, ElegantJ Printer can be instantiated with default constructor.

 

com.elegantj.util.printer.Printer printer = new com.elegantj.util.printer.Printer();

 

6.1.2Setting up Paper Type and Size

Available Paper Size with ElegantJ Printer Bean are -

 

Ø       com.elegantj.util.printer.Printer.A2_ENVELOP_TYPE

Ø       com.elegantj.util.printer.Printer.A4_TYPE

Ø       com.elegantj.util.printer.Printer.A5_TYPE

Ø       com.elegantj.util.printer.Printer.A6_CARD_TYPE

Ø       com.elegantj.util.printer.Printer.B5_TYPE

Ø       com.elegantj.util.printer.Printer.C6_ENVELOP_TYPE

Ø       com.elegantj.util.printer.Printer.CUSTOM_TYPE

Ø       com.elegantj.util.printer.Printer.DL_ENVELOP_TYPE

Ø       com.elegantj.util.printer.Printer.EXECUTIVE_TYPE

Ø       com.elegantj.util.printer.Printer.HAGAKI_CARD_TYPE

Ø       com.elegantj.util.printer.Printer.INDEX_CARD_4x6_TYPE

Ø       com.elegantj.util.printer.Printer.INDEX_CARD_5x8_TYPE

Ø       com.elegantj.util.printer.Printer.LEGAL_TYPE

Ø       com.elegantj.util.printer.Printer.LETTER_TYPE

Ø       com.elegantj.util.printer.Printer.N010_ENVELOP_TYPE

Ø       com.elegantj.util.printer.Printer.CUSTOM_TYPE

 

Ø       To set a paper type

 

printer.setPaperType(com.elegantj.util.printer.Printer.A4_TYPE);

 

If CUSTOM_TYPE is set, you need to specify paper width and height -

 

printer.setPaperType(com.elegantj.util.printer.Printer.CUSTOM_TYPE);

priner.setPaperSize(10, 8); 

// where width and height both are in inches

 

Ø       To retrieve paper width and paper height,

 

int paperWidth = printer.getPaperWidth(); // returns paper width in inches

int paperHeight = printer.getPaperHeight(); // returns paper height in inches

 

Ø       To retrieve imageable paper width and height

 

Imageable paper width and size is actual size of paper on which printing can be done.

 

int imageablePaperWidth = printer.getImageablePaperWidth();

int imageablePaperHeight = printer.getImageablePaperHeight();

 

Ø       To retrieve actual paper width and height

 

Actual paper width and height are width and height of the paper in which left, right, top and bottom margins are not included.

 

int actualPaperWidth = printer.getActualPaperWidth();

int actualPaperHeight = printer.getActualPaperHeight();

 

6.1.3Setting up margins and header / footer

Ø       To set left, right, top and bottom margins,

 

printer.setLeftMargin(1); // margin in inches

printer.setRightMargin(1); // margin in inches

printer.setTopMargin(1); // margin in inches

printer.setBottomMargin(1); // margin in inches

printer.setTopMargin(1); // margin in inches

printer.setBottomMargin(1); // margin in inches

printer.setTopMargin(1); // margin in inches

printer.setBottomMargin(1); // margin in inches

 

Ø       To set left, center, right header and footer.

 

printer.setLeftHeader("left header");

printer.setCenterHeader("center header");

printer.setRightHeader("right header");

printer.setLeftFooter("left footer");

printer.setCenterFooter("center footer");

printer.setRightFooter("right footer");

 

Ø       You can create header / footer string with combination of following string constants -

 

com.elegantj.util.printer.Printer.CURRENT_DATE

com.elegantj.util.printer.Printer.CURRENT_TIME

com.elegantj.util.printer.Printer.PAGE_NO

com.elegantj.util.printer.Printer.TOTAL_PAGES

 

Ø       To set current date in header / footer.

 

setXXXYYY("Date: "+com.elegantj.util.printer.Printer.CURRENT_DATE);

 

Ø       To set current time in header / footer.

 

setXXXYYY("Date: "+com.elegantj.util.printer.Printer.CURRENT_TIME);

 

Ø       To set page no. in header / footer

 

setXXXYYY("Page No.: "+com.elegantj.util.printer.Printer.PAGE_NO);

 

Ø       To set page no. / total no. of pages.

 

setXXXYYY("Page: " + com.elegantj.util.printer.Printer.PAGE_NO + " of " + com.elegantj.util.printer.Printer.TOTAL_PAGES);

 

where XXX = Left / Right and

         YYY = Header / Footer.

 

6.1.4Setting page Orientation

Page can be oriented as Portrait or Landscape -

 

Ø       com.elegantj.util.printer.Printer.LANDSCAPE

Ø       com.elegantj.util.printer.Printer.Printer.PORTRAIT

 

Ø       To set page orientation

 

printer.setPageOrientation(com.elegantj.util.printer.Printer.LANDSCAPE); // sets page orientation as landscape

 

6.1.5Setting number of copies

Ø       To set no. of copies.

 

printer.setNoOfCopies(5); // prints 5 copies of each page

 

6.1.6Showing a line below header and above footer

Ø       To show the line below header and line above footer.

 

printer.setLineBelowHeader(true); // which shows a line below header

printer.setLineAboveFooter(true); // which shows the line above footer

 

6.1.7Binding a component to Printer

Ø       To bind any component to the printer.

 

printer.setComponent(component); // which binds the component to the printer

 

6.1.8Applying Scaling and Wrapping

You can scale a component to single page or on multiple pages.  Set property as True to print it on single page.  Set it as False to print it on multiple pages through wrapping.

 

printer.setScaleComponentToSinglePage(true); // which turn on the scaling of the component to single page

printer.setScaleComponentToSinglePage(false); // which wrap the component on multiple pages

 

6.1.9Binding JTextArea, JTextPane, JTable, TextArea with Printer

Ø       To bind JTextArea with printer,

 

javax.swing.JTextArea jTextArea =

new javax.swing.JTextArea();

jTextArea.setText("JTextArea printing using ElegantJ Printer");

printer.setJTextArea(jTextArea);

 

Ø       To bind JTextPane with printer,

 

javax.swing.JTextPane jTextPane =

new javax.swing.JTextPane();

jTextPane.setText("JTextPane printing using ElegantJ Printer");

printer.setJTextPane(jTextPane);

 

Ø       To bind JTable with printer,

 

int rowCount = 10;

int columnCount = 5;

javax.swing.JTable table =

new javax.swing.JTable(rowCount, columnCount);

printer.setJTable(jTable);

 

Ø       To bind TextArea with printer

 

java.awt.TextArea textArea = new java.awt.TextArea();

textArea.setText("TextArea printing using ElegantJ Printer");

printer.setAWTTextArea(textArea);

 

6.1.10                  Working with Page Setup Control Dialog

ElegantJ Printer Bean provides facility of a Page Setup dialog box, that your user can use to specify page setup details.  With this user can -

 

Ø       set left, right, top and bottom margins

Ø       set left, center, right header and footer

Ø       set paper type and paper size

Ø       set page orientation

Ø       set number of copies

Ø       turn on / off the line below header and above footer

 

Ø       To open page setup dialog,

 

Printer printer = new Printer();

printer.pageSetup(); // displays page setup dialog

or

printer.pageSetup(jFrame); // displays page setup dialog with jFrame as parent

 

6.1.11                  Opening Print Preview

ElegantJ Printer's Print Preview facility provides easy navigation through all the pages, Zoom In and Zoom out facility.

 

Ø       To open the preview dialog.

 

printer.preview(); // displays the preview dialog

or

printer.preview(jFrame); // displays the preview dialog with jFrame as parent

 

6.1.12                  Handling Bulk Print Jobs (by controlling spool size)

Pages are spooled before they are printed.  Spooling will take long time if number of pages is more.  You can control spool size by printing books individually (at a time).  Next two points focuses on how you can control spool size.

 

Ø       Print book individually, and

Ø       Book size

 

Print book individually

Printing of large number of pages takes long time for spooling followed by printing.  To reduce delay in printing due to this, it is suggested to print books individually.

 

Set value of this property to True to stop spooling of entire print job.  As a result of this, computer spools a pre-set number of pages (user configurable) and prints it.  It print books individually.  Each book contains number of pages set as value of BookSize property.

 

printer.setPrintBookIndividually(true);

 

Book Size

If PrintBookIndividually property is set to true, then value set in BookSize property is considered for spooling.  This way a large print job is divided into smaller print jobs known as individual books.

 

printer.setPrintBookIndividually(true);

printer.setBookSize(5);  // does not spool all the pages, considers 5 pages per book

 

e.g.

Divide a 200 page print job in 20 smaller jobs of 10 pages each.  This will enable Java application to print this big job smoothly without any spooling delays or network congestions.

 

6.1.13                  Implementing Printing - print methods for printing

Ø       print()

 

This method prints all pages.

 

printer.print();

 

Ø       print(int pageIndex) 

 

This method prints specified page with pageIndex, pageIndex is zero based page index.  This method starts printing without showing print dialog.

 

printer.print(pageIndex)

 

Ø       print(int startPageIndex, int endPageIndex)

 

This method prints pages range specified with startPageIndex and endPageIndex, both page indexes are inclusive. This method starts printing without showing print dialog.

 

printer.print(startPageIndex, endPageIndex);

 

Ø       print(FileInputStream fis)

 

This method prints content of FileInputStream on printer target port.

 

printer.print(fileInputStream);

 

Ø       print(FileInputStream fis, String port)

 

This method prints content of FileInputStream, on specified printer target port.

 

printer.print(fileInputStream, port);

 

Ø       print(byte[] bytes)

 

This method prints content of bytes array on printer target port.

 

printer.print(bytes);

 

 

Ø       print(byte[] bytes, String port)

 

This method prints content of bytes array, on specified printer target port.

 

printer.print(bytes, port);

 

6.1.14                  Setting up port for direct printing on target port

This port will be considered for printing only if any one of the methods listed below is called -

 

print(FileInputStream fis)

print(byte[] bytes)

 

Ø       To configure target printer port, use Port Property

 

Printer printer = new Printer();

printer.setPort("LPT1");

 

Default Value : Default value is LPT1

 

Example for target port : LPT1, LPT2 or \\machine1\\xyz where machine1 is the name of the network computer and xyz is the printer port.

 

6.1.15                  Printer Listeners and Events

ElegantJ Printer provides the following event.

 

Event Name - PrintEvent

 

When is it invoked - when printing is going on.

 

6.1.16                  Extending Printing Support to your own component

Ø       To extend printing support to your own component, override two methods of com.elegantj.util.printer.Printer class given below - 

 

public int getNoOfPages()

 

This returns number of pages.

 

protected int Print(java.awt.Graphics graphics, com.elegantj.util.printer.PageFormat f, int pageIndex)

 

This implements printing.  If page exists then this method returns java.awt.print.Printable.PAGE_EXISTS.  If page does not exist, it returns java.awt.print.Printable.NO_SUCH_PAGE.

 

6.1.17                  Removing Header and footer

Ø       To remove headers

 

printer.setLeftHeader(""); // removes left header

printer.setCenterHeader(""); // removes center header

printer.setRightHeader(""); // removes right header

 

This removes all headers.

 

Ø       To remove footers

 

printer.setLeftFooter(""); // removes left footer

printer.setCenterFooter(""); // removes center footer

printer.setRightFooter(""); // removes right footer

 

This removes all footers.

 

Note: On Mac OS, on removing header or footer it gives run time error while printing a page.  So, instead of setting header or footer to a blank string, set header or footer values to one blank space.  e.g.

 

printer.setLeftHeader(" ");

 

6.1.18                  Removing line below header and above footer

Ø       To remove line below header

 

printer.setShowLineBelowHeader(false);

 

This removes line below header.

 

Ø       To remove line above footer

 

printer.setShowLineAboveFooter(false);

 

This removes line above footer.

 

6.1.19                  Printing large component on single page with scaling down

Ø       To print big component on a single page,

 

printer.setScaleComponentToSinglePage(true);

 

This allows to print / preview big component on to single page by scaling it down to a single page.

 

6.1.20                  Printing large component on multiple pages with wrapping

Ø       To print big component on multiple pages,

 

printer.setScaleComponentToSinglePage(false);

 

This allows to print / preview big component on multiple pages through wrapping.

 

6.1.21                  Keeping spool size small while printing large number of pages

Ø       First of all set the book size i.e. number of pages you want to print at a time.  Default value of book size is 1.

 

printer.setBookSize(2);

 

This sets book size to 2.

 

Ø       After setting book size, turn on following property to print books individually.

 

printer.setPrintBookIndividually(true);

 

This turns on printing of books (2 pages at a time).

 

6.1.22                  Disabling Printing from Preview Dialog Box

Ø       To disable printing through print button of Preview dialog,

 

When you create an instance of ElegantJ Printer, override print method of the com.elegantj.util.printer.Printer class, in following way,

 

com.elegantj.util.printer.Printer printer = new com.elegantj.util.printer.Printer()

{

     public void print()

     {

     }

};

 

On overriding print method of Printer class, user cant take printouts through Print button of preview dialog.

 


7       Product and Support Information

 

Product and Support Information:

Ø       You can find more information about ElegantJ Printer and its features on www.ElegantJBeans.com.

Ø       Forward your support related mails to support@ElegantJBeans.com.

Ø       Forward your sales related mails to sales@ElegantJBeans.com.

 

Feedback and Suggestions:

Ø       We will be pleased to get your feedback as well as suggestions about our product.

Ø       Forward any feedback or suggestions related mails to support@ElegantJBeans.com.