Example usage for com.itextpdf.text Chunk getWidthPoint

List of usage examples for com.itextpdf.text Chunk getWidthPoint

Introduction

In this page you can find the example usage for com.itextpdf.text Chunk getWidthPoint.

Prototype

public float getWidthPoint() 

Source Link

Document

Gets the width of the Chunk in points.

Usage

From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java

License:Apache License

/**
 * //  w  ww  . jav a2 s  . c om
 *  Paragraph ?.(Navigation  ?  title ) 
 *
 * @param title 
 * @param pageNumber 
 * @param depth 
 * @param x1 document left 
 * @param x2 document right 
 * @return Paragraph
 */
public Paragraph getTocParagraph(String title, int pageNumber, int depth, float x1, float x2) {

    Font tocFont = new Font(bfKorean, 10);
    if (depth == 0)
        tocFont.setStyle(Font.BOLD);

    Paragraph p = new Paragraph();
    p.setSpacingAfter(5);

    Chunk tit = new Chunk(title + " ", tocFont);
    tit.setAction(PdfAction.gotoLocalPage(title, false));

    Chunk point = new Chunk(".", tocFont);

    Chunk number = new Chunk(" " + pageNumber, tocFont);
    number.setAction(PdfAction.gotoLocalPage(title, false));

    p.add(tit);

    float width = x2 - x1 - tit.getWidthPoint() - number.getWidthPoint() - (depth * 12);

    if ((x2 - x1) < tit.getWidthPoint())
        width = x2 - x1 - (tit.getWidthPoint() - (x2 - x1)) - number.getWidthPoint() - (depth * 12) - 65;

    float i = point.getWidthPoint();
    while (i < width) {
        p.add(point);
        i += point.getWidthPoint();
    }

    p.add(number);

    return p;
}

From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public float addConversationPart(ColumnText ct, int column, String dateString, String senderString,
        String contentString, Bitmap contentBitmap, Boolean isVideo, Boolean isMe)
        throws DocumentException, MalformedURLException, IOException {
    float messageWidth = 196.0f;
    Chunk dateChunk = new Chunk(new StringBuilder(String.valueOf(dateString))
            .append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR).toString(), this.sansFont6Gray);
    float dateWidth = dateChunk.getWidthPoint();
    Paragraph contentParagraph = new Paragraph();
    if (contentString.length() > 0) {
        Element contentChunk = new Chunk(contentString, this.sansFont9);
        messageWidth = contentChunk.getWidthPoint();
        contentParagraph.add(contentChunk);
    }/* w w w. j  av  a 2 s .  co m*/
    if (messageWidth < dateWidth) {
        messageWidth = dateWidth;
    }
    if (messageWidth > MAX_COLUMN_CONTENT_WIDTH) {
        messageWidth = MAX_COLUMN_CONTENT_WIDTH;
        dateWidth += 7.0f;
    }
    Paragraph dateParagraph = new Paragraph(dateChunk);
    if (isMe.booleanValue()) {
        dateParagraph.setAlignment(0);
        dateParagraph
                .setIndentationLeft((((BUBBLE_L_WIDTH + messageWidth) + BUBBLE_R_WIDTH) + 7.0f) - dateWidth);
    } else {
        dateParagraph.setAlignment(2);
        dateParagraph
                .setIndentationRight((((BUBBLE_L_WIDTH + messageWidth) + BUBBLE_R_WIDTH) + 7.0f) - dateWidth);
    }
    ct.addElement(dateParagraph);
    contentParagraph.setExtraParagraphSpace(10.0f);
    if (contentString.length() > 0) {
        contentParagraph.setAlignment(0);
        if (isMe.booleanValue()) {
            contentParagraph.setIndentationLeft(8.6f);
            contentParagraph.setIndentationRight(BUBBLE_TEXT_INDENT_ALTERNATE);
        } else {
            contentParagraph.setIndentationRight(8.6f);
            float indentLeft = COLUMN_WIDTH - (BUBBLE_L_WIDTH + messageWidth);
            if (messageWidth == MAX_COLUMN_CONTENT_WIDTH) {
                indentLeft += BUBBLE_TEXT_INDENT_ALTERNATE;
            }
            contentParagraph.setIndentationLeft(indentLeft);
        }
        ct.addElement(contentParagraph);
    } else if (contentBitmap != null) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        if (isVideo.booleanValue()) {
            contentBitmap.compress(CompressFormat.PNG, 50, stream);
        } else {
            contentBitmap.compress(CompressFormat.JPEG, 50, stream);
        }
        Image contentImage = Image.getInstance(stream.toByteArray());
        contentImage.scaleToFit(198.0f, 198.0f);
        if (isVideo.booleanValue()) {
            contentImage.setCompressionLevel(this.settings.compressionLevel);
        }
        contentImage.setSpacingBefore(10.0f);
        contentImage.setSpacingAfter(10.0f);
        if (isMe.booleanValue()) {
            contentImage.setAlignment(1);
        } else {
            contentImage.setAlignment(1);
        }
        ct.addElement(contentImage);
    }
    Paragraph senderParagraph = new Paragraph(new Chunk(senderString, this.sansFont9Gray));
    if (!isMe.booleanValue()) {
        senderParagraph.setAlignment(2);
    }
    senderParagraph.setSpacingAfter(BUBBLE_TEXT_INDENT_ALTERNATE);
    ct.addElement(senderParagraph);
    return messageWidth;
}

