Re: [Retep-PDF] code snippets
Status: Beta
Brought to you by:
petermount
|
From: Peter M. <pe...@re...> - 2004-07-21 08:41:29
|
Paul wrote:
> Trying to make use of the retep code using the Java printer services.
>=20
> Anyone have any snippets that make use of=20
> DocFlavor.SERVICE_FORMATTED.PRINTABLE =96 I am particularly interested =
in=20
> the print() method of a Printable that draws a large image(2k+ x 1k+) t=
o=20
> the graphics context.
Something like this would do it:
public class TestPrt implements Printable {
public int print(java.awt.Graphics graphics,=20
java.awt.print.PageFormat pageFormat, int pageIndex) throws=20
java.awt.print.PrinterException {
return NO_SUCH_PAGE;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
PrintService services[] =3D=20
PrintServiceLookup.lookupPrintServices(null, null);
PrintService sve =3D null;
for(int i=3D0;i<services.length;i++) {
if(services[i].getName().startsWith("Retep PDF")) {
System.err.println("Whoho "+i);
sve =3D services[i];
}
}
DocPrintJob dpj =3D sve.createPrintJob();
Printable myPrintable =3D new TestPrt();
Doc doc =3D new=20
SimpleDoc(myPrintable,DocFlavor.SERVICE_FORMATTED.PRINTABLE,null);
PrintRequestAttributeSet attrs =3D new HashPrintRequestAttributeSe=
t();
attrs.add(
new Destination(
new URI("file:/home/peter/output.pdf")
)
);
attrs.add(OrientationRequested.LANDSCAPE);
attrs.add(MediaSizeName.ISO_A3);
dpj.print(doc,attrs);
}
}
Just implement the print() method as you would normally for printing.
Peter
--=20
Peter Mount
pe...@re...
http://retep.org/
http://retep.net/
Tel: +44 (0) 1622 749439
Fax: +44 (0) 8701 361620
Mobile: +44 (0) 7838 191423
IM-MSN: ret...@ho...
|