我正在尝试将条形码打印成pdf,但是当我输入writer..getDirectContent();它显示错误。
我导入了以下内容
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.pdf.BarcodeEAN;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.Rectangle;
结果集中的我的代码我要在pdf中打印条形码
try{
String sel_peince=jTextField33.getText();
String des=jTextField29.getText();
if((sel_peince.compareTo("")!=0) && (des.compareTo("")!=0)){
String sql="Select * from printing_press_inventory where unit_selling_price='"+sel_peince+"' and description ='"+des+"'";
pst=con.prepareStatement(sql);
rs = pst.executeQuery(sql);
rs.next();
String oitm=""+rs.getInt("item_id");
String Oqt=""+rs.getInt("quantity");
String description=rs.getString("description");
Document doc=new Document();
PdfWriter.getInstance(doc, new FileOutputStream("Barcode.pdf"));
doc.open();
doc.add(new Paragraph(new Chunk("Barcode for "+description+"")));
PdfContentByte cb = writer.getDirectContent();
BarcodeEAN codeEAN=new BarcodeEAN();
codeEAN.setCode(oitm);
Paragraph p=new Paragraph();
codeEAN.setCodeType(BarcodeEAN.UPCA);
doc.add(codeEAN.createImageWithBarcode(null, BaseColor.BLACK, BaseColor.BLACK));
doc.add(p);
doc.close();
}
else{
JOptionPane.showMessageDialog(null, "eerrrrr");
}
}
catch(Exception e){
System.out.println(e);
}
谢谢!:D