canimeicaca
canimeicaca
2016-08-10 13:35

poi将条形码写入word文档!求助

/**条形码工具类
*/
public class OneBarcodeUtil {

public void tool(String str)  

{

try

{

JBarcode localJBarcode = new JBarcode(EAN13Encoder.getInstance(), WidthCodedPainter.getInstance(), EAN13TextPainter.getInstance());

//生成. 欧洲商品条码(=European Article Number)

//这里我们用作图书条码

// String str = "788515004012";

BufferedImage localBufferedImage = localJBarcode.createBarcode(str);

saveToGIF(localBufferedImage, "EAN13.gif");

localJBarcode.setEncoder(Code39Encoder.getInstance());

localJBarcode.setPainter(WideRatioCodedPainter.getInstance());

localJBarcode.setTextPainter(BaseLineTextPainter.getInstance());

localJBarcode.setShowCheckDigit(false);

//xx

// str = "JBARCODE-39";

// localBufferedImage = localJBarcode.createBarcode(str);

// saveToPNG(localBufferedImage, "Code39.png");

}  
catch (Exception localException)  
{  
  localException.printStackTrace();  
}  

}

static void saveToJPEG(BufferedImage paramBufferedImage, String paramString)

{

saveToFile(paramBufferedImage, paramString, "jpeg");

}

static void saveToPNG(BufferedImage paramBufferedImage, String paramString)

{

saveToFile(paramBufferedImage, paramString, "png");

}

static void saveToGIF(BufferedImage paramBufferedImage, String paramString)

{

saveToFile(paramBufferedImage, paramString, "gif");

}

static void saveToFile(BufferedImage paramBufferedImage, String paramString1, String paramString2)

{

try

{

FileOutputStream localFileOutputStream = new FileOutputStream("d:/images/" + paramString1);

ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96, 96);

localFileOutputStream.close();

}

catch (Exception localException)

{

localException.printStackTrace();

}

}

}

/**
*word设置文档格式
*/
XWPFDocument xdoc = new XWPFDocument();

XWPFParagraph p = xdoc.createParagraph();
// 固定值25磅
setParagraphSpacingInfo(p, true, "0", "150", null, null, true, "500",
    STLineSpacingRule.EXACT);
// 左对齐
setParagraphAlignInfo(p, ParagraphAlignment.LEFT,
    TextAlignment.CENTER);
XWPFRun pRun = getOrAddParagraphFirstRun(p, false, false);

// setParagraphRunFontInfo(p, pRun, "**********调度单", "黑体",
// "Times New Roman", "24", false, false, false, false, null, null,
// 0, 0, 90);
setParagraphRunFontInfo(p, pRun, "oneBarcodeUtil.tool(waybill.getWaybillNo())", "黑体",
"Times New Roman", "24", false, false, false, false, null, null,
0, 0, 90);
p = xdoc.createParagraph();
// 单倍行距
setParagraphSpacingInfo(p, true, "0", "0", "0", "0", true, "240",
STLineSpacingRule.AUTO);
setParagraphAlignInfo(p, ParagraphAlignment.LEFT, TextAlignment.CENTER);
pRun = getOrAddParagraphFirstRun(p, false, false);
setParagraphRunFontInfo(p, pRun, "调度类型:"+departure.getDepartureType()+"制单人:"+departure.getCreator()+"打印时间:"+departure.getCreateTime(), "宋体",
"Times New Roman", "15", false, false, false, false, null, null,
10, 6, 0);
如何将条形码输入:以下是要实现的效果图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答