Example usage for com.lowagie.text.pdf BarcodeEAN BarcodeEAN

List of usage examples for com.lowagie.text.pdf BarcodeEAN BarcodeEAN

Introduction

In this page you can find the example usage for com.lowagie.text.pdf BarcodeEAN BarcodeEAN.

Prototype

public BarcodeEAN() 

Source Link

Document

Creates new BarcodeEAN

Usage

From source file:beans.ManagedBeanProducto.java

License:Open Source License

public String CreatePdf() throws IOException, DocumentException {
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    //System.out.println(" test: "+extContext);
    //System.out.println(" esta es la ruta" + extContext.getRealPath("//pdfs//"));
    // step 1/*from  w ww. j a  v a2s  .c  om*/
    String ruta_pdfs = extContext.getRealPath("//pdfs//");
    Document document = new Document(PageSize.A4);
    document.setMargins(5, 5, 25, 25);
    document.setMarginMirroring(true);

    // step 2
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(ruta_pdfs + "//CB" + Producto.getIdProducto() + ".pdf"));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();

    Paragraph Titulo = new Paragraph(
            "PRODUCTO : " + Producto.getNombreProducto().substring(14).toUpperCase() + "\n\n");
    Titulo.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(Titulo);

    // EAN 13
    // document.add(new Paragraph("Barcode EAN.UCC-13"));
    BarcodeEAN codeEAN = new BarcodeEAN();

    codeEAN.setCode(CodigoBarrasFinal());
    String nombre_producto = "";
    if (Producto.getNombreProducto().length() >= 41) {
        nombre_producto = Producto.getNombreProducto().substring(14, 41);
    } else {
        nombre_producto = Producto.getNombreProducto().substring(14);
    }
    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // document.add(codeEAN.createImageWithBarcode(cb,Color.BLUE , Color.BLUE));
    // codeEAN.setGuardBars(false);

    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // codeEAN.setGuardBars(false);
    Image imagen = codeEAN.createImageWithBarcode(cb, null, null);
    imagen.scaleAbsolute(87, 45);
    //document.add(imagen);

    PdfPTable table = new PdfPTable(5);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    // table.setTotalWidth(1800);
    PdfPCell cell;
    Phrase nombre = new Phrase(nombre_producto.toUpperCase(),
            new Font(Font.COURIER, 5, Font.BOLD, Color.BLACK));

    cell = new PdfPCell();
    cell.addElement(nombre);
    //cell.addElement(new Chunk("\n"));
    cell.addElement(imagen);
    //cell.addElement(new Chunk("\n"));

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    // EAN 8 "6987";
    // String inicio ="345";
    //  int intermedio =1000+Producto.getIdProducto();
    //  String fin ="0";
    // document.add(new Paragraph(Producto.getNombreProducto(),new Font(Font.COURIER, 4, Font.NORMAL)));
    // codeEAN.setCodeType(Barcode.EAN8);
    // codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
    // codeEAN.setCode(inicio.concat(intermedio+fin));
    // document.add(codeEAN.createImageWithBarcode(cb, null, null));
    document.close();

    return "codigo_barras_productos";
}

From source file:org.orbeon.oxf.processor.pdf.PDFTemplateProcessor.java

License:Open Source License

private Barcode createBarCode(String type) {
    if (type.equals("CODE39")) {
        return new Barcode39();
    } else if (type.equals("CODE128")) {
        return new Barcode128();
    } else if (type.equals("EAN")) {
        return new BarcodeEAN();
    }//  w  w w .  j a  v a2  s.c o m
    return new Barcode39();
}

From source file:view.ViewCodigobarras.java

public void gerarCodigoBarras(ArrayList<String> pListaCodigos) {

    System.out.println("Barcode Linha de Cdigo ");

    // criando um objeto da classe Document
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {/*from   w w w.  ja  v a 2s . c  o  m*/

        //Aqui comeamos a utilizar as classes do iText: o documento
        //criado acima ser
        //direcionado para um arquivo PDF.
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("C://Codigo_Barra_Java_Linha_Codigo.pdf"));

        //abrindo o documento.
        document.open();

        //adicionando um novo paragrafo.
        for (int i = 0; i < pListaCodigos.size(); i++) {
            document.add(new Paragraph("CDIGOS DE BARRA"));

            document.add(new Paragraph("    "));

            document.add(new Paragraph("    "));

            //Comecando a configurar o cod de barras
            PdfContentByte cb = writer.getDirectContent();

            BarcodeEAN codeEAN = new BarcodeEAN();

            //O iText suporta os principais tipos de cdigo de barra, como Barcode39,
            //  Barcode128 (128, 128_UCC, 128_RAW),  BarcodeEAN (EAN13, EAN8, UPCA, UPCE), EANSUP, etc
            if (jcbTipoCodigo.getSelectedItem().toString() == "EAN13") {
                codeEAN.setCodeType(codeEAN.EAN13);
            } else if ("EAN8".equals(jcbTipoCodigo.getSelectedItem().toString())) {
                codeEAN.setCodeType(codeEAN.EAN8);
            } else if ("UPCA".equals(jcbTipoCodigo.getSelectedItem().toString())) {
                codeEAN.setCodeType(codeEAN.UPCA);
            } else if ("UPCE".equals(jcbTipoCodigo.getSelectedItem().toString())) {
                codeEAN.setCodeType(codeEAN.UPCE);
            }

            codeEAN.setCode("1234567890123");

            Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);

            document.add(new Phrase(new Chunk(imageEAN, 0, 0)));
        }
        //abrir o arquivo
        File file = new File("C://Codigo_Barra_Java_Linha_Codigo.pdf");
        try {
            Desktop.getDesktop().open(file);
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(null, e);
        }
        file.deleteOnExit();

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

    }
    document.close();

}