From source file:com.vectorprint.report.itext.ItextHelper.java

License:Open Source License

public static float getTextWidth(Chunk c) {
    return c.getWidthPoint();
}

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

/**
 * Erzeugt das Inhaltsverzeichnis aus den bereits vorhandenen Elementen in
 * der Liste <code>listEntries</code>.
 * //from  w  w  w .  ja va  2s.co m
 * @param docPdf
 *            Zieldokument, falls Inhaltsverzeichnis nicht temporr erzeugt
 *            wird
 * @param temp
 *            Gibt an, ob das Inhaltsverzeichnis temporr in einer neuen
 *            Datei/Dokument erzeugt werden soll
 * @return Anzahl der Seiten
 * @throws DocumentException
 * @throws IOException
 */
private int erzeugeInhaltsverzeichnis(Document docPdf, boolean temp) throws DocumentException, IOException {

    int anzPages = 0;
    Document docInhalt = docPdf;
    String filePathTempInhaltString = "";

    if (temp) {
        // temp. Dateinamen bestimmen
        File fileDokuFile = new File(dateiname);
        filePathTempInhaltString = fileDokuFile.getParent() + "/tmp_inhalt.pdf";
        // Neues Dokument erzeugen
        docInhalt = initPdfWriterAndDocument(filePathTempInhaltString, false);
    }

    // berschrift
    Chapter currChapter = new Chapter(getParagraphChapter("Inhaltsverzeichnis"), 0);
    // 0, damit keine Nummerierung
    currChapter.setNumberDepth(0);
    docInhalt.add(currChapter);
    // eine Zeile Abstand
    docInhalt.add(getEmptyLineTextHalf());

    for (ContPdfEntry currEntry : listEntries) {

        // Eintrag erzeugen inkl. Abstand
        String strEintrag = currEntry.getBezeichnung() + "  ";
        Chunk chunkBezeichnung;
        Chunk chunkSeitenzahlChunk;
        if (currEntry.getParentEntry() == null) {
            // 1. Ebene => fett, Abstand davor einfgen
            docInhalt.add(getEmptyLineTextHalf());
            chunkBezeichnung = getChunkTextBold(strEintrag);
            chunkSeitenzahlChunk = getChunkTextBold("" + currEntry.getPageNumber());
        } else {
            // 2. Ebene
            chunkBezeichnung = getChunkText(strEintrag);
            chunkSeitenzahlChunk = getChunkText("" + currEntry.getPageNumber());
        }
        // Referenz setzen
        chunkBezeichnung.setLocalGoto(currEntry.getDestination());
        chunkSeitenzahlChunk.setLocalGoto(currEntry.getDestination());
        // Abstandzeichen generieren, Breite auffllen
        float widthAbstand = docInhalt.getPageSize().getWidth() * 0.81f;
        ;
        while (chunkBezeichnung.getWidthPoint() <= widthAbstand) {
            chunkBezeichnung.append(".");
        }

        // Tabelle erzeugen und formatieren
        PdfPTable currTable = new PdfPTable(2);
        currTable.setWidthPercentage(100f);
        currTable.setWidths(new int[] { 96, 4 });

        // Inhalte einfgen
        // Zelle Bezeichnung
        PdfPCell currCellBezeichnung = new PdfPCell(new Phrase(chunkBezeichnung));
        currCellBezeichnung.setBorder(0);
        currCellBezeichnung.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);

        // Zelle Seitennummer
        PdfPCell currCellPageNumberCell = new PdfPCell(new Phrase(chunkSeitenzahlChunk));
        currCellPageNumberCell.setBorder(0);
        currCellPageNumberCell.setHorizontalAlignment(Element.ALIGN_RIGHT);

        // Zellen zur Tabelle hinzufgen
        currTable.addCell(currCellBezeichnung);
        currTable.addCell(currCellPageNumberCell);

        docInhalt.add(currTable);
    }

    if (temp) {
        // Dokument schlieen
        docInhalt.close();

        // Anzahl der Seitenzahlen bestimmen
        PdfReader reader = new PdfReader(filePathTempInhaltString);
        anzPages = reader.getNumberOfPages();
        reader.close();

        // temp. Datei lschen
        File currFileInhaltFile = new File(filePathTempInhaltString);
        currFileInhaltFile.delete();
    }
    return anzPages;
}

