Java 类net.sf.jasperreports.engine.export.JRGraphics2DExporter 实例源码

项目:openbravo-pos    文件:JRPrinterAWT300.java   
/**
 *
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
    if (Thread.currentThread().isInterrupted())
    {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if ( pageIndex < 0 || pageIndex >= jasperPrint.getPages().size() )
    {
        return Printable.NO_SUCH_PAGE;
    }

    try
    {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
        exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
        exporter.exportReport();
    }
    catch (JRException e)
    {
        e.printStackTrace();
        throw new PrinterException(e.getMessage());
    }

    return Printable.PAGE_EXISTS;
}
项目:openbravo-pos    文件:JRPrinterAWT300.java   
/**
 *
 */
private Image printPageToImage(int pageIndex, float zoom) throws JRException
{
    Image pageImage = new BufferedImage(
        (int)(jasperPrint.getPageWidth() * zoom) + 1,
        (int)(jasperPrint.getPageHeight() * zoom) + 1,
        BufferedImage.TYPE_INT_RGB
        );

    JRGraphics2DExporter exporter = new JRGraphics2DExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
    exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());
    exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
    exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(zoom));
    exporter.exportReport();

    return pageImage;
}
项目:wifepos    文件:JRPrinterAWT300.java   
/**
 *
 */
private Image printPageToImage(int pageIndex, float zoom) throws JRException
{
    Image pageImage = new BufferedImage(
        (int)(jasperPrint.getPageWidth() * zoom) + 1,
        (int)(jasperPrint.getPageHeight() * zoom) + 1,
        BufferedImage.TYPE_INT_RGB
        );

    JRGraphics2DExporter exporter = new JRGraphics2DExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
    exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());
    exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
    exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(zoom));
    exporter.exportReport();

    return pageImage;
}
项目:micro-Blagajna    文件:JRPrinterAWT300.java   
/**
 *
 */
