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();
}
}
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);
}
}
}
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;
}
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();
}
}
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;
}
Aggregations