I'm trying to send my rendered PDF directly to the server-side printer. I'm
using a Document class and a stream to the XSLT file. This works and my
printer prints out the PDF. The only problem I have is that the image
included at the top of the page doesn't come out. I also have a page number
at the bottom of the page (region-after to be precise) and that doesn't get
printed either. Using the same code to render the PDF to the client via a
browser prints the image and the page numbers fine. Here's the code I'm
using:

------------

Driver driver = null;
PrinterJob pj = PrinterJob.getPrinterJob();
PrintRenderer renderer = new PrintRenderer(pj);

/*If any of these values are null then give up immediately*/

if (doc == null) {

  System.out.println("Document is null, no point in carrying on...");
  return false;
}

if (xslFile == null) {

  System.out.println("xslFile is null, no point in carrying on...");
  return false;
}

driver = new Driver();

pj.setCopies(1);
driver.setRenderer(renderer);

try {

        Transformer transformer =
TransformerFactory.newInstance().newTransformer(new StreamSource (xslFile));

        transformer.transform(new DOMSource(doc), new
SAXResult(driver.getContentHandler()));
}

/*If an exception occurs during the transformation, catch it and return
null*/

catch (TransformerConfigurationException tce) {

        System.out.println("TransformerConfigurationException: " +
tce.getMessage());
        return false;
}

catch (TransformerException te) {

        System.out.println("TransformerException: " + te.getMessage());
        return false;
}

/*Everything went fine, return true*/

return true;

--------------

The code for rendering to the browser is only slightly different (get the
output stream and use a printWriter etc.) I'm using a landscape layout,
would that make any difference? The printer is an P LaserJet 2100 Series PS.

Reply via email to