private Image printPageToImage(int pageIndex, float zoom) throws JRException
{
    Image pageImage = new BufferedImage(
        (int)(jasperPrint.getPageWidth() * zoom) + 1,
        (int)(jasperPrint.getPageHeight() * zoom) + 1,
        BufferedImage.TYPE_INT_RGB
        );

    JRGraphics2DExporter exporter = new JRGraphics2DExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
    exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());
    exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
    exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(zoom));
    exporter.exportReport();

    return pageImage;
}
项目:jasperreports    文件:JRPrinterAWT.java   
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
    if (Thread.interrupted())
    {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if ( pageIndex < 0 || pageIndex >= jasperPrint.getPages().size() )
    {
        return Printable.NO_SUCH_PAGE;
    }

    try
    {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter(jasperReportsContext);
        exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
        SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput();
        output.setGraphics2D((Graphics2D)graphics);
        exporter.setExporterOutput(output);
        SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration();
        configuration.setPageIndex(pageIndex);
        exporter.setConfiguration(configuration);
        exporter.exportReport();
    }
    catch (JRException e)
    {
        if (log.isDebugEnabled())
        {
            log.debug("Print failed.", e);
        }

        throw new PrinterException(e.getMessage()); //NOPMD
    }

    return Printable.PAGE_EXISTS;
}
项目:jasperreports    文件:PrintDrawVisitor.java   
@Override
public void visit(JRGenericPrintElement printElement, Offset offset)
{
    GenericElementGraphics2DHandler handler = 
        (GenericElementGraphics2DHandler)GenericElementHandlerEnviroment.getInstance(jasperReportsContext).getElementHandler(
                printElement.getGenericType(), 
                JRGraphics2DExporter.GRAPHICS2D_EXPORTER_KEY
                );

    if (handler != null)
    {
        handler.exportElement(this.frameDrawer.getExporterContext(), printElement, grx, offset);
    }
    else
    {
        if (log.isDebugEnabled())
        {
            log.debug("No Graphics2D generic element handler for " 
                    + printElement.getGenericType());
        }
    }
}
项目:jasperreports    文件:JRDesignViewerPanel.java   
@Override
protected JRGraphics2DExporter getGraphics2DExporter() throws JRException
{
    return 
        new JRGraphics2DExporter(viewerContext.getJasperReportsContext())
        {
            @Override
            protected void initReport()
            {
                super.initReport();
                drawVisitor.setClip(true);//FIXMENOW thick border of margin elements is clipped
            }
            @Override
            protected RenderersCache getRenderersCache()
            {
                return viewerContext.getRenderersCache();
            }
        };
}
项目:jasperreports    文件:MapElementGraphics2DHandler.java   
@Override
public void exportElement(
        JRGraphics2DExporterContext exporterContext, 
        JRGenericPrintElement element, 
        Graphics2D grx, 
        Offset offset)
{
    try
    {
        JRGraphics2DExporter exporter = (JRGraphics2DExporter)exporterContext.getExporterRef();
        ImageDrawer imageDrawer = exporter.getDrawVisitor().getImageDrawer();

        imageDrawer.draw(
                grx,
                MapElementImageProvider.getImage(exporterContext.getJasperReportsContext(), element), 
                offset.getX(), 
                offset.getY()
                );
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
项目:PDFReporter-Studio    文件:JSSDrawVisitor.java   
/**
 *
 */
public JSSDrawVisitor(ReportConverter reportConverter, Graphics2D grx) {
    this.reportConverter = reportConverter;
    this.convertVisitor = new JSSConvertVisitor(reportConverter);
    final JasperReportsContext jasperReportsContext = reportConverter.getJasperReportsContext();
    this.drawVisitor = new PrintDrawVisitor(jasperReportsContext) {
        @Override
        public void setTextRenderer(JRReport report) {
            AwtTextRenderer textRenderer = new AwtTextRenderer(jasperReportsContext, JRPropertiesUtil.getInstance(
                    jasperReportsContext).getBooleanProperty(report, JRGraphics2DExporter.MINIMIZE_PRINTER_JOB_SIZE, true),
                    JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(report,
                            JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT, false));

            setTextDrawer(new TextDrawer(jasperReportsContext, textRenderer));
            setFrameDrawer(new FrameDrawer(jasperReportsContext, null, textRenderer));

        }

    };
    setTextRenderer(reportConverter.getReport());
    this.grx = grx;
    setGraphics2D(grx);
    this.drawVisitor.setClip(true);
}
项目:unicenta    文件:JRPrinterAWT300.java   
/**
 *
 */
private Image printPageToImage(int pageIndex, float zoom) throws JRException
{
    Image pageImage = new BufferedImage(
        (int)(jasperPrint.getPageWidth() * zoom) + 1,
        (int)(jasperPrint.getPageHeight() * zoom) + 1,
        BufferedImage.TYPE_INT_RGB
        );

    JRGraphics2DExporter exporter = new JRGraphics2DExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
    exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());
    exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
    exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(zoom));
    exporter.exportReport();

    return pageImage;
}
项目:nordpos    文件:JRPrinterAWT.java   
/**
 *
 */
public Image printPageToImage(int pageIndex, float zoom) throws JRException
{
    PrintPageFormat pageFormat = jasperPrint.getPageFormat(pageIndex);

    Image pageImage = new BufferedImage(
        (int)(pageFormat.getPageWidth() * zoom) + 1,
        (int)(pageFormat.getPageHeight() * zoom) + 1,
        BufferedImage.TYPE_INT_RGB
        );

    JRGraphics2DExporter exporter = new JRGraphics2DExporter(jasperReportsContext);
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput();
    output.setGraphics2D((Graphics2D)pageImage.getGraphics());
    exporter.setExporterOutput(output);
    SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration();
    configuration.setPageIndex(pageIndex);
    configuration.setZoomRatio(zoom);
    exporter.setConfiguration(configuration);
    exporter.exportReport();

    return pageImage;
}
项目:OpenbravoPOS    文件:JRPrinterAWT300.java   
/**
 *
 */
private Image printPageToImage(int pageIndex, float zoom) throws JRException
{
    Image pageImage = new BufferedImage(
        (int)(jasperPrint.getPageWidth() * zoom) + 1,
        (int)(jasperPrint.getPageHeight() * zoom) + 1,
        BufferedImage.TYPE_INT_RGB
        );

    JRGraphics2DExporter exporter = new JRGraphics2DExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
    exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());
    exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
    exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(zoom));
    exporter.exportReport();

    return pageImage;
}
项目:jasperreports    文件:JRPrinterAWT.java   
/**
 *
 */
