Hi Muralidhar,
we do the same, but the best way I found is to use FOP to create
postscript and send this directly to PS-enabled printers.
This works fairly well, but leaves most Inkjet-Printer aside as they
usually cannot interpret postscript.
Regards,
Alex
Here is some sample code:
DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintRequestAttributeSet attributes = new
HashPrintRequestAttributeSet();
attributes.add(MediaSizeName.ISO_A4);
PrintService[] services =
PrintServiceLookup.lookupPrintServices(flavor, attributes);
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
// You do not have to use this dialog
// Just select the PrintService via getName() and manuelly modify
your PrintRequestAttributeSet
PrintService service = ServiceUI.printDialog(null, 200,
200, services, defaultService, flavor, attributes);
if (service != null) {
StringBuffer info = new StringBuffer();
info.append(service.getName()).append(": ");
for(Attribute attribute : attributes.toArray()) {
System.out.println("attribute: " + attribute);
if (attribute instanceof MediaTray) {
MediaTray tray = (MediaTray) attribute;
info.append(tray).append(" (").append(tray.getValue()).append(")");
}
}
File psFile = TemporaryFile.create("ps");
log.info("creating postscript file at: " +
psFile.getAbsolutePath());
// This is just a helper tool I wrote for FOP using MIME-TYPE
postscript
// replace this with your FOP transformation
FOPTransformer.getInstance().createPostscript(psFile,
xml, xsl);
final InputStream is = new FileInputStream(psFile);
SimpleDoc doc = new SimpleDoc(is, flavor, null);
DocPrintJob job = service.createPrintJob();
job.addPrintJobListener(new PrintJobAdapter() {
public void
printDataTransferCompleted(PrintJobEvent pje) {
log.info("print-job transfer completed");
printJobEnded();
}
public void printJobNoMoreEvents(PrintJobEvent
pje) {
log.info("print-job no more events");
printJobEnded();
}
public void printJobCompleted(PrintJobEvent pje) {
log.info("print-job completed");
printJobEnded();
}
public void printJobCanceled(PrintJobEvent pje) {
log.info("print-job cancelled");
printJobEnded();
}
public void printJobFailed(PrintJobEvent pje) {
log.info("print-job failed");
printJobEnded();
}
public void
printJobRequiresAttention(PrintJobEvent pje) {
log.info("print-job attention");
}
private synchronized void printJobEnded() {
try {
is.close();
} catch (IOException exc) {
exc.printStackTrace();
}
}
});
job.print(doc, attributes);
}
Am 25.01.2008 um 22:53 schrieb Jeremias Maerki:
On 25.01.2008 22:37:38 mikeanderson wrote:
Muralidhar,
I am also getting same king of problem. I have already existing
pdf
file. I want to print the pdf file without user interaction. I
have goggled
and got some information.
InputStream is = new BufferedInputStream(
new FileInputStream("c:\\test.pdf"));
// Here we need to convert pdf to pcl using fop
byte[] data = null; /* the fop output */;
DocFlavor flavor = DocFlavor.BYTE_ARRAY.PCL;
PrintService service =
PrintServiceLookup.lookupDefaultPrintService();
DocFlavor[] flavors = service.getSupportedDocFlavors();
// Create the print job
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(data, flavor, null);
// Print it
job.print(doc, null);
Murali , The above code may gives you some idea to print pdf ,
but we
have to know how to convert PDF file to PCL using FOP.
FOP cannot convert PDF into anything!!!! FOP can only produce PDF! You
need a different tool.
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
______________________________________________________________
Alexander Lohse • Entwicklungsleitung & Projektmanagement
Tel +49 38374 752 11 • Fax +49 38374 752 23
http://www.humantouch.de
Human Touch Medienproduktion GmbH
Am See 1 • 17440 Klein Jasedow • Deutschland
Geschäftsführung:
Lara Mallien, Nele Hybsier, Alexander Lohse, Johannes Heimrath (Senior)
Handelsregister Stralsund • HRB 4192 • USt-IdNr. DE128367684
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]