Not a Question. I have a piece of source to contribute ;-)
- From: ÎÏÎÎÎÎÏ ÎÎÎÎÎÎÎÏ <i.canellos (at) alpha-inf.gr>
- Date: Tue, 07 Feb 2006 10:36:32 +0200
I've been seeking ways to direct send a pdf file to the printer, without
having to use external programms such as acroread.
In your FAQ you mention that this is impossible, but I managed to do it !!!
This solution is multiplatform
The general ideas is to use a PdfWriter that writes into a piped
outputstream connected to the inputstream that feeds the Printer Doc.
public void printPDF(){
createBook();
BaseFont arial, courier, timesnewroman;
try{
PipedInputStream pdf_in = new PipedInputStream();
PipedOutputStream pdf_out = new PipedOutputStream();
DocFlavor myFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
pdf_in.connect(pdf_out);
Doc d = new SimpleDoc(pdf_in,myFlavor,new HashDocAttributeSet());
PDF_Thread pt = new PDF_Thread (pdf_out);
pt.start();
PrintService[] ps =
PrintServiceLookup.lookupPrintServices(myFlavor, null);
boolean bool = true;
PrintService service = ServiceUI.printDialog(null, 100, 100, ps,
ps[0], myFlavor, null);
DocPrintJob dpj = service.createPrintJob();
dpj.print(d, pas);
}catch(Exception e){e.printStackTrace(System.out);}
}
public class PDF_Thread extends Thread{
public PDF_Thread(OutputStream os){ this.os = os; }
public void run(){
try{
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, os);
document.open();
document.setPageCount(this.book.getNumberOfPages());
document.newPage();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(500,500);
Graphics2D g2 = tp.createGraphics(500,500, mapper);
g2.drawString("Hello World !!!",100,100);
cb.addTemplate(tp, 0, -0);
g2.dispose();
document.close();
}catch(Exception e){ e.printStackTrace(System.out);}
}
}
begin:vcard
fn;quoted-printable:=CE=99=CF=89=CE=AC=CE=BD=CE=BD=CE=B7=CF=82 =CE=9A=CE=B1=CE=BD=CE=AD=CE=BB=
=CE=BB=CE=BF=CF=82
n;quoted-printable;quoted-printable:=CE=9A=CE=B1=CE=BD=CE=AD=CE=BB=CE=BB=CE=BF=CF=82;=CE=99=CF=89=CE=AC=CE=BD=CE=BD=CE=B7=CF=82
email;internet:i.canellos@alpha-inf.gr
tel;work:(30)2106144459
version:2.1
end:vcard