Search in sources :

Example 1 with PageFormat

use of java.awt.print.PageFormat in project adempiere by adempiere.

the class Document method writePDF.

private static void writePDF(Pageable pageable, OutputStream output) {
    try {
        final PageFormat pf = pageable.getPageFormat(0);
        final com.lowagie.text.Document document = new com.lowagie.text.Document(new Rectangle((int) pf.getWidth(), (int) pf.getHeight()));
        final PdfWriter writer = PdfWriter.getInstance(document, output);
        writer.setPdfVersion(PdfWriter.VERSION_1_2);
        document.open();
        final DefaultFontMapper mapper = new DefaultFontMapper();
        //Elaine 2009/02/17 - load additional font from directory set in PDF_FONT_DIR of System Configurator 
        String pdfFontDir = MSysConfig.getValue(PDF_FONT_DIR, "");
        if (pdfFontDir != null && pdfFontDir.trim().length() > 0) {
            pdfFontDir = pdfFontDir.trim();
            File dir = new File(pdfFontDir);
            if (dir.exists() && dir.isDirectory())
                mapper.insertDirectory(pdfFontDir);
        }
        //
        final float w = (float) pf.getWidth();
        final float h = (float) pf.getHeight();
        final PdfContentByte cb = writer.getDirectContent();
        for (int page = 0; page < pageable.getNumberOfPages(); page++) {
            if (page != 0) {
                document.newPage();
            }
            final PdfTemplate tp = cb.createTemplate(w, h);
            final Graphics2D g2 = tp.createGraphics(w, h, mapper);
            tp.setWidth(w);
            tp.setHeight(h);
            pageable.getPrintable(page).print(g2, pf, page);
            g2.dispose();
            cb.addTemplate(tp, 0, 0);
            writer.releaseTemplate(tp);
        }
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) Rectangle(com.lowagie.text.Rectangle) DefaultFontMapper(com.lowagie.text.pdf.DefaultFontMapper) PdfTemplate(com.lowagie.text.pdf.PdfTemplate) Graphics2D(java.awt.Graphics2D) PageFormat(java.awt.print.PageFormat) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) File(java.io.File)

Example 2 with PageFormat

use of java.awt.print.PageFormat in project adempiere by adempiere.

the class PDFViewerBean method print.

public void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    //decoder.enableScaledPrinting(false);
    printJob.setPageable(decoder);
    final PageFormat pf = printJob.defaultPage();
    decoder.setPageFormat(pf);
    decoder.setTextPrint(PdfDecoder.TEXTGLYPHPRINT);
    printJob.setPrintable(decoder, pf);
    if (printJob.printDialog()) {
        final Cursor oldCursor = getCursor();
        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            printJob.print();
        } catch (PrinterException e) {
            e.printStackTrace();
        } finally {
            setCursor(oldCursor);
        }
    }
}
Also used : PageFormat(java.awt.print.PageFormat) PrinterException(java.awt.print.PrinterException) Cursor(java.awt.Cursor) PrinterJob(java.awt.print.PrinterJob)

Example 3 with PageFormat

use of java.awt.print.PageFormat in project adempiere by adempiere.

the class CPaper method getPageFormat.

//  getPrintRequestAttributes
/*************************************************************************/
/**
	 * 	Get the Page Format for the Papaer
	 * 	@return Page Format
	 */
public PageFormat getPageFormat() {
    PageFormat pf = new PageFormat();
    pf.setPaper(this);
    int orient = PageFormat.PORTRAIT;
    if (m_landscape)
        orient = PageFormat.LANDSCAPE;
    pf.setOrientation(orient);
    return pf;
}
Also used : PageFormat(java.awt.print.PageFormat)

Example 4 with PageFormat

use of java.awt.print.PageFormat in project jgnash by ccavanaugh.

the class DynamicJasperReportPanel method pageSetupAction.

private void pageSetupAction() {
    PageFormat oldFormat = report.getPageFormat();
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat format = job.pageDialog(oldFormat);
    if (format != oldFormat) {
        report.setPageFormat(format);
        refreshReport();
    }
}
Also used : PageFormat(java.awt.print.PageFormat) PrinterJob(java.awt.print.PrinterJob)

Example 5 with PageFormat

use of java.awt.print.PageFormat in project jgnash by ccavanaugh.

the class ReportPrintFactory method getPageFormat.

static PageFormat getPageFormat(final BaseDynamicJasperReport report) {
    Preferences p = report.getPreferences();
    double height = p.getDouble(HEIGHT, 0);
    double width = p.getDouble(WIDTH, 0);
    int orientation = p.getInt(ORIENTATION, 0);
    double imageableHeight = p.getDouble(IMAGEABLE_HEIGHT, 0);
    double imageableWidth = p.getDouble(IMAGEABLE_WIDTH, 0);
    double imageableX = p.getDouble(IMAGEABLE_X, 0);
    double imageableY = p.getDouble(IMAGEABLE_Y, 0);
    if (height == 0 || width == 0 || imageableHeight == 0 || imageableWidth == 0) {
        return getDefaultPage();
    }
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    pf.setOrientation(orientation);
    Paper paper = pf.getPaper();
    paper.setSize(width, height);
    paper.setImageableArea(imageableX, imageableY, imageableWidth, imageableHeight);
    pf.setPaper(paper);
    return pf;
}
Also used : PageFormat(java.awt.print.PageFormat) Paper(java.awt.print.Paper) Preferences(java.util.prefs.Preferences) PrinterJob(java.awt.print.PrinterJob)

Aggregations

PageFormat (java.awt.print.PageFormat)61 Paper (java.awt.print.Paper)23 PrinterJob (java.awt.print.PrinterJob)22 PrinterException (java.awt.print.PrinterException)19 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)12 PrintService (javax.print.PrintService)11 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)10 Printable (java.awt.print.Printable)9 BufferedImage (java.awt.image.BufferedImage)8 Graphics2D (java.awt.Graphics2D)7 File (java.io.File)6 IOException (java.io.IOException)6 MediaSize (javax.print.attribute.standard.MediaSize)6 HeadlessException (java.awt.HeadlessException)5 StreamPrintService (javax.print.StreamPrintService)5 Media (javax.print.attribute.standard.Media)5 MediaSizeName (javax.print.attribute.standard.MediaSizeName)5 Dimension (java.awt.Dimension)4 Rectangle (java.awt.Rectangle)4 Rectangle2D (java.awt.geom.Rectangle2D)4