Package systole.ioHandling.printers

Source Code of systole.ioHandling.printers.PrinterManager

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package systole.ioHandling.printers;

import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPrintPage;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import systole.view.utils.ErrorDialog;

/**
*
* @author jmj
*/
public class PrinterManager {

 

    /**
     * @param file
     */
    public void printReport(File file) {
        try {

            FileInputStream fis = new FileInputStream(file);
            FileChannel fc = fis.getChannel();
            ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
            PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page
            PDFPrintPage pages = new PDFPrintPage(pdfFile);

// Create Print Job
            PrinterJob pjob = PrinterJob.getPrinterJob();
            PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
            pjob.setJobName(file.getName());
            Book book = new Book();
            book.append(pages, pf, pdfFile.getNumPages());
            pjob.setPageable(book);

            if (pjob.printDialog()) {
                pjob.print();
            }
// Send print job to default printer
        } catch (FileNotFoundException ex) {
            ErrorDialog.showError(null, "No se pudo imprimir el reporte");
        } catch (IOException ex) {
            ErrorDialog.showError(null, "No se pudo imprimir el reporte");
        } catch (PrinterException ex) {
            ErrorDialog.showError(null, "No se pudo imprimir el reporte");
        }
    }
}
TOP

Related Classes of systole.ioHandling.printers.PrinterManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.