From source file:org.primaresearch.pdf.PageToPdfConverter.java

License:Apache License

/**
 * Calculates the font size to fit the given text into the specified dimensions.
 * @param text/* w  ww.j ava2 s  .  c o  m*/
 * @param width
 * @param height
 * @return
 * @throws IOException
 */
private float calculateFontSize(String text, int width, int height) throws IOException {

    float sw = font.getWidth(text);

    //float textHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000 * fontSize * 0.865;

    //float fontSizeY = height * 1000.0f / (font.get().getFontBoundingBox().getHeight() * 0.865f);
    float fontSizeX = width * 1000.0f / (sw * 0.865f);

    //Validate and reduce font size until it fits
    Chunk chunk = new Chunk(text, new Font(font, fontSizeX));
    ;
    while (chunk.getWidthPoint() > width) {
        fontSizeX -= 0.5f;
        chunk = new Chunk(text, new Font(font, fontSizeX));
    }

    //if (fontSizeX <= 0.0f && fontSizeY <= 0.0f)
    //   return 12f;

    //return Math.min(fontSizeX, fontSizeY);
    return fontSizeX;
}

From source file:psManage.StructSheet.java

public void createPdf(String mainTitle, String subTitle, String url, String userName,
        //String scanType,
        String comment,/*ww  w.j  a  v a 2s .co m*/
        //String thisPassCode,
        String passCodeA, String passCodeB, String fileDir, Boolean noBarCodePrint)
        throws IOException, DocumentException, RuntimeException {
    Document document = null;
    try {
        // step 1
        document = new Document(PageSize.A4, 60, 50, 50, 35);
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileDir));
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();
        /*
         Properties props = new Properties();
         String jarPath = System.getProperty("java.class.path");
         String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator)+1);
         FontFactory.registerDirectory("/res");
         FontFactory.register("ipag.ttf");
         Font ipaGothic = FontFactory.getFont("ipag", BaseFont.IDENTITY_H, 
         BaseFont.EMBEDDED, 10); //10 is the size
                
         InputStream is = getClass().getResourceAsStream("/res/ipag.ttf");
         */

        Properties props = new Properties();
        String jarPath = System.getProperty("java.class.path");
        String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator) + 1);
        System.out.println(jarPath);
        System.out.println(dirPath);
        System.out.println(System.getProperty("user.dir"));

        Font ipaGothic = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf",
                BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 11);

        Font ipaGothic14 = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf",
                BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 14);

        //?(2)
        PdfPTable pdfPTable = new PdfPTable(2);

        pdfPTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        pdfPTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        pdfPTable.getDefaultCell().setFixedHeight(150);

        pdfPTable.setWidthPercentage(100f);

        int pdfPTableWidth[] = { 10, 90 };
        pdfPTable.setWidths(pdfPTableWidth);

        PdfPCell cell_1_1 = new PdfPCell(new Paragraph("??", ipaGothic));
        cell_1_1.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell_1_1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell_1_1.setFixedHeight(50);
        PdfPCell cell_1_2 = new PdfPCell(new Paragraph(mainTitle, ipaGothic));
        cell_1_2.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell_1_2.setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPCell cell_2_1 = new PdfPCell(new Paragraph("", ipaGothic));
        cell_2_1.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell_2_1.setHorizontalAlignment(Element.ALIGN_CENTER);
        PdfPCell cell_2_2 = new PdfPCell(new Paragraph(subTitle, ipaGothic));
        cell_2_2.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell_2_2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell_2_2.setFixedHeight(50);
        pdfPTable.addCell(cell_1_1);
        pdfPTable.addCell(cell_1_2);
        pdfPTable.addCell(cell_2_1);
        pdfPTable.addCell(cell_2_2);

        PdfPCell cellUrlKey = new PdfPCell(new Paragraph("?", ipaGothic));
        cellUrlKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellUrlKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellUrlKey.setRowspan(2);
        pdfPTable.addCell(cellUrlKey);

        PdfPCell cellUrlValue = new PdfPCell(new Paragraph(url, ipaGothic));
        Chunk chunk = new Chunk(url, ipaGothic); // ??????????????
        System.out.println("??" + chunk.getWidthPoint());
        cellUrlValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
        if (chunk.getWidthPoint() > 410) { // ??????????
            cellUrlValue.setHorizontalAlignment(Element.ALIGN_LEFT);
        } else { // ?????????
            cellUrlValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        }

        cellUrlValue.setFixedHeight(50);
        pdfPTable.addCell(cellUrlValue);

        if (url.length() != 0 && !noBarCodePrint) {
            /* ?
             BarcodeQRCode qr = new BarcodeQRCode(url, 50, 50, null);
             PdfPCell cellUrlValueQr = new PdfPCell(qr.getImage());
             cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE);
             cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER);
             cellUrlValueQr.setFixedHeight(80);
             pdfPTable.addCell(cellUrlValueQr);
             */
            Image image = ZxingUti.getQRCode(url); //  SHIFT_JIS
            com.itextpdf.text.Image iTextImage = com.itextpdf.text.Image.getInstance(image, null);
            PdfPCell cell = new PdfPCell(iTextImage);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setFixedHeight(100);
            pdfPTable.addCell(cell); //  SIFT_JIS
        } else {
            PdfPCell cellUrlValueQr = new PdfPCell(new Paragraph("", ipaGothic));
            cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellUrlValueQr.setFixedHeight(80);
            pdfPTable.addCell(cellUrlValueQr);
        }

        PdfPCell cellUserNameKey = new PdfPCell(new Paragraph("", ipaGothic));
        cellUserNameKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellUserNameKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellUserNameKey.setRowspan(2);
        pdfPTable.addCell(cellUserNameKey);

        PdfPCell cellUserNameValue = new PdfPCell(new Paragraph(userName, ipaGothic14));
        cellUserNameValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellUserNameValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellUserNameValue.setFixedHeight(30);
        pdfPTable.addCell(cellUserNameValue);

        if (userName.length() != 0 && !noBarCodePrint) {
            Barcode128 code128 = new Barcode128();
            code128.setCode(userName);
            code128.setFont(ipaGothic.getBaseFont());
            code128.setBarHeight(40f);
            PdfPCell cellUserNameValueBc = new PdfPCell(code128.createImageWithBarcode(cb, null, null));
            cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellUserNameValueBc.setFixedHeight(80);
            pdfPTable.addCell(cellUserNameValueBc);
        } else {
            PdfPCell cellUserNameValueBc = new PdfPCell(new Paragraph("---", ipaGothic));
            cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellUserNameValueBc.setFixedHeight(80);
            pdfPTable.addCell(cellUserNameValueBc);
        }

        PdfPCell cellPassCodeKey = new PdfPCell(new Paragraph("?", ipaGothic));
        cellPassCodeKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellPassCodeKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellPassCodeKey.setRowspan(3);
        pdfPTable.addCell(cellPassCodeKey);

        PdfPCell cellPassCodeValue = new PdfPCell(new Paragraph(passCodeA + passCodeB, ipaGothic14));
        cellPassCodeValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellPassCodeValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellPassCodeValue.setFixedHeight(30);
        pdfPTable.addCell(cellPassCodeValue);

        if (passCodeA.length() != 0 && !noBarCodePrint) {
            Barcode128 code128 = new Barcode128();
            code128.setCode(passCodeA);
            code128.setFont(ipaGothic.getBaseFont());
            code128.setBarHeight(40f);
            PdfPCell cellPassCodeA_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null));
            cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellPassCodeA_Bc.setFixedHeight(80);
            pdfPTable.addCell(cellPassCodeA_Bc);
        } else {
            PdfPCell cellPassCodeA_Bc = new PdfPCell(new Paragraph("---", ipaGothic));
            cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellPassCodeA_Bc.setFixedHeight(80);
            pdfPTable.addCell(cellPassCodeA_Bc);
        }

        if (passCodeB.length() != 0 && !noBarCodePrint) {
            Barcode128 code128 = new Barcode128();
            code128.setCode(passCodeB);
            code128.setFont(ipaGothic.getBaseFont());
            code128.setBarHeight(40f);
            PdfPCell cellPassCodeB_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null));
            cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellPassCodeB_Bc.setFixedHeight(80);
            pdfPTable.addCell(cellPassCodeB_Bc);
        } else {
            PdfPCell cellPassCodeB_Bc = new PdfPCell(new Paragraph("---", ipaGothic));
            cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellPassCodeB_Bc.setFixedHeight(80);
            pdfPTable.addCell(cellPassCodeB_Bc);
        }

        PdfPCell cellCommentKey = new PdfPCell(new Paragraph("?", ipaGothic));
        cellCommentKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellCommentKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdfPTable.addCell(cellCommentKey);

        PdfPCell cellCommentValue = new PdfPCell(new Paragraph(comment, ipaGothic));
        cellCommentValue.setVerticalAlignment(Element.ALIGN_TOP);
        cellCommentValue.setHorizontalAlignment(Element.ALIGN_LEFT);
        cellCommentValue.setFixedHeight(150);
        pdfPTable.addCell(cellCommentValue);

        PdfPCell cellIssueKey = new PdfPCell(new Paragraph("", ipaGothic));
        cellIssueKey.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellIssueKey.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdfPTable.addCell(cellIssueKey);

        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        String strDate = sdf.format(cal.getTime());
        PdfPCell cellIssueValue = new PdfPCell(new Paragraph(strDate, ipaGothic));
        cellIssueValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellIssueValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellIssueValue.setFixedHeight(20);
        pdfPTable.addCell(cellIssueValue);

        //??
        document.add(pdfPTable);
        /*
                
         // CODE 128
         document.add(new Paragraph("?? : " + mainTitle, ipaGothic));
         document.add(new Paragraph(" : " + subTitle, ipaGothic));
         document.add(new Paragraph("-------------------------------------------------------"));
         document.add(new Paragraph(" " + strDate));
         document.add(new Paragraph("-------------------------------------------------------"));
                
                
         BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.EMBEDDED);
         Font font = new Font(bf, 12);
         document.add(new Paragraph("", ipaGothic));
         document.add(new Paragraph(url, ipaGothic));
         code128.setCode(url);
         code128.setFont(bf);
         code128.setX(1);
         //document.add(code128.createImageWithBarcode(cb, null, null));
                
         document.add(new Paragraph("USER", ipaGothic));
         if (userName.length() != 0) {
         document.add(new Paragraph(userName, ipaGothic));
         code128.setCode(userName);
         code128.setFont(bf);
         code128.setBarHeight(40f);
         document.add(code128.createImageWithBarcode(cb, null, null));
         }
                
         document.add(new Paragraph("CODE", ipaGothic));
         if (passCode.length() != 0) {
         document.add(new Paragraph(passCode, ipaGothic));
         code128.setCode(passCode);
         code128.setFont(bf);
         document.add(code128.createImageWithBarcode(cb, null, null));
         }
                
         document.add(new Paragraph("?", ipaGothic));
         document.add(new Paragraph(comment, ipaGothic));
         */
        // step 5
        document.close();
    } catch (RuntimeException ex) {
        document.close();
        throw ex;

    }
}