Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/08/2011, 13:36
luzadri_2908
 
Fecha de Ingreso: mayo-2011
Mensajes: 3
Antigüedad: 13 años
Puntos: 0
Pregunta Generar PDF con Itext con imagenes en AWT

Hola a todos.

tengo el siguiente problema: debo generar un pdf para una imagen que esta en AWT, no se si hay forma de convertirla al Image q trae la libreria Itext o alguna forma que me reconozca esa imagen.
La imagen en cuestion es un codigo de barras.

Les agradecia mucho su ayuda.

les dejo el codigo


public static BufferedImage getBarcode(String value, AbstractBarcodeBean barcode) {

barcode.setModuleWidth(1.0);
barcode.setBarHeight(40.0);
barcode.setFontSize(10.0);
barcode.setQuietZone(10.0);
barcode.doQuietZone(true);
barcode.getFontName();

BarcodeDimension dim = barcode.calcDimensions(value);
int width = (int) dim.getWidth(0) + 20;
int height = (int) dim.getHeight(0);

BufferedImage imgtext = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = imgtext.createGraphics();

g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, width, height);

g2d.setColor(Color.BLACK);

try {
barcode.generateBarcode(new Java2DCanvasProvider(g2d, 0), value);


} catch (IllegalArgumentException e) {
g2d.drawRect(0, 0, width - 1, height - 1);
g2d.drawString(value, 2, height - 3);
}

g2d.dispose();
try {

crearPdf(imgtext);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//print

return imgtext;

}





y este es la clase q generaria el pdf


public static void crearPdf(Image g) throws DocumentException, FileNotFoundException{
codigobarras = new Document();
FileOutputStream fileCodigo = new FileOutputStream("Codigo.pdf");
PdfWriter.getInstance(codigobarras,fileCodigo).set InitialLeading(20);

codigobarras.open();
try{
com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(g, null);
codigobarras.add(image); //en esta linea me da un error y me dice que // //ponga un cast a la imagen con element
}
catch(Exception e){}
}