public Image printPageToImage(int pageIndex, float zoom) throws JRException
{
    PrintPageFormat pageFormat = jasperPrint.getPageFormat(pageIndex);

    int rasterWidth = (int) Math.ceil(pageFormat.getPageWidth() * zoom);
    int rasterHeight = (int) Math.ceil(pageFormat.getPageHeight() * zoom);
    Image pageImage = new BufferedImage(
        rasterWidth,
        rasterHeight,
        BufferedImage.TYPE_INT_RGB
        );

    Graphics imageGraphics = pageImage.getGraphics();
    Graphics graphics = imageGraphics.create();
    //filling the image background here because JRGraphics2DExporter.exportPage uses the page size
    //which can be smaller than the image size due to Math.ceil above
    graphics.setColor(Color.white);
    graphics.fillRect(0, 0, rasterWidth, rasterHeight);

    JRGraphics2DExporter exporter = new JRGraphics2DExporter(jasperReportsContext);
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput();
    output.setGraphics2D((Graphics2D) imageGraphics);
    exporter.setExporterOutput(output);
    SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration();
    configuration.setPageIndex(pageIndex);
    configuration.setZoomRatio(zoom);
    configuration.setWhitePageBackground(false);
    exporter.setConfiguration(configuration);
    exporter.exportReport();

    return pageImage;
}
项目:jasperreports    文件:FrameDrawer.java   
/**
 *
 */
private void draw(Collection<JRPrintElement> elements) throws JRException
{
    if (elements != null && elements.size() > 0)
    {
        Shape clipArea = grx.getClip();
        for(Iterator<JRPrintElement> it = elements.iterator(); it.hasNext();)
        {
            JRPrintElement element = it.next();
            boolean isGenericElement = element instanceof JRGenericPrintElement;
            JRGenericPrintElement genericElement =  isGenericElement ? (JRGenericPrintElement)element : null;
            GenericElementGraphics2DHandler handler = isGenericElement 
                    ? (GenericElementGraphics2DHandler)GenericElementHandlerEnviroment.getInstance(getJasperReportsContext()).getElementHandler(genericElement.getGenericType(), JRGraphics2DExporter.GRAPHICS2D_EXPORTER_KEY)
                    : null;

            boolean isGenericElementToExport = isGenericElement && handler != null && handler.toExport(genericElement); 

            if (
                (filter != null && !filter.isToExport(element))
                || !clipArea.intersects(
                    element.getX() + elementOffset.getX() - ELEMENT_RECTANGLE_PADDING, 
                    element.getY() + elementOffset.getY() - ELEMENT_RECTANGLE_PADDING, 
                    element.getWidth() + 2 * ELEMENT_RECTANGLE_PADDING, 
                    element.getHeight() + 2 * ELEMENT_RECTANGLE_PADDING)
                )
            {
                continue;
            }
            else if(isGenericElementToExport)
            {
                handler.exportElement(exporterContext, genericElement, grx, elementOffset);
            }
            else
            {
                element.accept(drawVisitor, elementOffset);
            }
        }
    }
}
项目:jasperreports    文件:JRViewerPanel.java   
protected JRGraphics2DExporter getGraphics2DExporter() throws JRException
{
    return 
        new JRGraphics2DExporter(viewerContext.getJasperReportsContext())
        {
            @Override
            protected RenderersCache getRenderersCache()
            {
                return viewerContext.getRenderersCache();
            }
        };
}
项目:wifepos    文件:JRPrinterAWT300.java   
/**
 *
 */
   @Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
    if (Thread.currentThread().isInterrupted())
    {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if ( pageIndex < 0 || pageIndex >= jasperPrint.getPages().size() )
    {
        return Printable.NO_SUCH_PAGE;
    }

    try
    {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
        exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
        exporter.exportReport();
    }
    catch (JRException e)
    {
        throw new PrinterException(e.getMessage());
    }

    return Printable.PAGE_EXISTS;
}
项目:micro-Blagajna    文件:JRPrinterAWT300.java   
/**
 *
 */
   @Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
    if (Thread.currentThread().isInterrupted())
    {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if ( pageIndex < 0 || pageIndex >= jasperPrint.getPages().size() )
    {
        return Printable.NO_SUCH_PAGE;
    }

    try
    {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
        exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
        exporter.exportReport();
    }
    catch (JRException e)
    {
        throw new PrinterException(e.getMessage());
    }

    return Printable.PAGE_EXISTS;
}
项目:omr    文件:ParticipationHelper.java   
/**
 * Cria arquivos de imagens das provas. Utilizado exclusivamente em depuracao de codigo
 * @param jp
 * @param eventVO 
 */
