java - 如何在 Java/iReport 中旋转条形码?

标签 java jasper-reports barcode

据我所知,这样的条形码不能旋转(iReport 没有该属性,Java 类中的 Barbecue Barcode 也没有)。我看过一些示例,但它们不完整,我不明白如何使用它们,例如:

public class BarbecueRenderer extends JRAbstractSvgRenderer
{

private boolean rotate;
private Barcode barcode = null;

public BarbecueRenderer(Barcode barcode) 
{
    this(barcode, false);
}

public BarbecueRenderer(Barcode barcode, boolean rotate) 
{
    this.barcode = barcode;
    this.rotate = rotate;
}

// What should I use as the grx and rectangle objects?
public void render(Graphics2D grx, Rectangle2D rectangle) 
{
    if (barcode != null) 
    {
        Graphics2D graphics = (Graphics2D) grx.create();
        graphics.translate(rectangle.getX(), rectangle.getY());
        if (rotate)
        {
            graphics.translate(barcode.getBounds().getHeight(), 0);
            graphics.rotate(Math.PI / 2);
        }
        barcode.draw(graphics, 0, 0);
    }
}
}

我需要的是这样的:

 Barcode barcode = BarcodeFactory.createCode39("128", false);
 // rotate the barcode
 File f = new File ("c:\\barcode.jpg");
 BarcodeImageHandler.saveJPEG(barcode, f);

最佳答案

在 jasper reports 4.0.2 中,您可以简单地编辑 jrxml 并将旋转属性添加到 jr:barbecue 元素。

<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="Code128" drawText="true" checksumRequired="true" rotation="Right">

可能的值是任何有效的 net.sf.jasperreports.engine.type.RotationEnum

关于java - 如何在 Java/iReport 中旋转条形码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4014595/

相关文章:

java - 动态 Jasper 因大量数据而崩溃

php - 如何使用 zend 条形码库在 CodeIgniter-3.0rc2 中生成条形码

java - fragment 中的 onActivityResult 不更新 edittext

java - 可执行 jar 文件如何与另一个程序一起工作

java - Java 中基于 AES-256 密码的加密/解密

java - 将 XML 文件中的子节点拆分为自己的 XML 文件

java - 透明的 JButton 仍在绘制其背景

jasper-reports - 字体扩展不适用于 OTF 字体 - JasperReports 4.7.1

java - 如何使用外部字体 TTF 文件定义外语字体,然后在 JRXML 文件中使用它?

我无法理解的 Python 行为