Search in sources :

Example 1 with Report

use of jgnash.report.pdf.Report 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);
        }
    }
}
Also used : Path(java.nio.file.Path) PageFormat(java.awt.print.PageFormat) Report(jgnash.report.pdf.Report) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.jupiter.api.Test)

Example 2 with Report

use of jgnash.report.pdf.Report 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);
        }
    }
}
Also used : Path(java.nio.file.Path) PageFormat(java.awt.print.PageFormat) Report(jgnash.report.pdf.Report) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.jupiter.api.Test)

Aggregations

BufferedImage (java.awt.image.BufferedImage)2 PageFormat (java.awt.print.PageFormat)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Report (jgnash.report.pdf.Report)2 Test (org.junit.jupiter.api.Test)2