protected static void logPrintImages(JasperPrint jp, EventVO eventVO) {
    if(!log.isDebugEnabled()){
        return;
    }

    try {

        int pageCount = jp.getPages().size();

        for (int i = 0; i < pageCount; i++) {

            File file = new File("result/evento_"+eventVO.getPK()+"_pg_" + (i + 1) + "."+ JazzOMRImageParser.IMG_EXT);

            file.mkdirs();

            JRGraphics2DExporter graphics2dExporter = new JRGraphics2DExporter();
            BufferedImage bi = new BufferedImage(600, 900, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics graphics = bi.createGraphics();
            graphics2dExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.PAGE_INDEX, i);
            graphics2dExporter.exportReport();

            ImageIO.write(bi, JazzOMRImageParser.IMG_EXT, file);
        }

    } catch (JRException e1) {
        throw new RuntimeException("erro", e1);
    } catch (IOException e) {
        throw new RuntimeException("erro", e);
    }
}
项目:omr    文件:OMRModelTest.java   
/**
 * @param jp
 */
protected void printImages(JasperPrint jp) {
    try {

        int pageCount = jp.getPages().size();

        for (int i = 0; i < pageCount; i++) {

            File file = new File("result/pagina_" + (i + 1) + "."+ JazzOMRImageParser.IMG_EXT);

            JRGraphics2DExporter graphics2dExporter = new JRGraphics2DExporter();
            BufferedImage bi = new BufferedImage(600, 800, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics graphics = bi.createGraphics();
            graphics2dExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.PAGE_INDEX, i);
            graphics2dExporter.exportReport();

            ImageIO.write(bi, JazzOMRImageParser.IMG_EXT, file);
        }

    } catch (JRException e1) {
        throw new RuntimeException("erro", e1);
    } catch (IOException e) {
        throw new RuntimeException("erro", e);
    }
}
项目:omr    文件:ParticipationHelper.java   
/**
 * Cria arquivos de imagens das provas. Utilizado exclusivamente em depuracao de codigo
 * @param jp
 * @param eventVO 
 */
protected static void logPrintImages(JasperPrint jp, EventVO eventVO) {
    if(!log.isDebugEnabled()){
        return;
    }

    try {

        int pageCount = jp.getPages().size();

        for (int i = 0; i < pageCount; i++) {

            File file = new File("result/evento_"+eventVO.getPK()+"_pg_" + (i + 1) + "."+ JazzOMRImageParser.IMG_EXT);

            file.mkdirs();

            JRGraphics2DExporter graphics2dExporter = new JRGraphics2DExporter();
            BufferedImage bi = new BufferedImage(600, 900, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics graphics = bi.createGraphics();
            graphics2dExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.PAGE_INDEX, i);
            graphics2dExporter.exportReport();

            ImageIO.write(bi, JazzOMRImageParser.IMG_EXT, file);
        }

    } catch (JRException e1) {
        throw new RuntimeException("erro", e1);
    } catch (IOException e) {
        throw new RuntimeException("erro", e);
    }
}
项目:omr    文件:OMRModelTest.java   
/**
 * @param jp
 */
protected void printImages(JasperPrint jp) {
    try {

        int pageCount = jp.getPages().size();

        for (int i = 0; i < pageCount; i++) {

            File file = new File("result/pagina_" + (i + 1) + "."+ JazzOMRImageParser.IMG_EXT);

            JRGraphics2DExporter graphics2dExporter = new JRGraphics2DExporter();
            BufferedImage bi = new BufferedImage(600, 800, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics graphics = bi.createGraphics();
            graphics2dExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.PAGE_INDEX, i);
            graphics2dExporter.exportReport();

            ImageIO.write(bi, JazzOMRImageParser.IMG_EXT, file);
        }

    } catch (JRException e1) {
        throw new RuntimeException("erro", e1);
    } catch (IOException e) {
        throw new RuntimeException("erro", e);
    }
}
项目:omr    文件:ParticipationHelper.java   
/**
 * Cria arquivos de imagens das provas. Utilizado exclusivamente em depuracao de codigo
 * @param jp
 * @param eventVO 
 */
