use of java.awt.print.PageFormat in project jgnash by ccavanaugh.
the class ReportPrintFactory method getPageFormat.
/**
* Generates a {@code PageFormat} given a {@code Preferences} node
* @param p {@code Preferences} node
* @return restored {@code PageFormat} or the default if it has not been saved before
*/
public static PageFormat getPageFormat(final Preferences p) {
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();
}
final PageFormat pf = new PageFormat();
pf.setOrientation(orientation);
Paper paper = pf.getPaper();
paper.setSize(width, height);
paper.setImageableArea(imageableX, imageableY, imageableWidth, imageableHeight);
pf.setPaper(paper);
return pf;
}
use of java.awt.print.PageFormat in project jgnash by ccavanaugh.
the class ReportPrintFactory method getDefaultPage.
/**
* Returns the default paper size for a report
*
* @return page format
*/
public static PageFormat getDefaultPage() {
/* A4 is the assumed default */
PageSize defaultPageSize = PageSize.A4;
/* US and Canada use letter size as the default */
final Locale[] letterLocales = new Locale[] { Locale.US, Locale.CANADA, Locale.CANADA_FRENCH };
if (Arrays.asList(letterLocales).contains(Locale.getDefault())) {
defaultPageSize = PageSize.LETTER;
}
/* Create the default paper size with a default margin */
final Paper paper = new Paper();
double width = defaultPageSize.width;
double height = defaultPageSize.height;
paper.setSize(width, height);
paper.setImageableArea(DEFAULT_MARGIN, DEFAULT_MARGIN, width - (2 * DEFAULT_MARGIN), height - (2 * DEFAULT_MARGIN));
final PageFormat format = new PageFormat();
format.setPaper(paper);
return format;
}
use of java.awt.print.PageFormat in project jgnash by ccavanaugh.
the class PDFBoxTableTest method crossTabReportTest.
@Test
void crossTabReportTest() throws IOException {
Path tempPath = null;
Path tempRasterPath = null;
try (final Report report = new SimpleReport()) {
tempPath = Files.createTempFile("pdfTest", ".pdf");
tempRasterPath = Files.createTempFile("pdfTest", ".png");
final float padding = 2.5f;
report.setTableFont(PDType1Font.COURIER);
report.setHeaderFont(PDType1Font.HELVETICA_BOLD);
report.setCellPadding(padding);
report.setBaseFontSize(9);
report.setForceGroupPagination(true);
final PageFormat pageFormat = (PageFormat) report.getPageFormat().clone();
pageFormat.setOrientation(PageFormat.LANDSCAPE);
report.setPageFormat(pageFormat);
report.setFooterFont(PDType1Font.TIMES_ITALIC);
report.setEllipsis("…");
assertEquals(2, GroupInfo.getGroups(new CrossTabTestReport()).size());
report.addTable(new CrossTabTestReport());
report.addFooter();
report.saveToFile(tempPath);
assertTrue(report.isLandscape());
assertEquals(padding, report.getCellPadding());
assertTrue(Files.exists(tempPath));
// Create a PNG file
final BufferedImage bim = report.renderImage(0, 300);
ImageIOUtil.writeImage(bim, tempRasterPath.toString(), 300);
assertTrue(Files.exists(tempRasterPath));
} catch (final IOException e) {
e.printStackTrace();
} finally {
if (tempPath != null) {
Files.deleteIfExists(tempPath);
}
if (tempRasterPath != null) {
Files.deleteIfExists(tempRasterPath);
}
}
}
use of java.awt.print.PageFormat in project jgnash by ccavanaugh.
the class PDFBoxTableTest method basicReportTest.
@Test
void basicReportTest() throws IOException {
Path tempPath = null;
Path tempRasterPath = null;
try (final Report report = new SimpleReport()) {
tempPath = Files.createTempFile("pdfTest", ".pdf");
tempRasterPath = Files.createTempFile("pdfTest", ".png");
final float padding = 2.5f;
report.setTableFont(PDType1Font.COURIER);
report.setHeaderFont(PDType1Font.HELVETICA_BOLD);
report.setCellPadding(padding);
report.setBaseFontSize(9);
final PageFormat pageFormat = ReportPrintFactory.getDefaultPage();
pageFormat.setOrientation(PageFormat.LANDSCAPE);
report.setPageFormat(pageFormat);
report.setFooterFont(PDType1Font.TIMES_ITALIC);
report.setEllipsis("…");
assertEquals(1, GroupInfo.getGroups(new BasicTestReport()).size());
// assertEquals(80, ((GroupInfo) GroupInfo.getGroups(new BasicTestReport()).toArray()[0]).rows);
report.addTable(new BasicTestReport());
report.addFooter();
report.saveToFile(tempPath);
assertTrue(report.isLandscape());
assertEquals(padding, report.getCellPadding());
assertTrue(Files.exists(tempPath));
// Create a PNG file
final BufferedImage bim = report.renderImage(0, 300);
ImageIOUtil.writeImage(bim, tempRasterPath.toString(), 300);
assertTrue(Files.exists(tempRasterPath));
} catch (final IOException e) {
e.printStackTrace();
} finally {
if (tempPath != null) {
Files.deleteIfExists(tempPath);
}
if (tempRasterPath != null) {
Files.deleteIfExists(tempRasterPath);
}
}
}
use of java.awt.print.PageFormat in project netbeans-mmd-plugin by raydac.
the class Pages method getPreferredSize.
@Override
@Nonnull
public Dimension getPreferredSize() {
final PrintPage[][] pages = this.parent.getPages();
final PageFormat thePageFormat = this.parent.getPageFormat();
final double scale = this.parent.getScale();
int pagesAtHorizontal = 0;
int pagesAtVertical = pages.length;
final double paperWidth = thePageFormat.getWidth();
final double paperHeight = thePageFormat.getHeight();
for (final PrintPage[] row : pages) {
pagesAtHorizontal = Math.max(pagesAtHorizontal, row.length);
}
final int width = (int) Math.round(INTERVAL_X + ((paperWidth + INTERVAL_X) * pagesAtHorizontal));
final int height = (int) Math.round(INTERVAL_Y + ((paperHeight + INTERVAL_Y) * pagesAtVertical));
return new Dimension((int) Math.round(width * scale), (int) Math.round(height * scale));
}
Aggregations