Example usage for com.itextpdf.text.pdf Barcode128 setSize

List of usage examples for com.itextpdf.text.pdf Barcode128 setSize

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf Barcode128 setSize.

Prototype

public void setSize(float size) 

Source Link

Document

Sets the size of the text.

Usage

From source file:com.coderbd.pos.pdf.BarcodePdf.java

public void generateBarcodePdf(int amount) throws UnsupportedEncodingException {
    try {// w ww  .  j  av  a 2 s  .c  om
        String filename = directory + "\\" + barcodeData + ".pdf";
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Barcode128 code25 = new Barcode128();
        code25.setGenerateChecksum(true);
        code25.setCode(barcodeData);
        code25.setSize(10f);
        code25.setX(1.50f);

        PdfPTable pdfPTable = new PdfPTable(3);
        float[] widths = { 0.45f, .10f, .45f };
        pdfPTable.setWidths(widths);
        String codeName = getCodeName(shop.getShopName(), shop.getShopId(), amount);
        System.out.println("BarCodeName:" + codeName);

        Image image = code25.createImageWithBarcode(cb, null, null);

        Paragraph paragraph = new Paragraph(codeName);
        paragraph.setSpacingBefore(10.0f);
        PdfPCell title = new PdfPCell(paragraph);
        title.setBorder(Rectangle.NO_BORDER);

        PdfPCell barcodeCell = new PdfPCell(image, true);
        barcodeCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell blank = new PdfPCell();
        blank.setBorder(Rectangle.NO_BORDER);

        Paragraph blankParagraph = new Paragraph("-                                                    -");
        PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph);
        pdfPCellBlank.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < barcodeQuantity; i++) {
            /**
             * This is for barcode pdf title
             */
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);

            /**
             * This is for barcode image
             */
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);

            /**
             * Blank space after barcode image
             */
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
        }
        document.add(pdfPTable);
        document.close();
    } catch (DocumentException | FileNotFoundException dex) {
        System.out.println(dex.getMessage());
    }
}

From source file:com.coderbd.pos.pdf.BarcodePdf.java

public void generateBarcodePdf(boolean fixedRate, Product p) throws UnsupportedEncodingException {
    try {//w w w .j a  v  a2s.  c o m
        String filename = directory + "\\" + barcodeData + ".pdf";
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Barcode128 code25 = new Barcode128();
        code25.setGenerateChecksum(true);
        code25.setCode(barcodeData);
        code25.setSize(10f);
        code25.setX(1.50f);

        PdfPTable pdfPTable = new PdfPTable(3);
        float[] widths = { 0.45f, .10f, .45f };
        pdfPTable.setWidths(widths);
        String codeName = getCodeName(shop.getShopName(), shop.getShopId(), (int) p.getProductBuyRate());
        System.out.println("BarCodeName:" + codeName);

        Image image = code25.createImageWithBarcode(cb, null, null);

        Paragraph paragraph = new Paragraph(codeName);
        paragraph.setSpacingBefore(10.0f);
        PdfPCell title = new PdfPCell(paragraph);
        title.setBorder(Rectangle.NO_BORDER);

        PdfPCell barcodeCell = new PdfPCell(image, true);
        barcodeCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell blank = new PdfPCell();
        blank.setBorder(Rectangle.NO_BORDER);

        Paragraph blankParagraph = new Paragraph("-                                                    -");
        PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph);
        pdfPCellBlank.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < barcodeQuantity; i++) {
            /**
             * This is for barcode pdf title
             */
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);

            /**
             * This is for barcode image
             */
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);

            /**
             * Blank space after barcode image
             */
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
        }
        document.add(pdfPTable);
        document.close();
    } catch (DocumentException | FileNotFoundException dex) {
        System.out.println(dex.getMessage());
    }
}

From source file:com.coderbd.pos.pdf.CodePDF.java

public boolean genCodeVer2Pdf() throws UnsupportedEncodingException {

    if (isFixedRated == true) {
        barcodeQuantity = 12;//w  w  w  . j a va 2 s  .  c o m
    } else {
        barcodeQuantity = 15;
    }

    try {
        String filename = "";

        if (isFixedRated) {
            filename = directory + "\\" + product.getProductBarcode() + "_FIXED_TK" + ".pdf";
        } else {
            filename = directory + "\\" + product.getProductBarcode() + ".pdf";
        }

        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Barcode128 code25 = new Barcode128();
        code25.setGenerateChecksum(true);
        code25.setCode(product.getProductBarcode());
        code25.setSize(10f);
        code25.setX(1.50f);

        PdfPTable pdfPTable = new PdfPTable(7);
        pdfPTable.setWidthPercentage(98);
        float[] widths = { 0.22f, 0.04f, 0.22f, 0.04f, 0.22f, 0.04f, 0.22f };
        pdfPTable.setWidths(widths);
        String codeName = getCodeName(product.getShop().getShopName(), product.getShop().getShopId(),
                (int) product.getProductBuyRate());

        System.out.println("BarCodeName:" + codeName);

        Image image = code25.createImageWithBarcode(cb, null, null);

        Font titleArialFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL);
        Font priceFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD);

        Paragraph paragraph = new Paragraph(codeName, titleArialFont);
        paragraph.setSpacingBefore(10.0f);
        PdfPCell title = new PdfPCell(paragraph);
        title.setBorder(Rectangle.NO_BORDER);

        Paragraph fixedTKParagraph = new Paragraph("FIXED TK: " + product.getProductSellRate(), priceFont);
        PdfPCell fixedRateCell = new PdfPCell(fixedTKParagraph);
        fixedRateCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell barcodeCell = new PdfPCell(image, true);
        barcodeCell.setBorder(Rectangle.NO_BORDER);

        PdfPCell blank = new PdfPCell();
        blank.setBorder(Rectangle.NO_BORDER);

        Paragraph blankParagraph = new Paragraph("-                           -");
        PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph);
        pdfPCellBlank.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < barcodeQuantity; i++) {
            /**
             * This is for barcode pdf title
             */
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(title);

            /**
             * This is for barcode image
             */
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(barcodeCell);
            /**
             *
             */
            if (isFixedRated == true) {
                pdfPTable.addCell(fixedRateCell);
                pdfPTable.addCell(blank);
                pdfPTable.addCell(fixedRateCell);
                pdfPTable.addCell(blank);
                pdfPTable.addCell(fixedRateCell);
                pdfPTable.addCell(blank);
                pdfPTable.addCell(fixedRateCell);
            }
            /**
             * Blank space after barcode image
             */
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
            pdfPTable.addCell(blank);
            pdfPTable.addCell(pdfPCellBlank);
        }
        document.add(pdfPTable);
        document.add(new Paragraph(
                "Shop Name: " + product.getShop().getShopName() + ", Name:" + product.getProductName()
                        + "\n,Qty: " + product.getProductStock() + ", " + new Date().toString(),
                titleArialFont));
        document.close();
        return true;
    } catch (DocumentException | FileNotFoundException dex) {
        System.out.println(dex.getMessage());
        return false;
    }
}