protected static void logPrintImages(JasperPrint jp, EventVO eventVO) {
    if(!log.isDebugEnabled()){
        return;
    }

    try {

        int pageCount = jp.getPages().size();

        for (int i = 0; i < pageCount; i++) {

            File file = new File("result/evento_"+eventVO.getPK()+"_pg_" + (i + 1) + "."+ JazzOMRImageParser.IMG_EXT);

            file.mkdirs();

            JRGraphics2DExporter graphics2dExporter = new JRGraphics2DExporter();
            BufferedImage bi = new BufferedImage(600, 900, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics graphics = bi.createGraphics();
            graphics2dExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.PAGE_INDEX, i);
            graphics2dExporter.exportReport();

            ImageIO.write(bi, JazzOMRImageParser.IMG_EXT, file);
        }

    } catch (JRException e1) {
        throw new RuntimeException("erro", e1);
    } catch (IOException e) {
        throw new RuntimeException("erro", e);
    }
}
项目:omr    文件:OMRModelTest.java   
/**
 * @param jp
 */
protected void printImages(JasperPrint jp) {
    try {

        int pageCount = jp.getPages().size();

        for (int i = 0; i < pageCount; i++) {

            File file = new File("result/pagina_" + (i + 1) + "."+ JazzOMRImageParser.IMG_EXT);

            JRGraphics2DExporter graphics2dExporter = new JRGraphics2DExporter();
            BufferedImage bi = new BufferedImage(600, 800, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics graphics = bi.createGraphics();
            graphics2dExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.PAGE_INDEX, i);
            graphics2dExporter.exportReport();

            ImageIO.write(bi, JazzOMRImageParser.IMG_EXT, file);
        }

    } catch (JRException e1) {
        throw new RuntimeException("erro", e1);
    } catch (IOException e) {
        throw new RuntimeException("erro", e);
    }
}
项目:omr    文件:ParticipationHelper.java   
/**
 * Cria arquivos de imagens das provas. Utilizado exclusivamente em depuracao de codigo
 * @param jp
 * @param eventVO 
 */
protected static void logPrintImages(JasperPrint jp, EventVO eventVO) {
    if(!log.isDebugEnabled()){
        return;
    }

    try {

        int pageCount = jp.getPages().size();

        for (int i = 0; i < pageCount; i++) {

            File file = new File("result/evento_"+eventVO.getPK()+"_pg_" + (i + 1) + "."+ JazzOMRImageParser.IMG_EXT);

            file.mkdirs();

            JRGraphics2DExporter graphics2dExporter = new JRGraphics2DExporter();
            BufferedImage bi = new BufferedImage(600, 900, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics graphics = bi.createGraphics();
            graphics2dExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.PAGE_INDEX, i);
            graphics2dExporter.exportReport();

            ImageIO.write(bi, JazzOMRImageParser.IMG_EXT, file);
        }

    } catch (JRException e1) {
        throw new RuntimeException("erro", e1);
    } catch (IOException e) {
        throw new RuntimeException("erro", e);
    }
}
项目:omr    文件:OMRModelTest.java   
/**
 * @param jp
 */
