Spurious printing: AWTRenderer, FOP

K

KarthikR79

Hi,
I am using Apache FOP (org.apache.fop.render.awt.AWTRenderer) to print
the FOP XML to printer.

Java: JRE 1.5.0
OS: Windows XP
Printer: Xerox Phaser 8550 - Color

Every now and then (intermittent), I get unwanted - hundreds and
hundreds of printouts from the printer and yes there are that many
print jobs from the application to the printer in print queue. The
number of copies is not set from my code explicitly.

The pattern is when it prints hundred pages:
50 pages will print out "offending command: timeout" and 50 pages has
application rendered FOP XML (Most of them partially printed prinouts).


Application prints out just one copy of FOP XML.

Don't know why this intermittent behaviour happens?

Is this caused by:

1. Printer spooler (windows XP?) attempting to re-send the job again
and again which is not printing properly
2. Known issues in printing via AWTRenderer, PrinterJob
3. Xerox Printer driver issue
4. A strange character in the FOP XML causing this?

====================================================
Code:

class prjPrintRenderer extends AWTRenderer {

private static final int intEvenAndAll = 0;

private static final int intEven = 1;

private static final int intOdd = 2;

private int intStartNumber;

private int intEndNumber;

private int intMode = intEvenAndAll;

private int intCopies = 1;

private PrinterJob objPrinterJob;

private PrintRequestAttributeSet objPrntReqAttSet;

prjLogger logger =
new prjLogger(prjPrintRenderer.class);

/**
* @param printerJob
* To prjPrintRenderer
* @throws prjException
*
* The constructor method.
*/
prjPrintRenderer(PrinterJob printerJob)
throws prjException
{
super(null);

try
{
this.objPrinterJob = printerJob;
intStartNumber = 0;
intEndNumber = -1;
printerJob.setPageable(this);

intMode = intEvenAndAll;
String strEvenValue = System.getProperty("even");
if (strEvenValue != null)
{
intMode = Boolean.valueOf(strEvenValue)
.booleanValue() ? intEven : intOdd;
}
}
catch (Exception exception)
{
logger.error("Exception in " +
"prjPrintRenderer.Ctor",
exception);
throw new prjException(exception);
}
}

public void setPrintAttributesSet
(PrintRequestAttributeSet objPrntReqAttSet)
{
this.objPrntReqAttSet = objPrntReqAttSet;
}

public void stopRenderer(OutputStream outputStream)
{
try
{
super.stopRenderer(outputStream);

if (intEndNumber == -1)
{
intEndNumber = getPageCount();
}
Vector objVecNumbers = getInvalidPageNumbers();

for (int intCount = objVecNumbers.size() - 1;
intCount > -1; intCount--)
{
removePage(Integer.
parseInt((String) objVecNumbers.elementAt(intCount)));
}

// Actual Print Start
objPrinterJob.print(objPrntReqAttSet);
// Actual Print End
}
catch (Exception exception)
{
logger.error("Exception in " +
"prjPrintRenderer.stopRenderer",
exception);
prj.prj.generateErrorPage();
}
}

public void renderPage(Page page)
{
try
{
pageWidth = (int) (page.getWidth() / 1000f);
pageHeight = (int) (page.getHeight() / 1000f);
super.renderPage(page);
}
catch (Exception exception)
{
logger.error("Exception in " +
"prjPrintRenderer.renderPage",
exception);
prj.prj.generateErrorPage();
}
}

private Vector getInvalidPageNumbers()
{
Vector objVector = new Vector();
int intMax = getPageCount();
boolean blnIsValid;
for ( int intCount = 0; intCount < intMax; intCount++) {
blnIsValid = true;
if (intCount < intStartNumber || intCount > intEndNumber) {
blnIsValid = false;
} else if (intMode != intEvenAndAll) {
if (intMode == intEven && ((intCount + 1) % 2 != 0))
blnIsValid = false;
else if (intMode == intOdd && ((intCount + 1) % 2 !=
1))
blnIsValid = false;
}
if (!blnIsValid)
objVector.add(intCount + "");
}
return objVector;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top