From 23f980f919e20948ccf9f37c3108e8fde0c02507 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Mon, 14 Jan 2008 18:11:59 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@655 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../src/siprp/ficha/PDFFilePrinter.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 trunk/SIPRPSoft/src/siprp/ficha/PDFFilePrinter.java diff --git a/trunk/SIPRPSoft/src/siprp/ficha/PDFFilePrinter.java b/trunk/SIPRPSoft/src/siprp/ficha/PDFFilePrinter.java new file mode 100644 index 00000000..01068e9e --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/ficha/PDFFilePrinter.java @@ -0,0 +1,60 @@ +package siprp.ficha; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.print.PageFormat; +import java.io.File; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; + +import com.evolute.utils.print.A4ContinuoPage; +import com.evolute.utils.print.AbstractPrintHandler; +import com.sun.pdfview.PDFFile; +import com.sun.pdfview.PDFPage; +import com.sun.pdfview.PDFRenderer; + +public class PDFFilePrinter extends AbstractPrintHandler +{ + protected byte pdf[]; + protected PDFFile pdffile; + + public PDFFilePrinter(byte pdf[], boolean printDialog ) + throws Exception + { + super( new A4ContinuoPage(), printDialog ); + + this.pdf = pdf; + ByteBuffer buffer = ByteBuffer.allocate( pdf.length ); + buffer.put( pdf ); +// + +// File file = new File("/home/fpalma/Desktop/icons_op.pdf"); +// +// // set up the PDF reading +// RandomAccessFile raf = new RandomAccessFile(file, "r"); +// FileChannel channel = raf.getChannel(); +// ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); + pdffile = new PDFFile(buffer); + setNumberOfPages( pdffile.getNumPages() ); + print(); + } + + protected void paintGraphics( Graphics g, PageFormat pf, int index ) + { + try + { + PDFPage page = pdffile.getPage( index ); + PDFRenderer renderer = new PDFRenderer(page, ( Graphics2D ) g, + new Rectangle(0, 0,(int) page.getWidth(), (int) page.getHeight()), null, Color.RED); + page.waitForFinish(); + renderer.run(); + } + catch( Exception ex ) + { + ex.printStackTrace(); + } + } +}