protected void printImages(JasperPrint jp) {
    try {

        int pageCount = jp.getPages().size();

        for (int i = 0; i < pageCount; i++) {

            File file = new File("result/pagina_" + (i + 1) + "."+ JazzOMRImageParser.IMG_EXT);

            JRGraphics2DExporter graphics2dExporter = new JRGraphics2DExporter();
            BufferedImage bi = new BufferedImage(600, 800, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics graphics = bi.createGraphics();
            graphics2dExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
            graphics2dExporter.setParameter(JRGraphics2DExporterParameter.PAGE_INDEX, i);
            graphics2dExporter.exportReport();

            ImageIO.write(bi, JazzOMRImageParser.IMG_EXT, file);
        }

    } catch (JRException e1) {
        throw new RuntimeException("erro", e1);
    } catch (IOException e) {
        throw new RuntimeException("erro", e);
    }
}
项目:PDFReporter-Studio    文件:ViewerCanvas.java   
private Image renderPage() throws Throwable {
    JasperPrint jr = rViewer.getReport();
    BufferedImage img = new BufferedImage((int) (jr.getPageWidth() * zoom) + 1, (int) (jr.getPageHeight() * zoom) + 1, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2d = (Graphics2D) img.getGraphics();
    try {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter(jContext);
        exporter.setExporterInput(new SimpleExporterInput(jr));

        SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput();
        output.setGraphics2D(g2d);
        exporter.setExporterOutput(output);

        SimpleGraphics2DReportConfiguration grxConfiguration = new SimpleGraphics2DReportConfiguration();
        grxConfiguration.setPageIndex(rViewer.getPageIndex());
        grxConfiguration.setZoomRatio(zoom);
        exporter.setConfiguration(grxConfiguration);

        exporter.exportReport();

        g2d.setColor(Color.black);
        g2d.setStroke(new BasicStroke(1));
        g2d.drawRect(0, 0, (int) (img.getWidth() / zoom), (int) (img.getHeight() / zoom));
    } finally {
        g2d.dispose();
    }
    return UIUtils.awt2Swt(img);
}
项目:unicenta    文件:JRPrinterAWT300.java   
/**
 *
 */
   @Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
    if (Thread.currentThread().isInterrupted())
    {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if ( pageIndex < 0 || pageIndex >= jasperPrint.getPages().size() )
    {
        return Printable.NO_SUCH_PAGE;
    }

    try
    {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
        exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
        exporter.exportReport();
    }
    catch (JRException e)
    {
        throw new PrinterException(e.getMessage());
    }

    return Printable.PAGE_EXISTS;
}
项目:nordpos    文件:JRPrinterAWT.java   
/**
 *
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
    if (Thread.interrupted())
    {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if ( pageIndex < 0 || pageIndex >= jasperPrint.getPages().size() )
    {
        return Printable.NO_SUCH_PAGE;
    }

    try
    {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter(jasperReportsContext);
        exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
        SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput();
        output.setGraphics2D((Graphics2D)graphics);
        exporter.setExporterOutput(output);
        SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration();
        configuration.setPageIndex(pageIndex);
        exporter.setConfiguration(configuration);
        exporter.exportReport();
    }
    catch (JRException e)
    {
        if (log.isDebugEnabled())
        {
            log.debug("Print failed.", e);
        }

        throw new PrinterException(e.getMessage()); //NOPMD
    }

    return Printable.PAGE_EXISTS;
}
项目:OpenbravoPOS    文件:JRPrinterAWT300.java   
/**
 *
 */
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
    if (Thread.currentThread().isInterrupted())
    {
        throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if ( pageIndex < 0 || pageIndex >= jasperPrint.getPages().size() )
    {
        return Printable.NO_SUCH_PAGE;
    }

    try
    {
        JRGraphics2DExporter exporter = new JRGraphics2DExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
        exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
        exporter.exportReport();
    }
    catch (JRException e)
    {
        e.printStackTrace();
        throw new PrinterException(e.getMessage());
    }

    return Printable.PAGE_EXISTS;
}
项目:jasperreports-wms-component    文件:WmsMapElementGraphics2DHandler.java   
@Override
public void exportElement(JRGraphics2DExporterContext context,
    JRGenericPrintElement element, Graphics2D grx, Offset offset) {
  try {
    JRGraphics2DExporter exporter = (JRGraphics2DExporter) context
        .getExporter();
    ImageDrawer imageDrawer = exporter.getFrameDrawer().getDrawVisitor()
        .getImageDrawer();
    JRPrintImage image = getImage(context.getJasperReportsContext(), element);
    imageDrawer.draw(grx, image, offset.getX(), offset.getY());
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
项目:jasperreports-wms-component    文件:WmsMapElementGraphics2DHandlerTest.java   
@Ignore
@Test
public void testExportElement() throws JRException {
  JRGraphics2DExporter exporter = new JRGraphics2DExporter();
  JRGraphics2DExporterContext context = mock(JRGraphics2DExporterContext.class);
  when(context.getExporter()).thenReturn(exporter);
  JRGenericPrintElement element = mock(JRGenericPrintElement.class);
  java.awt.Container container = new Container();
  Graphics2D graphics = (Graphics2D) container.getGraphics();
  Offset offset = new Offset(0, 0);
  handler.exportElement(context, element, graphics, offset);
}
项目:openbravo-pos    文件:JRViewer300.java   
/**
 * 
 */
protected JRGraphics2DExporter getGraphics2DExporter() throws JRException
{
    return new JRGraphics2DExporter();
}
项目:jasperreports    文件:HtmlElementHandlerBundle.java   
@Override
public GenericElementHandler getHandler(String elementName,
        String exporterKey)
{
    if (NAME.equals(elementName)
            && JRPdfExporter.PDF_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementPdfHandler();
    }
    else if (NAME.equals(elementName)
            && HtmlExporter.HTML_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementHtmlHandler();
    }
    else if (NAME.equals(elementName)
            && JRXlsExporter.XLS_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementXlsHandler();
    }
    else if (NAME.equals(elementName)
            && JRGraphics2DExporter.GRAPHICS2D_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementGraphics2DHandler();
    }       
    else if (NAME.equals(elementName)
            && JRDocxExporter.DOCX_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementDocxHandler();
    }       
    else if (NAME.equals(elementName)
            && JRPptxExporter.PPTX_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementPptxHandler();
    }
    else if (NAME.equals(elementName)
            && JRXlsxExporter.XLSX_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementXlsxHandler();
    }
    else if (NAME.equals(elementName)
            && JRRtfExporter.RTF_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementRtfHandler();
    }
    else if (NAME.equals(elementName)
            && JROdtExporter.ODT_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementOdtHandler();
    }
    else if (NAME.equals(elementName)
            && JROdsExporter.ODS_EXPORTER_KEY.equals(exporterKey))
    {
        return new HtmlElementOdsHandler();
    }       
    return null;
}
项目:jasperreports    文件:IconLabelElementGraphics2DHandler.java   
@Override
public void exportElement(
        JRGraphics2DExporterContext exporterContext, 
        JRGenericPrintElement element, 
        Graphics2D grx, 
        Offset offset)
{
    try
    {
        JRPrintText labelPrintText = (JRPrintText)element.getParameterValue(IconLabelElement.PARAMETER_LABEL_TEXT_ELEMENT);
        if (labelPrintText == null) //FIXMEINPUT deal with xml serialization
        {
            return;
        }

        JRBasePrintFrame frame = new JRBasePrintFrame(element.getDefaultStyleProvider());
        frame.setX(element.getX());
        frame.setY(element.getY());
        frame.setWidth(element.getWidth());
        frame.setHeight(element.getHeight());
        frame.setStyle(element.getStyle());
        frame.setBackcolor(element.getBackcolor());
        frame.setForecolor(element.getForecolor());
        frame.setMode(element.getModeValue());
        JRLineBox lineBox = (JRLineBox)element.getParameterValue(IconLabelElement.PARAMETER_LINE_BOX);
        if (lineBox != null)
        {
            frame.copyBox(lineBox);
        }

        frame.addElement(labelPrintText);

        JRPrintText iconPrintText = (JRPrintText)element.getParameterValue(IconLabelElement.PARAMETER_ICON_TEXT_ELEMENT);
        if (iconPrintText != null) //FIXMEINPUT deal with xml serialization
        {
            frame.addElement(iconPrintText);
        }

        JRGraphics2DExporter exporter = (JRGraphics2DExporter)exporterContext.getExporterRef();

        FrameDrawer frameDrawer = exporter.getDrawVisitor().getFrameDrawer();
        frameDrawer.draw(
            grx, 
            frame, 
            offset.getX(), 
            offset.getY()
            );
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
项目:omr    文件:JasperTeste3.java   
public static void createImage() throws FileNotFoundException, JRException, IOException {
    // TODO Auto-generated method stub

    InputStream jrxmlStream = new FileInputStream("/home/darcio/workspace/modules/JazzAV/bsn/src/main/resources/modeloAdes1.jrxml");

    FileOutputStream out = new FileOutputStream("/home/darcio/workspace/modules/JazzAV/bsn/src/main/resources/modeloAdes1.png");


    JasperReport compiled = JasperCompileManager.compileReport(jrxmlStream);


    Map rootMap = new HashMap();
    JasperPrint jasperPrint = JasperFillManager.fillReport(compiled, rootMap, new JREmptyDataSource(1));

    int pageIndex = 0;

    BufferedImage pageImage = new BufferedImage(jasperPrint.getPageWidth() + 1, jasperPrint.getPageHeight() + 1, BufferedImage.TYPE_INT_RGB);

    JRGraphics2DExporter exporter = new JRGraphics2DExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());


    exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, 0.6f);


    exporter.exportReport();
    ImageIO.write(pageImage, "png", out);
}
项目:nordpos    文件:JRViewer.java   
/**
 * 
 */
protected JRGraphics2DExporter getGraphics2DExporter() throws JRException
{
    return new JRGraphics2DExporter(jasperReportsContext);
}
项目:OpenbravoPOS    文件:JRViewer300.java   
/**
 * 
 */
protected JRGraphics2DExporter getGraphics2DExporter() throws JRException
{
    return new JRGraphics2DExporter();
}
项目:jasperreports-wms-component    文件:ExtensionsRegistryFactory.java   
@Override
public GenericElementHandler getHandler(String elementName,
    String exporterKey) {
  if (WmsMapPrintElement.WMS_MAP_ELEMENT_NAME.equals(elementName)) {
    if (JRGraphics2DExporter.GRAPHICS2D_EXPORTER_KEY
        .equals(exporterKey)) {
      return WmsMapElementGraphics2DHandler.getInstance();
    }
    if (JRHtmlExporter.HTML_EXPORTER_KEY.equals(exporterKey)
        || JRXhtmlExporter.XHTML_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementHtmlHandler.getInstance();
    }
    else if (JRPdfExporter.PDF_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementPdfHandler.getInstance();
    }
    else if (JRXlsExporter.XLS_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementXlsHandler.getInstance();
    }
    else if (JExcelApiExporter.JXL_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementJExcelApiHandler.getInstance();
    }
    // else
    // if(JExcelApiMetadataExporter.JXL_METADATA_EXPORTER_KEY.equals(exporterKey))
    // {
    // return MapElementJExcelApiMetadataHandler.getInstance();
    // }
    else if (JRXlsxExporter.XLSX_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementXlsxHandler.getInstance();
    }
    else if (JRDocxExporter.DOCX_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementDocxHandler.getInstance();
    }
    else if (JRPptxExporter.PPTX_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementPptxHandler.getInstance();
    }
    else if (JRRtfExporter.RTF_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementRtfHandler.getInstance();
    }
    else if (JROdtExporter.ODT_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementOdtHandler.getInstance();
    }
    else if (JROdsExporter.ODS_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementOdsHandler.getInstance();
    }
  }
  return null;
}
项目:jasperreports-wms-component    文件:ComponentsExtensionsRegistryFactory.java   
@Override
public GenericElementHandler getHandler(String elementName,
    String exporterKey) {
  if (WmsMapPrintElement.WMS_MAP_ELEMENT_NAME.equals(elementName)) {
    if (JRGraphics2DExporter.GRAPHICS2D_EXPORTER_KEY
        .equals(exporterKey)) {
      return WmsMapElementGraphics2DHandler.getInstance();
    }
    if (JRHtmlExporter.HTML_EXPORTER_KEY.equals(exporterKey)
        || JRXhtmlExporter.XHTML_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementHtmlHandler.getInstance();
    }
    else if (JRPdfExporter.PDF_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementPdfHandler.getInstance();
    }
    else if (JRXlsExporter.XLS_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementXlsHandler.getInstance();
    }
    else if (JExcelApiExporter.JXL_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementJExcelApiHandler.getInstance();
    }
    // else
    // if(JExcelApiMetadataExporter.JXL_METADATA_EXPORTER_KEY.equals(exporterKey))
    // {
    // return MapElementJExcelApiMetadataHandler.getInstance();
    // }
    else if (JRXlsxExporter.XLSX_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementXlsxHandler.getInstance();
    }
    else if (JRDocxExporter.DOCX_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementDocxHandler.getInstance();
    }
    else if (JRPptxExporter.PPTX_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementPptxHandler.getInstance();
    }
    else if (JRRtfExporter.RTF_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementRtfHandler.getInstance();
    }
    else if (JROdtExporter.ODT_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementOdtHandler.getInstance();
    }
    else if (JROdsExporter.ODS_EXPORTER_KEY.equals(exporterKey)) {
      return WmsMapElementOdsHandler.getInstance();
    }
  }
  return null;
}
项目:omr    文件:JasperTeste.java   
public static void createImage() throws FileNotFoundException, JRException, IOException {
    // TODO Auto-generated method stub

    InputStream jrxmlStream = new FileInputStream("/home/darcio/workspace/modules/JazzAV/bsn/src/main/resources/modeloAdes1.jrxml");

    FileOutputStream out = new FileOutputStream("/home/darcio/workspace/modules/JazzAV/bsn/src/main/resources/modeloAdes1.png");


    JasperReport compiled = JasperCompileManager.compileReport(jrxmlStream);


    Map rootMap = new HashMap();
    JasperPrint jasperPrint = JasperFillManager.fillReport(compiled, rootMap, new JREmptyDataSource(1));

    int pageIndex = 0;

    BufferedImage pageImage = new BufferedImage(jasperPrint.getPageWidth() + 1, jasperPrint.getPageHeight() + 1, BufferedImage.TYPE_INT_RGB);

    JRGraphics2DExporter exporter = new JRGraphics2DExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());


    exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, 0.6f);


    exporter.exportReport();
    ImageIO.write(pageImage, "png", out);
}