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

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

Introduction

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

Prototype

public PdfPCell(PdfPCell cell) 

Source Link

Document

Constructs a deep copy of a PdfPCell.

Usage

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

private void addReplyLink(Document document, String replyURL) throws DocumentException {
    PdfPTable replyTable = new PdfPTable(1);
    replyTable.setWidthPercentage(100f);

    replyTable.setSplitLate(false);/*from  w  ww.j  a  va  2s  .c  o  m*/

    replyTable.setSpacingBefore(5f);
    replyTable.setHorizontalAlignment(Element.ALIGN_LEFT);

    Font linkFont = new Font();

    linkFont.setStyle(Font.BOLD);
    linkFont.setColor(0, 0, 255);
    linkFont.setSize(headerFontSize);

    Chunk anchor = new Chunk("Reply", linkFont);

    anchor.setAnchor(replyURL);

    Phrase phrase = new Phrase();

    phrase.add(anchor);

    PdfPCell cell = new PdfPCell(phrase);
    cell.setBorder(Rectangle.NO_BORDER);

    replyTable.addCell(cell);

    document.add(replyTable);
}

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

public void buildPDF(MimeMessage message, String replyURL, OutputStream pdfStream)
        throws DocumentException, MessagingException, IOException {
    Document document = createDocument();

    PdfWriter pdfWriter = createPdfWriter(document, pdfStream);

    document.open();/*w ww.ja  va2  s .  c o m*/

    String[] froms = null;

    try {
        froms = EmailAddressUtils.addressesToStrings(message.getFrom(), true /* mime decode */);
    } catch (MessagingException e) {
        logger.warn("From address is not a valid email address.");
    }

    if (froms != null) {
        for (String from : froms) {
            document.addAuthor(from);
        }
    }

    String subject = null;

    try {
        subject = message.getSubject();
    } catch (MessagingException e) {
        logger.error("Error getting subject.", e);
    }

    if (subject != null) {
        document.addSubject(subject);
        document.addTitle(subject);
    }

    String[] tos = null;

    try {
        tos = EmailAddressUtils.addressesToStrings(message.getRecipients(RecipientType.TO),
                true /* mime decode */);
    } catch (MessagingException e) {
        logger.warn("To is not a valid email address.");
    }

    String[] ccs = null;

    try {
        ccs = EmailAddressUtils.addressesToStrings(message.getRecipients(RecipientType.CC),
                true /* mime decode */);
    } catch (MessagingException e) {
        logger.warn("CC is not a valid email address.");
    }

    Date sentDate = null;

    try {
        sentDate = message.getSentDate();
    } catch (MessagingException e) {
        logger.error("Error getting sent date.", e);
    }

    Collection<Part> attachments = new LinkedList<Part>();

    String body = BodyPartUtils.getPlainBodyAndAttachments(message, attachments);

    attachments = preprocessAttachments(attachments);

    if (body == null) {
        body = MISSING_BODY;
    }

    /*
     * PDF does not have tab support so we convert tabs to spaces
     */
    body = StringReplaceUtils.replaceTabsWithSpaces(body, tabWidth);

    PdfPTable headerTable = new PdfPTable(2);

    headerTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    headerTable.setWidthPercentage(100);
    headerTable.setWidths(new int[] { 1, 6 });
    headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    Font headerFont = createHeaderFont();

    FontSelector headerFontSelector = createHeaderFontSelector();

    PdfPCell cell = new PdfPCell(new Paragraph("From:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);

    String decodedFroms = StringUtils.defaultString(StringUtils.join(froms, ", "));

    headerTable.addCell(headerFontSelector.process(decodedFroms));

    cell = new PdfPCell(new Paragraph("To:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(StringUtils.join(tos, ", "))));

    cell = new PdfPCell(new Paragraph("CC:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(StringUtils.join(ccs, ", "))));

    cell = new PdfPCell(new Paragraph("Subject:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(subject)));

    cell = new PdfPCell(new Paragraph("Date:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable.addCell(ObjectUtils.toString(sentDate));

    cell = new PdfPCell(new Paragraph("Attachments:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable
            .addCell(headerFontSelector.process(StringUtils.defaultString(getAttachmentHeader(attachments))));

    document.add(headerTable);

    if (replyURL != null) {
        addReplyLink(document, replyURL);
    }

    /*
     * Body table will contain the body of the message
     */
    PdfPTable bodyTable = new PdfPTable(1);
    bodyTable.setWidthPercentage(100f);

    bodyTable.setSplitLate(false);

    bodyTable.setSpacingBefore(15f);
    bodyTable.setHorizontalAlignment(Element.ALIGN_LEFT);

    addBodyAndAttachments(pdfWriter, document, bodyTable, body, attachments);

    Phrase footer = new Phrase(FOOTER_TEXT);

    PdfContentByte cb = pdfWriter.getDirectContent();

    ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, footer, document.right(), document.bottom(), 0);

    document.close();
}

From source file:mx.dr.util.report.impl.PdfService.java

License:Open Source License

/**
* write a label in pdf document./*from   w  ww.  j av a  2  s.  co  m*/
* <br/>
* escribe una etiqueta en el documento pdf.
* @param doc pdf document / documento pdf.
* @param dto object that encompasses the values of the labels to be placed in the document / objeto que engloba los valores de las etiquetas que se colocaran en el documento.
* @param offset jump on the Y axis to be given before placing the tag in the document / salto en el eje Y que se dara antes de colocar la etiqueta en el documento.
* @param table container table if applicable / contenedor de tabla si es que aplica.
* @throws Exception If an error occurs / si ocurre algun error.
*/
public void estampaEtiqueta(Document doc, Object dto, Float offset, PdfPTable table) throws Exception {
    List<Field> fields = new ArrayList<Field>();

    for (Field m : dto.getClass().getDeclaredFields()) {
        m.setAccessible(true);
        if (m.getAnnotation(DRPdfLabel.class) != null) {
            fields.add(m);
        }
    }
    Collections.sort(fields, new Comparator<Field>() {

        public int compare(Field o1, Field o2) {
            DRPdfLabel etiqueta1 = o1.getAnnotation(DRPdfLabel.class);
            DRPdfLabel etiqueta2 = o2.getAnnotation(DRPdfLabel.class);
            String uno = int2String(etiqueta1.y()) + "." + int2String(etiqueta1.order());
            String dos = int2String(etiqueta2.y()) + "." + int2String(etiqueta2.order());
            return uno.compareTo(dos);

        }

        private String int2String(int num) {
            if (num < 10) {
                return "0" + num;
            } else {
                return String.valueOf(num);
            }
        }
    });
    DRPdfLabel etiqueta;
    DRPdfTable etiquetaTabla;
    int lineaActual = 0;
    Paragraph pantagram = null;
    StringBuffer sb = null;
    Font font;
    Object valor;
    String label;
    DRPdfImage img;
    int residuo;
    int adicional = 0;
    for (Field m : fields) {
        etiqueta = m.getAnnotation(DRPdfLabel.class);
        img = m.getAnnotation(DRPdfImage.class);
        valor = m.get(dto);
        if (valor != null && valor instanceof List) {
            etiquetaTabla = m.getAnnotation(DRPdfTable.class);
            PdfPTable tableDance = null;
            if (etiquetaTabla != null) {
                tableDance = new PdfPTable(etiquetaTabla.colsPercentage());
                tableDance.setSpacingBefore(etiqueta.offset());
                for (String c : etiquetaTabla.columnLabels()) {
                    tableDance.addCell(c);
                }
            }
            if (pantagram != null) {
                doc.add(pantagram);
                pantagram = null;
            }
            for (int i = 0; i < ((List) valor).size(); i++) {
                if (i == 0 && etiqueta.offset() > 0) {
                    estampaEtiqueta(doc, ((List) valor).get(i), etiqueta.offset(), tableDance);
                } else {
                    estampaEtiqueta(doc, ((List) valor).get(i), null, tableDance);
                }
            }
            if (etiquetaTabla != null) {
                doc.add(tableDance);
            }
        } else if (img != null) {
            /* File file = new File(IMGDIR + valor);
            FileInputStream inImg = new FileInputStream(file);
            byte[] b=new byte[(int)file.length()];
            inImg.read(b);*/

            Image ima = Image.getInstance(IMGDIR + valor);

            //System.out.println(ima.getPlainWidth());
            ima.scaleAbsoluteWidth(img.width());
            //System.out.println(ima.getScaledWidth());
            ima.scaleAbsoluteHeight(ima.getScaledWidth());
            ima.setAlignment(img.style());
            ima.setAbsolutePosition(img.x(), img.y());
            doc.add(ima);

        } else if (table != null) {

            PdfPCell cerda = null;

            label = value2String(valor);
            residuo = etiqueta.length() - label.length();
            label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label;
            DRPdfColumn col = m.getAnnotation(DRPdfColumn.class);
            if (col != null) {
                cerda = new PdfPCell(new Paragraph(label));
                cerda.setColspan(col.colspan());
                table.addCell(cerda);
            } else {
                table.addCell(label);
            }

        } else {
            if (lineaActual < etiqueta.y()) {
                if (pantagram != null) {
                    doc.add(pantagram);
                }
                if (offset == null || etiqueta.y() > 1) {
                    if (etiqueta.offset() > 0) {
                        pantagram = new Paragraph(etiqueta.offset());
                    } else {
                        pantagram = new Paragraph();
                    }
                } else {
                    pantagram = new Paragraph(offset);
                }
                lineaActual = etiqueta.y();
            }

            if (etiqueta.wspacesBefore() > 0) {
                sb = new StringBuffer("");
                fillEmpty(etiqueta.wspacesBefore(), sb);
                font = new Font(Font.COURIER, 12);
                pantagram.add(new Chunk(sb.toString(), font));
            }
            sb = new StringBuffer("");
            label = value2String(valor);
            residuo = etiqueta.length() - label.length();
            label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label;

            if (etiqueta.font().equals(BaseFont.COURIER)) {
                font = new Font(Font.COURIER, etiqueta.fontSize(), etiqueta.style(),
                        new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2]));
                adicional = 0;
            } else {
                font = FontFactory.getFont(TTFDIR + etiqueta.font(), BaseFont.CP1252, BaseFont.EMBEDDED,
                        etiqueta.fontSize(), etiqueta.style(),
                        new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2]));
                adicional = label.equals("") ? (residuo / 2) + 1 : 0;
            }

            if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.DER) && residuo > 0) {
                fillEmpty(residuo + adicional, sb);
            }
            sb.append(label);
            if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.IZQ) && residuo > 0) {
                fillEmpty(residuo + adicional, sb);
            }
            pantagram.add(new Chunk(sb.toString(), font));
        }
    }
    if (pantagram != null) {
        doc.add(pantagram);
    }

}

From source file:net.algem.contact.TeacherCtrl.java

License:Open Source License

private File getFollowUpAsPDF(String userId, String from, String to)
        throws IOException, BadElementException, DocumentException {
    String path = "/tmp/" + "suivi-" + userId + ".pdf";
    File f = new File(path);
    LOGGER.log(Level.INFO, f.getName());
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Document document = new Document(PageSize.A4.rotate());
    PdfWriter.getInstance(document, byteArrayOutputStream); // Do this BEFORE document.open()
    document.open();/*from w w w  .  j  a  va 2  s. co m*/

    PdfPTable table = new PdfPTable(10);
    table.setWidthPercentage(100);
    table.setWidths(new float[] { 1.1f, 1.2f, 0.6f, 1.5f, 1.5f, 2f, 0.5f, 0.5f, 1.9f, 1.9f });

    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);
    BaseFont bfb = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, false);
    Font normalFont = new Font(bf, 10);
    Font boldFont = new Font(bfb, 10);

    String fromLabel = messageSource.getMessage("from.label", null, CTX_LOCALE);
    String toLabel = messageSource.getMessage("to.label", null, CTX_LOCALE);
    String prefix = messageSource.getMessage("follow-up.label", null, CTX_LOCALE) + " "
            + organization.get("name.label");
    String period = fromLabel.toLowerCase() + " " + from + " " + toLabel.toLowerCase() + " " + to;
    PdfPCell headerCell = new PdfPCell(new Phrase(prefix + " " + period, boldFont));

    headerCell.setBackgroundColor(Color.LIGHT_GRAY);
    headerCell.setColspan(10);
    table.addCell(headerCell);

    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("date.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("time.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("time.length.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("room.label", null, CTX_LOCALE), boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("course.label", null, CTX_LOCALE), boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("student.label", null, CTX_LOCALE), boldFont)));
    String abs = messageSource.getMessage("absence.label", null, CTX_LOCALE);
    table.addCell(new PdfPCell(new Phrase(abs != null ? abs.substring(0, 3) + "." : "", boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("score.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("individual.logbook.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("collective.comment.label", null, CTX_LOCALE), boldFont)));

    List<ScheduleElement> items = getFollowUpSchedules(userId, from, to);
    //LOGGER.log(Level.INFO, items.toString());
    for (ScheduleElement e : items) {
        List<ScheduleRangeElement> ranges = new ArrayList<ScheduleRangeElement>(
                (Collection<? extends ScheduleRangeElement>) e.getRanges());

        for (ScheduleRangeElement r : ranges) {
            String status = CommonDao.getAbsenceFromNumberStatus(r.getFollowUp().getStatus());
            String note = r.getFollowUp().getNote();
            String content1 = r.getFollowUp().getContent();
            String content2 = e.getFollowUp().getContent();
            table.addCell(new Phrase(e.getDateFr().toString(), normalFont));
            table.addCell(new Phrase(r.getStart() + "-" + r.getEnd(), normalFont));
            table.addCell(new Phrase(new Hour(r.getLength()).toString(), normalFont));
            table.addCell(new Phrase(e.getDetail().get("room").getName(), normalFont));
            table.addCell(new Phrase(e.getDetail().get("course").getName(), normalFont));
            table.addCell(new Phrase(r.getPerson().getFirstName() + " " + r.getPerson().getName(), normalFont));
            table.addCell(new Phrase(status, normalFont));
            table.addCell(new Phrase(note == null ? "" : note, normalFont));
            table.addCell(new Phrase(content1 == null ? "" : content1.replaceAll("[\r\n]", " "), normalFont));
            table.addCell(new Phrase(content2 == null ? "" : content2.replaceAll("[\r\n]", " "), normalFont));
        }
    }

    document.add(table);
    document.close();
    byte[] pdfBytes = byteArrayOutputStream.toByteArray();
    Files.write(Paths.get(path), pdfBytes);
    return f;
}

From source file:net.algem.security.UserCtrl.java

License:Open Source License

private File getFollowUpAsPDF(String userId, String from, String to)
        throws IOException, BadElementException, DocumentException {
    String path = "/tmp/" + "suivi-" + userId + ".pdf";
    File f = new File(path);
    LOGGER.log(Level.INFO, f.getName());
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Document document = new Document(PageSize.A4.rotate());
    PdfWriter.getInstance(document, byteArrayOutputStream); // Do this BEFORE document.open()
    document.open();//from w  w  w  .j a  v a 2s  .c  o  m

    PdfPTable table = new PdfPTable(10);
    table.setWidthPercentage(100);
    table.setWidths(new float[] { 1.1f, 1.2f, 0.6f, 1.5f, 1.5f, 2f, 0.5f, 0.5f, 1.9f, 1.9f });

    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);
    BaseFont bfb = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, false);
    Font normalFont = new Font(bf, 10);
    Font boldFont = new Font(bfb, 10);

    String fromLabel = messageSource.getMessage("from.label", null, CTX_LOCALE);
    String toLabel = messageSource.getMessage("to.label", null, CTX_LOCALE);
    String prefix = messageSource.getMessage("follow-up.label", null, CTX_LOCALE) + " "
            + organization.get("name.label");
    String period = fromLabel.toLowerCase() + " " + from + " " + toLabel.toLowerCase() + " " + to;
    PdfPCell headerCell = new PdfPCell(new Phrase(prefix + " " + period, boldFont));

    headerCell.setBackgroundColor(Color.LIGHT_GRAY);
    headerCell.setColspan(10);
    table.addCell(headerCell);

    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("date.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("time.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("time.length.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("room.label", null, CTX_LOCALE), boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("course.label", null, CTX_LOCALE), boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("teacher.label", null, CTX_LOCALE), boldFont)));
    String abs = messageSource.getMessage("absence.label", null, CTX_LOCALE);
    table.addCell(new PdfPCell(new Phrase(abs != null ? abs.substring(0, 3) + "." : "", boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("score.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("individual.logbook.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("collective.comment.label", null, CTX_LOCALE), boldFont)));

    fillPdfTable(table, getFollowUpSchedules(userId, from, to), normalFont);

    document.add(table);
    document.close();
    byte[] pdfBytes = byteArrayOutputStream.toByteArray();
    Files.write(Paths.get(path), pdfBytes);
    return f;
}

From source file:nl.dykema.jxmlnote.spikes.Spacing.java

License:Open Source License

/**
 * Main method./*from  www.  j a  v a2 s  . c  o  m*/
 * @param    args    no arguments needed
 * @throws DocumentException 
 * @throws IOException
 */
public static void main(String[] args) throws DocumentException, IOException {
    // step 1
    Document document = new Document();
    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(RESULT));
    // step 3
    document.open();
    // step 4
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    Phrase p = new Phrase(
            "Dr. iText or: How I Learned to Stop Worrying " + "and Love the Portable Document Format.");
    PdfPCell cell = new PdfPCell(p);
    table.addCell("default leading / spacing");
    table.addCell(cell);
    table.addCell("absolute leading: 20");
    cell.setLeading(20f, 0f);
    table.addCell(cell);
    table.addCell("absolute leading: 3; relative leading: 1.2");
    cell.setLeading(3f, 1.2f);
    table.addCell(cell);
    table.addCell("absolute leading: 0; relative leading: 1.2");
    cell.setLeading(0f, 1.2f);
    table.addCell(cell);
    table.addCell("no leading at all");
    cell.setLeading(0f, 0f);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("Dr. iText or: How I Learned to Stop Worrying and Love PDF"));
    table.addCell("padding 10");
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell("padding 0");
    cell.setPadding(0);
    table.addCell(cell);
    table.addCell("different padding for left, right, top and bottom");
    cell.setPaddingLeft(20);
    cell.setPaddingRight(50);
    cell.setPaddingTop(0);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    p = new Phrase("iText in Action Second Edition");
    table.getDefaultCell().setPadding(2);
    table.getDefaultCell().setUseAscender(false);
    table.getDefaultCell().setUseDescender(false);
    table.addCell("padding 2; no ascender, no descender");
    table.addCell(p);
    table.getDefaultCell().setUseAscender(true);
    table.getDefaultCell().setUseDescender(false);
    table.addCell("padding 2; ascender, no descender");
    table.addCell(p);
    table.getDefaultCell().setUseAscender(false);
    table.getDefaultCell().setUseDescender(true);
    table.addCell("padding 2; descender, no ascender");
    table.addCell(p);
    table.getDefaultCell().setUseAscender(true);
    table.getDefaultCell().setUseDescender(true);
    table.addCell("padding 2; ascender and descender");
    cell.setPadding(2);
    cell.setUseAscender(true);
    cell.setUseDescender(true);
    table.addCell(p);
    document.add(table);
    // step 5
    document.close();
}

From source file:open.dolphin.hiro.PrescriptionPDFMaker.java

/**
 * ??//from  ww  w .j av  a2 s .c o  m
 */
public String output() {
    BufferedOutputStream bos;
    PdfWriter pw = null;
    Document document = null;

    try {
        Date dateNow = new Date();

        // ID
        String patientId = pkg.getPatientId();

        // ???
        String name = pkg.getPatientName();
        name = name.replaceAll(" ", "");
        name = name.replaceAll("", "");

        String iNum; // ??
        String piNum = null; // ?
        String rNum = null; // ??

        String piNum2 = null; // ?
        String rNum2 = null; // ??

        String div = ""; // ?
        String payRatio = ""; // ?

        String mNum = ""; // ???

        char[] iNumC = new char[8]; // ???
        char[] piNumC = new char[8]; // ??
        char[] rNumC = new char[7]; // ??
        char[] piNumC2 = new char[8]; // ??
        char[] rNumC2 = new char[7]; // ??
        DecimalFormat df = new DecimalFormat("#0.#"); // ??
        String paymentRatio = ""; // ?
        String paymentRatio2 = ""; // ?

        if (pkg.getApplyedInsurance().getInsuranceNumber() != null) {

            // ??
            iNum = pkg.getApplyedInsurance().getInsuranceNumber();

            // ? null ??
            if (iNum.toLowerCase().startsWith("z") || iNum.equals("9999")) {
                iNum = null;
            }

            // 
            if (pkg.getApplyedInsurance().getPVTPublicInsuranceItem() != null) {
                PVTPublicInsuranceItemModel[] pubItems = pkg.getApplyedInsurance().getPVTPublicInsuranceItem();
                for (int i = 0; i < pubItems.length; i++) {
                    PVTPublicInsuranceItemModel pm = pubItems[i];
                    if (i == 0) {
                        // ?
                        piNum = pm.getProvider();
                        piNum = ("mikinyu".equals(piNum)) ? "" : piNum;

                        // ??
                        rNum = pm.getRecipient();
                        rNum = ("mikinyu".equals(rNum)) ? "" : rNum;

                        // ???
                        paymentRatio = pm.getPaymentRatio();
                    } else if (i == 1) {
                        piNum2 = pm.getProvider();
                        piNum2 = ("mikinyu".equals(piNum2)) ? "" : piNum2;

                        rNum2 = pm.getRecipient();
                        rNum2 = ("mikinyu".equals(rNum2)) ? "" : rNum2;

                        paymentRatio2 = pm.getPaymentRatio();
                        break;
                    }
                }
            }

            // ? ?? ?
            StringBuilder sb = new StringBuilder();

            // ? ?
            if (pkg.getApplyedInsurance().getClientGroup() != null
                    && !pkg.getApplyedInsurance().getClientGroup().equals("??")) {
                sb.append(pkg.getApplyedInsurance().getClientGroup()).append("");
            }
            // ??
            if (pkg.getApplyedInsurance().getClientNumber() != null
                    && !pkg.getApplyedInsurance().getClientNumber().equals("??")) {
                sb.append(pkg.getApplyedInsurance().getClientNumber());
            }
            mNum = sb.length() > 0 ? sb.toString() : "";

            // 
            if ("?".equals(pkg.getApplyedInsurance().getInsuranceClass())) {
                div = "";
                payRatio = paymentRatio;
            } else {
                // ?
                div = "true".equals(pkg.getApplyedInsurance().getFamilyClass()) ? "?"
                        : "";
                payRatio = pkg.getApplyedInsurance().getPayOutRatio();
            }
            if (payRatio != null && !("".equals(payRatio))) {
                payRatio = df.format(Double.valueOf(payRatio) * 10);
            }

            if (DEBUG) {
                System.err.println("iNum=" + iNum);
                System.err.println("piNum=" + piNum);
                System.err.println("rNum=" + rNum);
                System.err.println("piNum2=" + piNum2);
                System.err.println("rNum2=" + rNum2);
                System.err.println("mNum=" + mNum);
                System.err.println("?=" + div);
                System.err.println("=" + payRatio);
            }

            // ???
            iNumC = partitionPadRL(iNum, 8, "R"); // ??
            piNumC = partitionPadRL(piNum, 8, "L"); // ?
            rNumC = partitionPadRL(rNum, 7, "L"); // ??
            piNumC2 = partitionPadRL(piNum2, 8, "L"); // ?2
            rNumC2 = partitionPadRL(rNum2, 7, "L"); // ??2
        }
        /*****  *****/

        document = new Document(PageSize.A5, 10, 10, 2, 2);
        // @002 2009/11/17 
        // ?PDF????????
        if (getDocumentDir() == null) {
            StringBuilder sb = new StringBuilder();
            sb.append(System.getProperty("user.dir"));
            sb.append(File.separator);
            sb.append(DIR_NAME);
            setDocumentDir(sb.toString());
        }
        File dir = new File(getDocumentDir());
        dir.mkdir();

        // ??(?-ID_???_.pdf)
        StringBuilder sb = new StringBuilder();
        sb.append(FILE_NAME_PRE);
        sb.append(patientId).append("_").append(name).append("_");
        sb.append(new SimpleDateFormat("yyyyMMddHHmmss").format(dateNow));
        sb.append(FILE_EXTENTION);
        setFileName(sb.toString());

        sb = new StringBuilder();
        if (getDocumentDir() != null) {
            sb.append(getDocumentDir());
            sb.append(File.separator);
        }
        sb.append(getFileName());
        pathToPDF = sb.toString();

        //minagawa^ ???water mark?????????? byte[]???            
        ByteArrayOutputStream byteo = new ByteArrayOutputStream();
        bos = new BufferedOutputStream(byteo);
        //minagawa$             
        pw = PdfWriter.getInstance(document, bos);

        // font setting
        bfm = BaseFont.createFont(FONT_HEISEI_MIN3, CODE_UNIJIS_H, BaseFont.NOT_EMBEDDED);
        bfg = BaseFont.createFont(FONT_HEISEI_KAKU5, CODE_UNIJIS_H, BaseFont.NOT_EMBEDDED);
        min_6 = new Font(bfm, 6);
        min_7 = new Font(bfm, 7);
        min_8 = new Font(bfm, 8);
        min_9 = new Font(bfm, 9);
        min_10 = new Font(bfm, 10);
        min_12 = new Font(bfm, 12);
        min_14 = new Font(bfm, 14);
        min_15 = new Font(bfm, 15);
        min_4 = new Font(bfm, 4); // @009

        // 
        document.open();
        document.addAuthor(pkg.getPhysicianName());
        document.addTitle(PROPERTY_TITLE);
        document.addSubject(PROPERTY_SUB_TITLE);

        // ???
        List<PdfPTable> list = createPrescriptionTbl2();
        Iterator<PdfPTable> ite = list.iterator();

        // ?
        int pageNo = 0;
        int totalPageNo = list.size();

        // ?????????
        do {
            PdfPTable ptbl = new PdfPTable(1);
            ptbl.setWidthPercentage(100f);
            ptbl.getDefaultCell().setPadding(0f);
            PdfPCell pcell = new PdfPCell(new Paragraph(REPORT_TITLE, min_15));
            pcell.setBorder(Table.NO_BORDER);
            setAlignCenter(pcell);
            ptbl.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(REPORT_SUB_TITLE, min_7));
            pcell.setBorder(Table.NO_BORDER);
            setAlignCenter(pcell);
            ptbl.addCell(pcell);
            document.add(ptbl);

            ptbl = new PdfPTable(3);
            ptbl.setWidthPercentage(100f);
            ptbl.getDefaultCell().setPadding(0f);
            ptbl.getDefaultCell().setBorder(Table.NO_BORDER);
            float[] widths = { 43.5f, 2f, 54.5f };
            ptbl.setWidths(widths);
            // ?
            pcell = new PdfPCell(new Paragraph(patientId, min_9));
            pcell.setBorder(Table.NO_BORDER);
            pcell.setColspan(10);
            ptbl.addCell(pcell);

            PdfPTable ptblL = new PdfPTable(9);
            ptblL.setSpacingBefore(10f);
            ptblL.setWidthPercentage(100f);
            float[] widthsL = { 33, 8, 8, 8, 8, 8, 8, 8, 8 };
            ptblL.setWidths(widthsL);
            ptblL.getDefaultCell().setPadding(0f);
            pcell = new PdfPCell(new Paragraph("?", min_7));
            pcell.setMinimumHeight(CELL_HIGHT_0);
            setAlignJustifiedAll(pcell);
            setAlignMiddle(pcell);
            pcell.setBorderWidth(LINE_WIDTH_1);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[0]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[1]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[2]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[3]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[4]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_2);
            pcell.setBorderWidthRight(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[5]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthTop(LINE_WIDTH_2);
            pcell.setBorderWidthBottom(LINE_WIDTH_2);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[6]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_2);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setBorderWidthLeft(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[7]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph("???", min_7));
            pcell.setPaddingTop(0.3f);
            setAlignJustifiedAll(pcell);
            pcell.setBorderWidth(LINE_WIDTH_1);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[0]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[1]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[2]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[3]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[4]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[5]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[6]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell();
            pcell.setBorderWidth(LINE_WIDTH_0);
            ptblL.addCell(pcell);

            PdfPTable patientTbl = new PdfPTable(2);
            patientTbl.setWidthPercentage(100f);
            float[] widthsPa = { 7.8f, 92.2f };
            patientTbl.setWidths(widthsPa);
            patientTbl.getDefaultCell().setPadding(0f);
            patientTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell pcellP = new PdfPCell(new Paragraph("", min_7));
            pcellP.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pcellP);
            patientTbl.addCell(pcellP);
            // 
            PdfPTable desc = new PdfPTable(5);
            desc.setWidthPercentage(100f);
            float[] widthsD = { 28.5f, 41.5f, 7, 16, 7 };
            desc.setWidths(widthsD);
            // ???(??)
            PdfPCell patientInfo = new PdfPCell(new Paragraph("???", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(patientInfo);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            PdfPTable nameTbl = new PdfPTable(1);
            nameTbl.setWidthPercentage(100f);
            nameTbl.setSpacingAfter(3f);
            PdfPCell nameCell = new PdfPCell(new Paragraph(pkg.getPatientKana(), min_7));
            nameCell.setBorderWidth(LINE_WIDTH_0);
            nameTbl.addCell(nameCell);
            nameCell = new PdfPCell(new Paragraph(pkg.getPatientName(), min_9));
            nameCell.setBorderWidth(LINE_WIDTH_0);
            nameTbl.addCell(nameCell);
            patientInfo = new PdfPCell(nameTbl);
            patientInfo.setColspan(4);
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            desc.addCell(patientInfo);
            // 
            patientInfo = new PdfPCell(new Paragraph("", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(patientInfo);
            desc.addCell(patientInfo);
            String birthDay = ModelUtils.convertToGengo(pkg.getPatientBirthday());
            patientInfo = new PdfPCell(new Paragraph(birthDay, min_9));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            patientInfo.setColspan(3);
            patientInfo.setPaddingTop(0.5f);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph(pkg.getPatientSex(), min_8));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(patientInfo);
            desc.addCell(patientInfo);
            // 
            patientInfo = new PdfPCell(new Paragraph("", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(patientInfo);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph(div, min_8));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph("?", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph(payRatio, min_9));
            setAlignRightMiddle(patientInfo);
            patientInfo.setBorderWidth(LINE_WIDTH_0);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph("", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_0);
            patientInfo.setVerticalAlignment(Element.ALIGN_BOTTOM);
            setAlignRight(patientInfo);
            desc.addCell(patientInfo);
            patientTbl.addCell(desc);
            pcell = new PdfPCell(patientTbl);
            pcell.setColspan(9);
            pcell.setBorderWidth(LINE_WIDTH_1);
            ptblL.addCell(pcell);
            // 
            pcell = new PdfPCell(new Paragraph("", min_7));
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(pcell);
            setAlignMiddle(pcell);
            ptblL.addCell(pcell);
            // @003 2010/02/15 ???????????????
            String issueDate = ModelUtils.convertToGengo(
                    ModelUtils.getDateAsFormatString(pkg.getIssuanceDate(), IInfoModel.DATE_WITHOUT_TIME));
            pcell = new PdfPCell(new Paragraph(issueDate, min_9));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPaddingTop(0.5f);
            setAlignMiddle(pcell);
            pcell.setColspan(8);
            ptblL.addCell(pcell);

            ptbl.addCell(ptblL);
            ptbl.addCell("");

            PdfPTable ptblR = new PdfPTable(10);
            ptblR.setSpacingBefore(10f);
            ptblR.setWidthPercentage(100f);
            float[] widthsR = { 30, 7, 7, 7, 7, 7, 7, 7, 7, 14 };
            ptblR.setWidths(widthsR);
            pcell = new PdfPCell(new Paragraph("??", min_7));
            pcell.setMinimumHeight(CELL_HIGHT_0);
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(pcell);
            setAlignMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[0]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[1]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_2);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[2]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[3]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_2);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[4]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthTop(LINE_WIDTH_2);
            pcell.setBorderWidthBottom(LINE_WIDTH_2);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[5]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthTop(LINE_WIDTH_2);
            pcell.setBorderWidthBottom(LINE_WIDTH_2);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[6]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_2);
            pcell.setBorderWidthLeft(LINE_WIDTH_1);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[7]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell();
            pcell.setBorderWidth(LINE_WIDTH_0);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(
                    new Paragraph("?????", min_7));
            pcell.setPaddingTop(0.3f);
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(pcell);
            setAlignMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(mNum, min_9));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setColspan(9);
            setAlignMiddle(pcell);
            ptblR.addCell(pcell);

            //FacilityModel facility = getPhysician().getFacilityModel();
            String facilityName = pkg.getInstitutionName(); // ??
            //String facilityZipCode = facility.getZipCode(); // ?
            String facilityAddress = pkg.getInstitutionAddress(); // ?
            String facilityTelNo = pkg.getInstitutionTelephone(); // ?
            //minagawa^ ?????                 
            String drName = pkg.getPhysicianName();
            //minagawa$                    
            if (pkg.isChkUseDrugInfo()) {
                // ??
                drName = pkg.getPhysicianName();
            }
            // ********** @008 2010/06/18  **********
            // 20104?
            String prefNo = "  "; // ?? 2?
            String grade = " "; // ? 1?
            String institution = "       "; //  7?

            if ((pkg.getInstitutionNumber() != null) && (pkg.getInstitutionNumber().length() > 9)) {
                prefNo = pkg.getInstitutionNumber().substring(0, 2);
                grade = pkg.getInstitutionNumber().substring(2, 3);
                institution = pkg.getInstitutionNumber().substring(3, 10);
            }
            // ********** @008 2010/06/18  **********

            PdfPTable medOrgTbl = new PdfPTable(3);
            medOrgTbl.setWidthPercentage(100f);
            float[] widthsM = { 30, 55, 15 };
            medOrgTbl.setWidths(widthsM);
            PdfPCell medOrgCell = new PdfPCell(new Paragraph("??\n", min_7));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignJustifiedAll(medOrgCell);
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph(facilityAddress, min_8));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            medOrgCell.setColspan(2);
            setAlignMiddle(medOrgCell);
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph("????", min_7));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignJustifiedAll(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgCell.setPaddingBottom(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph(facilityName, min_8));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            medOrgCell.setColspan(2);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgCell.setPaddingBottom(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell();
            medOrgCell.setBorder(Table.NO_BORDER);
            medOrgCell.setColspan(3);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgCell.setPaddingBottom(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph("?", min_7));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignJustifiedAll(medOrgCell);
            setAlignMiddle(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph(facilityTelNo, min_9));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignMiddle(medOrgCell);
            medOrgCell.setColspan(2);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph("????", min_7));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignJustifiedAll(medOrgCell);
            setAlignMiddle(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph(drName, min_10));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignMiddle(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph("?", min_8));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignMiddle(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            pcell = new PdfPCell(medOrgTbl);
            pcell.setBorder(Table.NO_BORDER);
            pcell.setColspan(10);
            pcell.setPaddingBottom(CELL_PADDING_1);
            ptblR.addCell(pcell);
            // ********** @008 2010/06/18  **********
            // 20104? 
            PdfPTable medCodeTbl = new PdfPTable(13);
            medCodeTbl.setWidthPercentage(100f);
            float[] widthsCode = { 17, 8, 8, 15, 8, 17, 8, 8, 8, 8, 8, 8, 8 };
            medCodeTbl.setWidths(widthsCode);
            // ??
            PdfPCell medCodeCell = new PdfPCell(new Paragraph("?\n?", min_6));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(prefNo.charAt(0)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(prefNo.charAt(1)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph("\n?", min_6));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(grade.charAt(0)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph("", min_6));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(0)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(1)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(2)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(3)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(4)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(5)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(6)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            pcell = new PdfPCell(medCodeTbl);
            pcell.setBorder(Table.NO_BORDER);
            pcell.setColspan(10);
            pcell.setPaddingBottom(CELL_PADDING_1);
            ptblR.addCell(pcell);
            // ********** @008 2010/06/18  **********

            ptbl.addCell(ptblR);

            // ??
            PdfPTable termTbl = new PdfPTable(3);
            termTbl.setWidthPercentage(100f);
            float[] widthsT = { 14.8f, 26, 59.2f };
            termTbl.setWidths(widthsT);
            termTbl.getDefaultCell().setPadding(0f);
            PdfPCell termCell = new PdfPCell(new Paragraph("??\n", min_7));
            termCell.setBorderWidth(LINE_WIDTH_1);
            termCell.setPaddingTop(0.3f);
            setAlignJustifiedAll(termCell);
            termTbl.addCell(termCell);
            // ********* @009 2010/07/01  *********
            String periodDate = "?";
            if (pkg.getPeriod() != null) {
                periodDate = ModelUtils.convertToGengo(
                        ModelUtils.getDateAsFormatString(pkg.getPeriod(), IInfoModel.DATE_WITHOUT_TIME));
            }
            termCell = new PdfPCell(new Paragraph(periodDate, min_8));
            // ********* @009 2010/07/01  *********
            termCell.setBorderWidth(LINE_WIDTH_1);
            termCell.setBorderWidthRight(LINE_WIDTH_0);
            setAlignMiddle(termCell);
            termTbl.addCell(termCell);
            termCell = new PdfPCell(new Paragraph(
                    "???????????????????",
                    min_6));
            termCell.setBorderWidth(LINE_WIDTH_1);
            termCell.setBorderWidthLeft(LINE_WIDTH_0);
            setAlignMiddle(termCell);
            termTbl.addCell(termCell);
            pcell = new PdfPCell(termTbl);
            pcell.setBorder(Table.NO_BORDER);
            pcell.setColspan(3);
            ptbl.addCell(pcell);

            document.add(ptbl);

            // 
            ptbl = new PdfPTable(2);
            ptbl.setWidthPercentage(100f);
            ptbl.getDefaultCell().setPadding(0f);
            ptbl.getDefaultCell().setBorder(Table.NO_BORDER);
            float[] widthsPre = { 3.5f, 96.5f };
            ptbl.setWidths(widthsPre);
            pcell = new PdfPCell(
                    new Paragraph("", min_7));
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pcell);
            ptbl.addCell(pcell);
            // @005 2010/02/26  
            // ??
            // 
            PdfPTable outLineTbl = new PdfPTable(1);
            PdfPCell outLineCell; // ?
            // @005 2010/02/26  
            // 
            PdfPTable prescriptionTbl; // 
            if (ite.hasNext()) {
                prescriptionTbl = ite.next();
            } else {
                prescriptionTbl = new PdfPTable(1);
            }
            // @005 2010/02/26  
            // ??
            outLineCell = new PdfPCell(prescriptionTbl);
            outLineCell.setFixedHeight(200f);
            outLineCell.setBorderWidth(LINE_WIDTH_0);
            outLineTbl.addCell(outLineCell);
            if (totalPageNo > 1) {
                pageNo++;
                outLineCell = new PdfPCell(
                        new Paragraph((String.valueOf(pageNo) + "?" + String.valueOf(totalPageNo)), min_10));
                setAlignRight(outLineCell);
                outLineCell.setFixedHeight(12f); // @010
                outLineCell.setBorderWidth(LINE_WIDTH_1); // @010
                outLineTbl.addCell(outLineCell);
            }
            // @005 2010/02/26  
            PdfPCell prescriptionCell = new PdfPCell(outLineTbl);
            prescriptionCell.setFixedHeight(215f);
            prescriptionCell.setBorderWidth(LINE_WIDTH_1);
            ptbl.addCell(prescriptionCell);

            // 
            pcell = new PdfPCell(new Paragraph("", min_7));
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pcell);
            ptbl.addCell(pcell);
            // 
            PdfPTable noteTbl = new PdfPTable(5); // @010
            noteTbl.setWidthPercentage(100f);
            float[] widthsN = { 11, 4, 34, 4, 47 }; // @010
            noteTbl.setWidths(widthsN);
            noteTbl.getDefaultCell().setPadding(0f);
            noteTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            String address = (pkg.getPatientAddress() == null) ? "" : pkg.getPatientAddress();
            String patientName = pkg.getPatientName();
            String addressName = "?" + address + "\n???" + patientName;
            String useDrugInfo = "??" + pkg.getDrugLicenseNumber() + "("
                    + pkg.getPhysicianName() + ")";

            StringBuilder postInfo = new StringBuilder();
            // 
            if (pkg.isChkHomeMedical()) {
                postInfo.append(NOTES_HOME_MEDICAL + "\n");
            }
            if (pkg.isChkPatientInfo()) {
                // ?????
                postInfo.append(addressName);
            }
            if (postInfo.length() > 0) {
                // 
                postInfo.append("\n");
            }
            if (pkg.isChkUseDrugInfo()) {
                // ??
                postInfo.append(useDrugInfo);
            }
            // @010 20124 -->
            PdfPCell noteCell = new PdfPCell(new Paragraph("???", min_7));
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteCell.setBorderWidthBottom(LINE_WIDTH_1);
            noteCell.setMinimumHeight(CELL_HIGHT_2);
            setAlignTop(noteCell);
            noteTbl.addCell(noteCell);

            noteCell = new PdfPCell(new Paragraph("", min_15));//min_15
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteCell.setBorderWidthBottom(LINE_WIDTH_1);
            noteCell.setPadding(0f);
            setAlignRight(noteCell);
            noteTbl.addCell(noteCell);

            noteCell = new PdfPCell(new Paragraph(
                    "??????????\n?????????????",
                    min_6));
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteCell.setBorderWidthBottom(LINE_WIDTH_1);
            noteTbl.addCell(noteCell);

            noteCell = new PdfPCell(new Paragraph("", min_15));//min_15
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteCell.setBorderWidthBottom(LINE_WIDTH_1);
            noteCell.setBorderWidthRight(LINE_WIDTH_1);
            noteCell.setPadding(0f);
            setAlignLeft(noteCell);
            noteTbl.addCell(noteCell);

            //minagawa^ ????  47                   
            noteCell = new PdfPCell();
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteTbl.addCell(noteCell);
            //minagawa                    
            noteCell = new PdfPCell(new Paragraph(postInfo.toString(), min_7)); // ????????
            noteCell.setColspan(widthsN.length);
            noteCell.setMinimumHeight(40f);
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteTbl.addCell(noteCell);
            // <-- 20124 @010

            pcell = new PdfPCell(noteTbl);
            pcell.setBorderWidth(LINE_WIDTH_1);
            ptbl.addCell(pcell);

            document.add(ptbl);

            // ??
            ptbl = new PdfPTable(2);
            ptbl.setWidthPercentage(100f);
            float[] widthsOther = { 58, 42 };
            ptbl.setWidths(widthsOther);
            ptbl.getDefaultCell().setPadding(0f);
            ptbl.getDefaultCell().setBorder(Table.NO_BORDER);
            // 
            ptblL = new PdfPTable(3);
            ptblL.setWidthPercentage(100f);
            float[] widthsPh = { 28, 65, 7 };
            ptblL.setWidths(widthsPh);
            ptblL.getDefaultCell().setPadding(0f);
            ptblL.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell pcellL = new PdfPCell(new Paragraph("", min_7));
            pcellL.setMinimumHeight(CELL_HIGHT_0);
            pcellL.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(pcellL);
            setAlignMiddle(pcellL);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell(new Paragraph("?", min_8));
            pcellL.setBorderWidth(LINE_WIDTH_1);
            setAlignMiddle(pcellL);
            pcellL.setColspan(2);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell(new Paragraph("??\n??\n??", min_7));
            pcellL.setPaddingTop(0.2f);
            pcellL.setBorderWidth(LINE_WIDTH_1);
            pcellL.setBorderWidthBottom(LINE_WIDTH_0);
            setAlignJustifiedAll(pcellL);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell();
            pcellL.setBorderWidth(LINE_WIDTH_0);
            pcellL.setBorderWidthRight(LINE_WIDTH_1);
            pcellL.setColspan(2);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell(new Paragraph("?\n???", min_7));
            pcellL.setPaddingTop(0.2f);
            pcellL.setBorderWidth(LINE_WIDTH_1);
            pcellL.setBorderWidthTop(LINE_WIDTH_0);
            setAlignJustifiedAll(pcellL);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell();
            pcellL.setBorderWidth(LINE_WIDTH_0);
            pcellL.setBorderWidthBottom(LINE_WIDTH_1);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell(new Paragraph("?", min_8));
            pcellL.setBorderWidth(LINE_WIDTH_1);
            pcellL.setBorderWidthTop(LINE_WIDTH_0);
            pcellL.setBorderWidthLeft(LINE_WIDTH_0);
            setAlignJustifiedAll(pcellL);
            setAlignMiddle(pcellL);
            ptblL.addCell(pcellL);
            ptbl.addCell(ptblL);

            ptblR = new PdfPTable(9);
            ptblR.setWidthPercentage(100f);
            float[] widthsPu = { 33, 8, 8, 8, 8, 8, 8, 8, 8 };
            ptblR.setWidths(widthsPu);
            ptblR.getDefaultCell().setPadding(0f);
            PdfPCell pcellR = new PdfPCell(new Paragraph("?", min_7));
            pcellR.setMinimumHeight(CELL_HIGHT_0);
            setAlignJustifiedAll(pcellR);
            setAlignMiddle(pcellR);
            pcellR.setBorderWidth(LINE_WIDTH_1);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[0]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[1]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[2]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[3]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[4]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_2);
            pcellR.setBorderWidthRight(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[5]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthTop(LINE_WIDTH_2);
            pcellR.setBorderWidthBottom(LINE_WIDTH_2);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[6]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_2);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setBorderWidthLeft(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[7]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph("???", min_7));
            pcellR.setPaddingTop(0.3f);
            setAlignJustifiedAll(pcellR);
            pcellR.setBorderWidth(LINE_WIDTH_1);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[0]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[1]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[2]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[3]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[4]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[5]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[6]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell();
            pcellR.setBorderWidth(LINE_WIDTH_0);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell();
            pcellR.setBorderWidth(LINE_WIDTH_0);
            pcellR.setColspan(9);
            ptblR.addCell(pcellR);

            ptbl.addCell(ptblR);

            document.add(ptbl);

            ptbl = new PdfPTable(2);
            ptbl.setWidthPercentage(100f);
            float[] widthsMed = { 3.5f, 96.5f };
            ptbl.setWidths(widthsMed);
            ptbl.setSpacingBefore(3f);
            ptbl.getDefaultCell().setPadding(0f);
            ptbl.getDefaultCell().setBorder(Table.NO_BORDER);
            pcell = new PdfPCell(new Paragraph("????", min_7));
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(pcell);
            ptbl.addCell(pcell);

            ptblR = new PdfPTable(3);
            ptblR.setWidthPercentage(100f);
            float[] widthsPm = { 60, 20, 20 };
            ptblR.setWidths(widthsPm);
            ptblR.getDefaultCell().setPadding(0f);
            ptblR.getDefaultCell().setBorder(Table.NO_BORDER);
            // ????????
            PdfPTable pointTbl = new PdfPTable(7);
            pointTbl.setWidthPercentage(100f);
            float[] widthsPo = { 7, 15.5f, 15.5f, 15.5f, 15.5f, 15.5f, 15.5f };
            pointTbl.setWidths(widthsPo);
            pointTbl.getDefaultCell().setPadding(0f);
            pointTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("?", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("?", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            // ?
            PdfPCell blankCell = new PdfPCell();
            blankCell.setBorderWidth(LINE_WIDTH_1);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            ptblR.addCell(pointTbl);
            // ?
            PdfPTable feeTbl = new PdfPTable(2);
            feeTbl.setWidthPercentage(100f);
            float[] widthsF = { 50, 50 };
            feeTbl.setWidths(widthsF);
            feeTbl.getDefaultCell().setPadding(0f);
            feeTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell feeCell = new PdfPCell(new Paragraph("    ", min_7));
            feeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCell);
            feeTbl.addCell(feeCell);
            feeCell = new PdfPCell(new Paragraph("    ", min_7));
            feeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCell);
            feeTbl.addCell(feeCell);
            feeCell = new PdfPCell();
            feeCell.setBorderWidth(LINE_WIDTH_1);
            feeCell.setMinimumHeight(CELL_HIGHT_1);
            feeTbl.addCell(feeCell);
            feeTbl.addCell(feeCell);
            // ?etc..
            PdfPTable feeTblSub = new PdfPTable(4);
            feeTblSub.setWidthPercentage(100f);
            float[] widthsSub = { 28, 16, 28, 28 };
            feeTblSub.setWidths(widthsSub);
            feeTblSub.getDefaultCell().setPadding(0f);
            feeTblSub.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell feeCellSub = new PdfPCell(new Paragraph("?", min_7));
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeCellSub = new PdfPCell(new Paragraph("", min_7));
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeCellSub = new PdfPCell(new Paragraph("  ", min_7));
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeCellSub = new PdfPCell(new Paragraph("?  ", min_7));
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            // ?
            feeCellSub = new PdfPCell();
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            feeCellSub.setMinimumHeight(CELL_HIGHT_1);
            feeTblSub.addCell(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeCell = new PdfPCell(feeTblSub);
            feeCell.setBorder(Table.NO_BORDER);
            feeCell.setColspan(2);
            feeTbl.addCell(feeCell);
            // etc..?
            pcellR = new PdfPCell(feeTbl);
            pcellR.setPadding(0f);
            pcellR.setColspan(2);
            pcellR.setBorder(Table.NO_BORDER);
            ptblR.addCell(pcellR);
            // 
            noteTbl = new PdfPTable(2);
            noteTbl.setWidthPercentage(100f);
            float[] widthsNote = { 5.3f, 94.7f };
            noteTbl.setWidths(widthsNote);
            noteTbl.getDefaultCell().setPadding(0f);
            noteTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            noteCell = new PdfPCell(new Paragraph("", min_7));
            noteCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(noteCell);
            noteTbl.addCell(noteCell);
            noteCell = new PdfPCell();
            noteCell.setBorderWidth(LINE_WIDTH_1);
            noteTbl.addCell(noteCell);
            pcell = new PdfPCell(noteTbl);
            pcell.setBorderWidth(LINE_WIDTH_0);
            pcell.setPadding(0f);
            pcell.setColspan(2);
            ptblR.addCell(pcell);
            // ?
            PdfPTable sumTbl = new PdfPTable(1);
            sumTbl.setWidthPercentage(100f);
            sumTbl.getDefaultCell().setPadding(0f);
            sumTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell sumCell = new PdfPCell(new Paragraph("?", min_7));
            sumCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(sumCell);
            sumTbl.addCell(sumCell);
            sumCell = new PdfPCell();
            sumCell.setBorderWidth(LINE_WIDTH_1);
            sumCell.setMinimumHeight(CELL_HIGHT_1);
            sumTbl.addCell(sumCell);
            ptblR.addCell(sumTbl);

            pcell = new PdfPCell(ptblR);
            pcell.setBorderWidth(LINE_WIDTH_0);
            pcell.setPadding(0f);
            ptbl.addCell(pcell);

            document.add(ptbl);
            // 
            if (ite.hasNext()) {
                document.newPage();
            }

        } while (ite.hasNext());

        document.close();
        bos.close();

        // pdf content bytes
        byte[] pdfbytes = byteo.toByteArray();

        // ????? File????
        //if (!ClientContext.is5mTest()) {
        if (!Project.isTester()) {
            FileOutputStream fout = new FileOutputStream(pathToPDF);
            FileChannel channel = fout.getChannel();
            ByteBuffer bytebuff = ByteBuffer.wrap(pdfbytes);

            while (bytebuff.hasRemaining()) {
                channel.write(bytebuff);
            }
            channel.close();
            return pathToPDF;
        }

        // ??? water Mark ??
        PdfReader pdfReader = new PdfReader(pdfbytes);
        PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(pathToPDF));

        Image image = Image.getInstance(ClientContext.getImageResource("water-mark.png"));

        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {

            PdfContentByte content = pdfStamper.getUnderContent(i);

            image.scaleAbsolute(PageSize.A5.getWidth(), PageSize.A5.getHeight());
            image.setAbsolutePosition(0.0f, 0.0f);
            content.addImage(image);
        }

        pdfStamper.close();

        return pathToPDF;

    } catch (DocumentException e) {
        e.printStackTrace(System.err);
        throw new RuntimeException(e.getMessage());

    } catch (IOException e) {
        e.printStackTrace(System.err);
        throw new RuntimeException(e.getMessage());

    } catch (Exception e) {
        e.printStackTrace(System.err);
        throw new RuntimeException(e.getMessage());

    } finally {
        if (document != null && document.isOpen()) {
            document.close();
        }
    }
}

From source file:open.dolphin.hiro.PrescriptionPDFMaker.java

private List<PdfPTable> createPrescriptionTbl2() {
    ClaimItem[] items;/*www. j  a  va2s  .co  m*/
    PdfPCell pcell, blank, numCell, amountCell;
    int num, cnt;
    double sum; // @009 ?????(?*)
    List<PdfPTable> preTblList = null;
    String admin, number; // @009
    String classCode, amount, medicine; // @009

    try {
        StringBuilder sb = new StringBuilder();
        sb.append(
                "???????(??)??????????????\n");
        sb.append(
                "?????????????????????????");
        PdfPTable ptbl = new PdfPTable(9); // @009
        ptbl.setWidthPercentage(100f);
        // @009 ???, ?, ??, ?, ??, , "(", , ")"
        float[] widthsP = { 14, 7, 52, 8, 15, 32, 2, 5, 9 };
        ptbl.setWidths(widthsP);
        ptbl.getDefaultCell().setPadding(0f);
        preTblList = new ArrayList<PdfPTable>();

        num = 1;
        //admin = "";  // @009 
        //number = ""; // @009 
        //amount = ""; // @009 ?
        numCell = new PdfPCell(new Paragraph("", min_8)); // @009
        numCell.setBorderWidth(LINE_WIDTH_0); // @009

        PdfPCell notes = new PdfPCell(new Paragraph("??", min_8));
        notes.setBorderWidth(LINE_WIDTH_1);
        notes.setBorderWidthBottom(LINE_WIDTH_0);
        PdfPCell bracket = new PdfPCell(new Paragraph("", min_15));
        bracket.setBorderWidth(LINE_WIDTH_0);
        bracket.setHorizontalAlignment(Element.ALIGN_RIGHT);
        bracket.setPadding(0f);
        PdfPCell notesDetail = new PdfPCell(new Paragraph(sb.toString(), min_6));
        notesDetail.setBorderWidth(LINE_WIDTH_0);
        notesDetail.setColspan(5);
        PdfPCell bracketC = new PdfPCell(new Paragraph("", min_15));
        bracketC.setBorderWidth(LINE_WIDTH_0);
        bracketC.setHorizontalAlignment(Element.ALIGN_LEFT);
        bracketC.setPadding(0f);
        bracketC.setColspan(2);

        for (Iterator<BundleMed> ite = pkg.getPriscriptionList().iterator(); ite.hasNext();) {
            BundleMed prescription = ite.next();
            admin = prescription.getAdmin(); // @009  
            number = prescription.getBundleNumber(); // @009  ????=1 bundeNumber
            classCode = prescription.getClassCode(); // @009   221 etc 

            items = prescription.getClaimItem();
            //minagawa^                
            boolean genericIsOk = true;

            if (items != null) {
                for (ClaimItem i : items) {
                    if (i.getCode().equals("099209903")) {
                        genericIsOk = false;
                        break;
                    }
                }
            }
            genericIsOk = true;
            //minagawa4                

            if (ptbl.getRows().isEmpty()) {
                ptbl.addCell(notes);
                ptbl.addCell(bracket);
                ptbl.addCell(notesDetail);
                ptbl.addCell(bracketC);
            }

            // @001 2009/11/17 ?
            // items?null???????????????
            // ???????????items ? null ??????
            // if???????????(??????????)
            if (items != null) {
                boolean clearFlg = true; // @004 2010/02/26  ?
                // ********** @009  **********
                //sum = 0; // ?????
                Font adminF = min_8; // 
                boolean wrap = true;
                if (admin != null) {
                    if (admin.length() > 17) {
                        // ??17???4??
                        adminF = min_4;
                        wrap = false;
                    } else if (admin.length() > 11) {
                        // ??11???6??
                        adminF = min_6;
                    }
                }
                Font medicineF; // ??
                // ********** @009  **********

                // ??? ClaimItem iterate
                for (cnt = 0; cnt < items.length; cnt++) {
                    //System.out.println("row size:" + ptbl.getRows().size());

                    // ??
                    if (!genericIsOk) {
                        blank = new PdfPCell(new Paragraph("", min_8));
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setBorderWidthRight(LINE_WIDTH_1);
                        ptbl.addCell(blank);
                        genericIsOk = true;

                    } else {
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setBorderWidthRight(LINE_WIDTH_1);
                        ptbl.addCell(blank);
                    }

                    if (ptbl.getRows().size() > 13) {
                        // ?13???????????
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setColspan(4);
                        ptbl.addCell(blank);
                        pcell = new PdfPCell(new Paragraph("???", min_8));
                        pcell.setBorderWidth(LINE_WIDTH_0);
                        pcell.setColspan(5);
                        ptbl.addCell(pcell);
                        preTblList.add(ptbl);
                        ptbl = new PdfPTable(9);
                        ptbl.setWidthPercentage(100f);
                        ptbl.setWidths(widthsP);
                        ptbl.getDefaultCell().setPadding(0f);
                        // ??
                        ptbl.addCell(notes);
                        ptbl.addCell(bracket);
                        ptbl.addCell(notesDetail);
                        ptbl.addCell(bracketC);
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setBorderWidthRight(LINE_WIDTH_1);
                        ptbl.addCell(blank);
                    }

                    if (cnt > 0) {
                        // ?1?????????
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        ptbl.addCell(blank);
                    } else {
                        // ?1??????
                        numCell = new PdfPCell(new Paragraph(num++ + ")", min_8));
                        numCell.setBorderWidth(LINE_WIDTH_0);
                        setAlignRight(numCell);
                        ptbl.addCell(numCell);
                        // @004 2010/02/26  
                        // ?1?????? false ??
                        if (!ClaimConst.COMMENT_CODE_0.equals(items[cnt].getCode())) {
                            clearFlg = false;
                        }
                        // @004 2010/02/26  
                    }

                    // ********** @009  **********
                    amount = items[cnt].getNumber();
                    //                        System.out.println("??" + items[cnt].getName());
                    //                        System.out.println("?" + amount);
                    //medicine = "";
                    medicine = items[cnt].getName();
                    //                        System.out.println("????" + medicine.length());
                    if (medicine.length() > 19) {
                        // ????19???7??
                        medicineF = min_7;
                    } else {
                        // ????19???8???
                        medicineF = min_8;
                    }
                    // ********** @009  **********

                    if ((ClaimConst.SUBCLASS_CODE_ID.equals(items[cnt].getClassCodeSystem()))
                            && ((String.valueOf(ClaimConst.YAKUZAI).equals(items[cnt].getClassCode()))
                                    || (String.valueOf(ClaimConst.ZAIRYO).equals(items[cnt].getClassCode())))) {

                        pcell = new PdfPCell(new Paragraph(convertNVL(items[cnt].getName()), medicineF)); // ?? ??? ????
                        pcell.setBorderWidth(LINE_WIDTH_0);
                        ptbl.addCell(pcell);
                        amountCell = new PdfPCell(new Paragraph(convertNVL(amount), min_8)); // ?
                        setAlignRight(amountCell);
                        amountCell.setBorderWidth(LINE_WIDTH_0);
                        ptbl.addCell(amountCell);

                        if (!(String.valueOf(ClaimConst.ZAIRYO).equals(items[cnt].getClassCode()))) {
                            // ?????
                            pcell = new PdfPCell(new Paragraph(convertNVL(items[cnt].getUnit()), min_8)); // ??
                            pcell.setBorderWidth(LINE_WIDTH_0);
                            ptbl.addCell(pcell);
                            // ********** @009  **********
                            pcell = new PdfPCell(new Paragraph(admin, adminF)); // 
                            pcell.setBorderWidth(LINE_WIDTH_0);
                            pcell.setNoWrap(wrap);
                            ptbl.addCell(pcell);
                        } else {
                            blank = new PdfPCell();
                            blank.setColspan(2);
                            blank.setBorderWidth(LINE_WIDTH_0);
                            ptbl.addCell(blank);
                        }

                        if (ClaimConst.RECEIPT_CODE_GAIYO.equals(classCode)) {
                            pcell = new PdfPCell(new Paragraph("", min_8));
                            pcell.setBorderWidth(LINE_WIDTH_0);
                            pcell.setColspan(3);
                            ptbl.addCell(pcell);
                            sum = Double.parseDouble(amount) * Double.parseDouble(number);
                            DecimalFormat f = new DecimalFormat("####0.###");
                            //                                System.out.println("??" + sum);
                            amountCell.getPhrase().clear();
                            amountCell.getPhrase().add(new Paragraph(String.valueOf(f.format(sum)), min_8)); // ?
                        } else {
                            // 
                            if ((number != null) && !("".equals(number))) {
                                pcell = new PdfPCell(new Paragraph("(", min_8));
                                pcell.setBorderWidth(LINE_WIDTH_0);
                                ptbl.addCell(pcell);
                                pcell = new PdfPCell(new Paragraph(number, min_8));
                                pcell.setBorderWidth(LINE_WIDTH_0);
                                setAlignRight(pcell);
                                ptbl.addCell(pcell);

                                //minagawa^          
                                if (classCode.startsWith("22")) {
                                    // 
                                    pcell = new PdfPCell(new Paragraph(")", min_8));
                                } else if (classCode.startsWith("21")) {
                                    // 
                                    pcell = new PdfPCell(new Paragraph(")", min_8));
                                    // 
                                } else if (classCode.startsWith("23")) {
                                    pcell = new PdfPCell(new Paragraph("", min_8));
                                }
                                //minagawa$     
                                pcell.setBorderWidth(LINE_WIDTH_0);
                                setAlignRight(pcell);
                                ptbl.addCell(pcell);
                            } else {
                                blank = new PdfPCell();
                                blank.setBorderWidth(LINE_WIDTH_0);
                                blank.setColspan(3);
                                ptbl.addCell(blank);
                            }
                        }
                        // ********** @009  **********
                    } else {
                        pcell = new PdfPCell(new Paragraph(convertNVL(items[cnt].getName()), min_8));
                        pcell.setBorderWidth(LINE_WIDTH_0);
                        pcell.setColspan(7);
                        ptbl.addCell(pcell);
                    }
                }
                // @004 2010/02/26  
                // ?? true ????
                if (clearFlg && (admin == null)) {
                    numCell.getPhrase().clear();
                    num--;
                }
                // @004 2010/02/26  

            } else {
                String stampName = prescription.getOrderName();
                System.err.println("??" + stampName
                        + "????????????");
                StringBuilder b = new StringBuilder();
                b.append("??").append(stampName)
                        .append("?????????").append(System.getProperty(STR_LF));
                System.err.println(b.toString());
            }

            if (!ite.hasNext()) {
                blank = new PdfPCell();
                blank.setBorderWidth(LINE_WIDTH_0);
                ptbl.addCell(blank);
                pcell = new PdfPCell(new Paragraph("", min_8));
                pcell.setBorderWidth(LINE_WIDTH_0);
                pcell.setBorderWidthLeft(LINE_WIDTH_1);
                pcell.setPaddingLeft(30f);
                pcell.setColspan(8);
                ptbl.addCell(pcell);
                preTblList.add(ptbl);
            }
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
    return preTblList;
}

From source file:open.dolphin.msg.ServerPrescriptionPDFMaker.java

/**
 * ??//from   w w  w. j a  va  2  s.com
 */
public String output() {
    BufferedOutputStream bos;
    PdfWriter pw = null;
    Document document = null;

    try {
        Date dateNow = new Date();

        // ID
        String patientId = pkg.getPatientId();

        // ???
        String name = pkg.getPatientName();
        name = name.replaceAll(" ", "");
        name = name.replaceAll("", "");

        String iNum; // ??
        String piNum = null; // ?
        String rNum = null; // ??

        String piNum2 = null; // ?
        String rNum2 = null; // ??

        String div = ""; // ?
        String payRatio = ""; // ?

        String mNum = ""; // ???

        char[] iNumC = new char[8]; // ???
        char[] piNumC = new char[8]; // ??
        char[] rNumC = new char[7]; // ??
        char[] piNumC2 = new char[8]; // ??
        char[] rNumC2 = new char[7]; // ??
        DecimalFormat df = new DecimalFormat("#0.#"); // ??
        String paymentRatio = ""; // ?
        String paymentRatio2 = ""; // ?

        if (pkg.getApplyedInsurance().getInsuranceNumber() != null) {

            // ??
            iNum = pkg.getApplyedInsurance().getInsuranceNumber();

            // ? null ??
            if (iNum.toLowerCase().startsWith("z") || iNum.equals("9999")) {
                iNum = null;
            }

            // 
            if (pkg.getApplyedInsurance().getPVTPublicInsuranceItem() != null) {
                PVTPublicInsuranceItemModel[] pubItems = pkg.getApplyedInsurance().getPVTPublicInsuranceItem();
                for (int i = 0; i < pubItems.length; i++) {
                    PVTPublicInsuranceItemModel pm = pubItems[i];
                    if (i == 0) {
                        // ?
                        piNum = pm.getProvider();
                        piNum = ("mikinyu".equals(piNum)) ? "" : piNum;

                        // ??
                        rNum = pm.getRecipient();
                        rNum = ("mikinyu".equals(rNum)) ? "" : rNum;

                        // ???
                        paymentRatio = pm.getPaymentRatio();
                    } else if (i == 1) {
                        piNum2 = pm.getProvider();
                        piNum2 = ("mikinyu".equals(piNum2)) ? "" : piNum2;

                        rNum2 = pm.getRecipient();
                        rNum2 = ("mikinyu".equals(rNum2)) ? "" : rNum2;

                        paymentRatio2 = pm.getPaymentRatio();
                        break;
                    }
                }
            }

            // ? ?? ?
            StringBuilder sb = new StringBuilder();

            // ? ?
            if (pkg.getApplyedInsurance().getClientGroup() != null
                    && !pkg.getApplyedInsurance().getClientGroup().equals("??")) {
                sb.append(pkg.getApplyedInsurance().getClientGroup()).append("");
            }
            // ??
            if (pkg.getApplyedInsurance().getClientNumber() != null
                    && !pkg.getApplyedInsurance().getClientNumber().equals("??")) {
                sb.append(pkg.getApplyedInsurance().getClientNumber());
            }
            mNum = sb.length() > 0 ? sb.toString() : "";

            // 
            if ("?".equals(pkg.getApplyedInsurance().getInsuranceClass())) {
                div = "";
                payRatio = paymentRatio;
            } else {
                // ?
                div = "true".equals(pkg.getApplyedInsurance().getFamilyClass()) ? "?"
                        : "";
                payRatio = pkg.getApplyedInsurance().getPayOutRatio();
            }
            if (payRatio != null && !("".equals(payRatio))) {
                payRatio = df.format(Double.valueOf(payRatio) * 10);
            }

            if (DEBUG) {
                System.err.println("iNum=" + iNum);
                System.err.println("piNum=" + piNum);
                System.err.println("rNum=" + rNum);
                System.err.println("piNum2=" + piNum2);
                System.err.println("rNum2=" + rNum2);
                System.err.println("mNum=" + mNum);
                System.err.println("?=" + div);
                System.err.println("=" + payRatio);
            }

            // ???
            iNumC = partitionPadRL(iNum, 8, "R"); // ??
            piNumC = partitionPadRL(piNum, 8, "L"); // ?
            rNumC = partitionPadRL(rNum, 7, "L"); // ??
            piNumC2 = partitionPadRL(piNum2, 8, "L"); // ?2
            rNumC2 = partitionPadRL(rNum2, 7, "L"); // ??2
        }
        /*****  *****/

        document = new Document(PageSize.A5, 10, 10, 2, 2);

        // ?PDF?welcome-content
        if (getDocumentDir() == null) {
            StringBuilder sb = new StringBuilder();
            sb.append(System.getProperty("jboss.home.dir"));
            sb.append(File.separator);
            sb.append(DIR_NAME);
            setDocumentDir(sb.toString());
        }
        File dir = new File(getDocumentDir());
        dir.mkdir();

        // ??(ID_.pdf)
        StringBuilder sb = new StringBuilder();
        sb.append(patientId).append("_");
        sb.append(new SimpleDateFormat("yyyyMMddHHmmss").format(dateNow));
        sb.append(FILE_EXTENTION);
        setFileName(sb.toString());

        sb = new StringBuilder();
        sb.append(getDocumentDir());
        sb.append(File.separator);
        sb.append(getFileName());
        pathToPDF = sb.toString();

        //minagawa^ ???water mark?????????? byte[]???            
        ByteArrayOutputStream byteo = new ByteArrayOutputStream();
        bos = new BufferedOutputStream(byteo);
        //minagawa$             
        pw = PdfWriter.getInstance(document, bos);

        // font setting
        bfm = BaseFont.createFont(FONT_HEISEI_MIN3, CODE_UNIJIS_H, BaseFont.NOT_EMBEDDED);
        bfg = BaseFont.createFont(FONT_HEISEI_KAKU5, CODE_UNIJIS_H, BaseFont.NOT_EMBEDDED);
        min_6 = new Font(bfm, 6);
        min_7 = new Font(bfm, 7);
        min_8 = new Font(bfm, 8);
        min_9 = new Font(bfm, 9);
        min_10 = new Font(bfm, 10);
        min_12 = new Font(bfm, 12);
        min_14 = new Font(bfm, 14);
        min_15 = new Font(bfm, 15);
        min_4 = new Font(bfm, 4); // @009

        // 
        document.open();
        document.addAuthor(pkg.getPhysicianName());
        document.addTitle(PROPERTY_TITLE);
        document.addSubject(PROPERTY_SUB_TITLE);

        // ???
        List<PdfPTable> list = createPrescriptionTbl2();
        Iterator<PdfPTable> ite = list.iterator();

        // ?
        int pageNo = 0;
        int totalPageNo = list.size();

        // ?????????
        do {
            PdfPTable ptbl = new PdfPTable(1);
            ptbl.setWidthPercentage(100f);
            ptbl.getDefaultCell().setPadding(0f);
            PdfPCell pcell = new PdfPCell(new Paragraph(REPORT_TITLE, min_15));
            pcell.setBorder(Table.NO_BORDER);
            setAlignCenter(pcell);
            ptbl.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(REPORT_SUB_TITLE, min_7));
            pcell.setBorder(Table.NO_BORDER);
            setAlignCenter(pcell);
            ptbl.addCell(pcell);
            document.add(ptbl);

            ptbl = new PdfPTable(3);
            ptbl.setWidthPercentage(100f);
            ptbl.getDefaultCell().setPadding(0f);
            ptbl.getDefaultCell().setBorder(Table.NO_BORDER);
            float[] widths = { 43.5f, 2f, 54.5f };
            ptbl.setWidths(widths);
            // ?
            pcell = new PdfPCell(new Paragraph(patientId, min_9));
            pcell.setBorder(Table.NO_BORDER);
            pcell.setColspan(10);
            ptbl.addCell(pcell);

            PdfPTable ptblL = new PdfPTable(9);
            ptblL.setSpacingBefore(10f);
            ptblL.setWidthPercentage(100f);
            float[] widthsL = { 33, 8, 8, 8, 8, 8, 8, 8, 8 };
            ptblL.setWidths(widthsL);
            ptblL.getDefaultCell().setPadding(0f);
            pcell = new PdfPCell(new Paragraph("?", min_7));
            pcell.setMinimumHeight(CELL_HIGHT_0);
            setAlignJustifiedAll(pcell);
            setAlignMiddle(pcell);
            pcell.setBorderWidth(LINE_WIDTH_1);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[0]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[1]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[2]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[3]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[4]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_2);
            pcell.setBorderWidthRight(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[5]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthTop(LINE_WIDTH_2);
            pcell.setBorderWidthBottom(LINE_WIDTH_2);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[6]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_2);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setBorderWidthLeft(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[7]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph("???", min_7));
            pcell.setPaddingTop(0.3f);
            setAlignJustifiedAll(pcell);
            pcell.setBorderWidth(LINE_WIDTH_1);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[0]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[1]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[2]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[3]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[4]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[5]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[6]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthLeft(LINE_WIDTH_3);
            pcell.setPadding(0f);
            setAlignCenterMiddle(pcell);
            ptblL.addCell(pcell);
            pcell = new PdfPCell();
            pcell.setBorderWidth(LINE_WIDTH_0);
            ptblL.addCell(pcell);

            PdfPTable patientTbl = new PdfPTable(2);
            patientTbl.setWidthPercentage(100f);
            float[] widthsPa = { 7.8f, 92.2f };
            patientTbl.setWidths(widthsPa);
            patientTbl.getDefaultCell().setPadding(0f);
            patientTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell pcellP = new PdfPCell(new Paragraph("", min_7));
            pcellP.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pcellP);
            patientTbl.addCell(pcellP);
            // 
            PdfPTable desc = new PdfPTable(5);
            desc.setWidthPercentage(100f);
            float[] widthsD = { 28.5f, 41.5f, 7, 16, 7 };
            desc.setWidths(widthsD);
            // ???(??)
            PdfPCell patientInfo = new PdfPCell(new Paragraph("???", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(patientInfo);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            PdfPTable nameTbl = new PdfPTable(1);
            nameTbl.setWidthPercentage(100f);
            nameTbl.setSpacingAfter(3f);
            PdfPCell nameCell = new PdfPCell(new Paragraph(pkg.getPatientKana(), min_7));
            nameCell.setBorderWidth(LINE_WIDTH_0);
            nameTbl.addCell(nameCell);
            nameCell = new PdfPCell(new Paragraph(pkg.getPatientName(), min_9));
            nameCell.setBorderWidth(LINE_WIDTH_0);
            nameTbl.addCell(nameCell);
            patientInfo = new PdfPCell(nameTbl);
            patientInfo.setColspan(4);
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            desc.addCell(patientInfo);
            // 
            patientInfo = new PdfPCell(new Paragraph("", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(patientInfo);
            desc.addCell(patientInfo);
            String birthDay = ModelUtils.convertToGengo(pkg.getPatientBirthday());
            patientInfo = new PdfPCell(new Paragraph(birthDay, min_9));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            patientInfo.setColspan(3);
            patientInfo.setPaddingTop(0.5f);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph(pkg.getPatientSex(), min_8));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(patientInfo);
            desc.addCell(patientInfo);
            // 
            patientInfo = new PdfPCell(new Paragraph("", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(patientInfo);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph(div, min_8));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph("?", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_1);
            setAlignMiddle(patientInfo);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph(payRatio, min_9));
            setAlignRightMiddle(patientInfo);
            patientInfo.setBorderWidth(LINE_WIDTH_0);
            desc.addCell(patientInfo);
            patientInfo = new PdfPCell(new Paragraph("", min_7));
            patientInfo.setBorderWidth(LINE_WIDTH_0);
            patientInfo.setVerticalAlignment(Element.ALIGN_BOTTOM);
            setAlignRight(patientInfo);
            desc.addCell(patientInfo);
            patientTbl.addCell(desc);
            pcell = new PdfPCell(patientTbl);
            pcell.setColspan(9);
            pcell.setBorderWidth(LINE_WIDTH_1);
            ptblL.addCell(pcell);
            // 
            pcell = new PdfPCell(new Paragraph("", min_7));
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(pcell);
            setAlignMiddle(pcell);
            ptblL.addCell(pcell);
            // @003 2010/02/15 ???????????????
            String issueDate = ModelUtils.convertToGengo(
                    ModelUtils.getDateAsFormatString(pkg.getIssuanceDate(), IInfoModel.DATE_WITHOUT_TIME));
            pcell = new PdfPCell(new Paragraph(issueDate, min_9));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPaddingTop(0.5f);
            setAlignMiddle(pcell);
            pcell.setColspan(8);
            ptblL.addCell(pcell);

            ptbl.addCell(ptblL);
            ptbl.addCell("");

            PdfPTable ptblR = new PdfPTable(10);
            ptblR.setSpacingBefore(10f);
            ptblR.setWidthPercentage(100f);
            float[] widthsR = { 30, 7, 7, 7, 7, 7, 7, 7, 7, 14 };
            ptblR.setWidths(widthsR);
            pcell = new PdfPCell(new Paragraph("??", min_7));
            pcell.setMinimumHeight(CELL_HIGHT_0);
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(pcell);
            setAlignMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[0]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[1]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_2);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[2]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[3]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthRight(LINE_WIDTH_2);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[4]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthTop(LINE_WIDTH_2);
            pcell.setBorderWidthBottom(LINE_WIDTH_2);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[5]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setBorderWidthTop(LINE_WIDTH_2);
            pcell.setBorderWidthBottom(LINE_WIDTH_2);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[6]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_2);
            pcell.setBorderWidthLeft(LINE_WIDTH_1);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[7]), min_14));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setPadding(CELL_PADDING_0);
            setAlignCenterMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell();
            pcell.setBorderWidth(LINE_WIDTH_0);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(
                    new Paragraph("?????", min_7));
            pcell.setPaddingTop(0.3f);
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(pcell);
            setAlignMiddle(pcell);
            ptblR.addCell(pcell);
            pcell = new PdfPCell(new Paragraph(mNum, min_9));
            pcell.setBorderWidth(LINE_WIDTH_1);
            pcell.setColspan(9);
            setAlignMiddle(pcell);
            ptblR.addCell(pcell);

            //FacilityModel facility = getPhysician().getFacilityModel();
            String facilityName = pkg.getInstitutionName(); // ??
            //String facilityZipCode = facility.getZipCode(); // ?
            String facilityAddress = pkg.getInstitutionAddress(); // ?
            String facilityTelNo = pkg.getInstitutionTelephone(); // ?
            //minagawa^ ?????                 
            String drName = pkg.getPhysicianName();
            //minagawa$                    
            if (pkg.isChkUseDrugInfo()) {
                // ??
                drName = pkg.getPhysicianName();
            }
            // ********** @008 2010/06/18  **********
            // 20104?
            String prefNo = "  "; // ?? 2?
            String grade = " "; // ? 1?
            String institution = "       "; //  7?

            if ((pkg.getInstitutionNumber() != null) && (pkg.getInstitutionNumber().length() > 9)) {
                prefNo = pkg.getInstitutionNumber().substring(0, 2);
                grade = pkg.getInstitutionNumber().substring(2, 3);
                institution = pkg.getInstitutionNumber().substring(3, 10);
            }
            // ********** @008 2010/06/18  **********

            PdfPTable medOrgTbl = new PdfPTable(3);
            medOrgTbl.setWidthPercentage(100f);
            float[] widthsM = { 30, 55, 15 };
            medOrgTbl.setWidths(widthsM);
            PdfPCell medOrgCell = new PdfPCell(new Paragraph("??\n", min_7));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignJustifiedAll(medOrgCell);
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph(facilityAddress, min_8));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            medOrgCell.setColspan(2);
            setAlignMiddle(medOrgCell);
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph("????", min_7));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignJustifiedAll(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgCell.setPaddingBottom(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph(facilityName, min_8));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            medOrgCell.setColspan(2);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgCell.setPaddingBottom(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell();
            medOrgCell.setBorder(Table.NO_BORDER);
            medOrgCell.setColspan(3);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgCell.setPaddingBottom(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph("?", min_7));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignJustifiedAll(medOrgCell);
            setAlignMiddle(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph(facilityTelNo, min_9));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignMiddle(medOrgCell);
            medOrgCell.setColspan(2);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph("????", min_7));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignJustifiedAll(medOrgCell);
            setAlignMiddle(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph(drName, min_10));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignMiddle(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            medOrgCell = new PdfPCell(new Paragraph("?", min_8));
            medOrgCell.setBorderWidth(LINE_WIDTH_0);
            setAlignMiddle(medOrgCell);
            medOrgCell.setPaddingTop(CELL_PADDING_0); // @008
            medOrgTbl.addCell(medOrgCell);
            pcell = new PdfPCell(medOrgTbl);
            pcell.setBorder(Table.NO_BORDER);
            pcell.setColspan(10);
            pcell.setPaddingBottom(CELL_PADDING_1);
            ptblR.addCell(pcell);
            // ********** @008 2010/06/18  **********
            // 20104? 
            PdfPTable medCodeTbl = new PdfPTable(13);
            medCodeTbl.setWidthPercentage(100f);
            float[] widthsCode = { 17, 8, 8, 15, 8, 17, 8, 8, 8, 8, 8, 8, 8 };
            medCodeTbl.setWidths(widthsCode);
            // ??
            PdfPCell medCodeCell = new PdfPCell(new Paragraph("?\n?", min_6));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(prefNo.charAt(0)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(prefNo.charAt(1)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph("\n?", min_6));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(grade.charAt(0)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph("", min_6));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(0)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(1)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(2)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(3)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(4)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(5)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(6)), min_14));
            medCodeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(medCodeCell);
            medCodeCell.setPaddingTop(CELL_PADDING_0);
            medCodeTbl.addCell(medCodeCell);
            pcell = new PdfPCell(medCodeTbl);
            pcell.setBorder(Table.NO_BORDER);
            pcell.setColspan(10);
            pcell.setPaddingBottom(CELL_PADDING_1);
            ptblR.addCell(pcell);
            // ********** @008 2010/06/18  **********

            ptbl.addCell(ptblR);

            // ??
            PdfPTable termTbl = new PdfPTable(3);
            termTbl.setWidthPercentage(100f);
            float[] widthsT = { 14.8f, 26, 59.2f };
            termTbl.setWidths(widthsT);
            termTbl.getDefaultCell().setPadding(0f);
            PdfPCell termCell = new PdfPCell(new Paragraph("??\n", min_7));
            termCell.setBorderWidth(LINE_WIDTH_1);
            termCell.setPaddingTop(0.3f);
            setAlignJustifiedAll(termCell);
            termTbl.addCell(termCell);
            // ********* @009 2010/07/01  *********
            String periodDate = "?";
            if (pkg.getPeriod() != null) {
                periodDate = ModelUtils.convertToGengo(
                        ModelUtils.getDateAsFormatString(pkg.getPeriod(), IInfoModel.DATE_WITHOUT_TIME));
            }
            termCell = new PdfPCell(new Paragraph(periodDate, min_8));
            // ********* @009 2010/07/01  *********
            termCell.setBorderWidth(LINE_WIDTH_1);
            termCell.setBorderWidthRight(LINE_WIDTH_0);
            setAlignMiddle(termCell);
            termTbl.addCell(termCell);
            termCell = new PdfPCell(new Paragraph(
                    "???????????????????",
                    min_6));
            termCell.setBorderWidth(LINE_WIDTH_1);
            termCell.setBorderWidthLeft(LINE_WIDTH_0);
            setAlignMiddle(termCell);
            termTbl.addCell(termCell);
            pcell = new PdfPCell(termTbl);
            pcell.setBorder(Table.NO_BORDER);
            pcell.setColspan(3);
            ptbl.addCell(pcell);

            document.add(ptbl);

            // 
            ptbl = new PdfPTable(2);
            ptbl.setWidthPercentage(100f);
            ptbl.getDefaultCell().setPadding(0f);
            ptbl.getDefaultCell().setBorder(Table.NO_BORDER);
            float[] widthsPre = { 3.5f, 96.5f };
            ptbl.setWidths(widthsPre);
            pcell = new PdfPCell(
                    new Paragraph("", min_7));
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pcell);
            ptbl.addCell(pcell);
            // @005 2010/02/26  
            // ??
            // 
            PdfPTable outLineTbl = new PdfPTable(1);
            PdfPCell outLineCell; // ?
            // @005 2010/02/26  
            // 
            PdfPTable prescriptionTbl; // 
            if (ite.hasNext()) {
                prescriptionTbl = ite.next();
            } else {
                prescriptionTbl = new PdfPTable(1);
            }
            // @005 2010/02/26  
            // ??
            outLineCell = new PdfPCell(prescriptionTbl);
            outLineCell.setFixedHeight(200f);
            outLineCell.setBorderWidth(LINE_WIDTH_0);
            outLineTbl.addCell(outLineCell);
            if (totalPageNo > 1) {
                pageNo++;
                outLineCell = new PdfPCell(
                        new Paragraph((String.valueOf(pageNo) + "?" + String.valueOf(totalPageNo)), min_10));
                setAlignRight(outLineCell);
                outLineCell.setFixedHeight(12f); // @010
                outLineCell.setBorderWidth(LINE_WIDTH_1); // @010
                outLineTbl.addCell(outLineCell);
            }
            // @005 2010/02/26  
            PdfPCell prescriptionCell = new PdfPCell(outLineTbl);
            prescriptionCell.setFixedHeight(215f);
            prescriptionCell.setBorderWidth(LINE_WIDTH_1);
            ptbl.addCell(prescriptionCell);

            // 
            pcell = new PdfPCell(new Paragraph("", min_7));
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pcell);
            ptbl.addCell(pcell);
            // 
            PdfPTable noteTbl = new PdfPTable(5); // @010
            noteTbl.setWidthPercentage(100f);
            float[] widthsN = { 11, 4, 34, 4, 47 }; // @010
            noteTbl.setWidths(widthsN);
            noteTbl.getDefaultCell().setPadding(0f);
            noteTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            String address = (pkg.getPatientAddress() == null) ? "" : pkg.getPatientAddress();
            String patientName = pkg.getPatientName();
            String addressName = "?" + address + "\n???" + patientName;
            String useDrugInfo = "??" + pkg.getDrugLicenseNumber() + "("
                    + pkg.getPhysicianName() + ")";

            StringBuilder postInfo = new StringBuilder();
            // 
            if (pkg.isChkHomeMedical()) {
                postInfo.append(NOTES_HOME_MEDICAL + "\n");
            }
            if (pkg.isChkPatientInfo()) {
                // ?????
                postInfo.append(addressName);
            }
            if (postInfo.length() > 0) {
                // 
                postInfo.append("\n");
            }
            if (pkg.isChkUseDrugInfo()) {
                // ??
                postInfo.append(useDrugInfo);
            }
            // @010 20124 -->
            PdfPCell noteCell = new PdfPCell(new Paragraph("???", min_7));
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteCell.setBorderWidthBottom(LINE_WIDTH_1);
            noteCell.setMinimumHeight(CELL_HIGHT_2);
            setAlignTop(noteCell);
            noteTbl.addCell(noteCell);

            noteCell = new PdfPCell(new Paragraph("", min_15));//min_15
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteCell.setBorderWidthBottom(LINE_WIDTH_1);
            noteCell.setPadding(0f);
            setAlignRight(noteCell);
            noteTbl.addCell(noteCell);

            noteCell = new PdfPCell(new Paragraph(
                    "??????????\n?????????????",
                    min_6));
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteCell.setBorderWidthBottom(LINE_WIDTH_1);
            noteTbl.addCell(noteCell);

            noteCell = new PdfPCell(new Paragraph("", min_15));//min_15
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteCell.setBorderWidthBottom(LINE_WIDTH_1);
            noteCell.setBorderWidthRight(LINE_WIDTH_1);
            noteCell.setPadding(0f);
            setAlignLeft(noteCell);
            noteTbl.addCell(noteCell);

            //minagawa^ ????  47                   
            noteCell = new PdfPCell();
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteTbl.addCell(noteCell);
            //minagawa                    
            noteCell = new PdfPCell(new Paragraph(postInfo.toString(), min_7)); // ????????
            noteCell.setColspan(widthsN.length);
            noteCell.setMinimumHeight(40f);
            noteCell.setBorderWidth(LINE_WIDTH_0);
            noteTbl.addCell(noteCell);
            // <-- 20124 @010

            pcell = new PdfPCell(noteTbl);
            pcell.setBorderWidth(LINE_WIDTH_1);
            ptbl.addCell(pcell);

            document.add(ptbl);

            // ??
            ptbl = new PdfPTable(2);
            ptbl.setWidthPercentage(100f);
            float[] widthsOther = { 58, 42 };
            ptbl.setWidths(widthsOther);
            ptbl.getDefaultCell().setPadding(0f);
            ptbl.getDefaultCell().setBorder(Table.NO_BORDER);
            // 
            ptblL = new PdfPTable(3);
            ptblL.setWidthPercentage(100f);
            float[] widthsPh = { 28, 65, 7 };
            ptblL.setWidths(widthsPh);
            ptblL.getDefaultCell().setPadding(0f);
            ptblL.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell pcellL = new PdfPCell(new Paragraph("", min_7));
            pcellL.setMinimumHeight(CELL_HIGHT_0);
            pcellL.setBorderWidth(LINE_WIDTH_1);
            setAlignJustifiedAll(pcellL);
            setAlignMiddle(pcellL);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell(new Paragraph("?", min_8));
            pcellL.setBorderWidth(LINE_WIDTH_1);
            setAlignMiddle(pcellL);
            pcellL.setColspan(2);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell(new Paragraph("??\n??\n??", min_7));
            pcellL.setPaddingTop(0.2f);
            pcellL.setBorderWidth(LINE_WIDTH_1);
            pcellL.setBorderWidthBottom(LINE_WIDTH_0);
            setAlignJustifiedAll(pcellL);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell();
            pcellL.setBorderWidth(LINE_WIDTH_0);
            pcellL.setBorderWidthRight(LINE_WIDTH_1);
            pcellL.setColspan(2);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell(new Paragraph("?\n???", min_7));
            pcellL.setPaddingTop(0.2f);
            pcellL.setBorderWidth(LINE_WIDTH_1);
            pcellL.setBorderWidthTop(LINE_WIDTH_0);
            setAlignJustifiedAll(pcellL);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell();
            pcellL.setBorderWidth(LINE_WIDTH_0);
            pcellL.setBorderWidthBottom(LINE_WIDTH_1);
            ptblL.addCell(pcellL);
            pcellL = new PdfPCell(new Paragraph("?", min_8));
            pcellL.setBorderWidth(LINE_WIDTH_1);
            pcellL.setBorderWidthTop(LINE_WIDTH_0);
            pcellL.setBorderWidthLeft(LINE_WIDTH_0);
            setAlignJustifiedAll(pcellL);
            setAlignMiddle(pcellL);
            ptblL.addCell(pcellL);
            ptbl.addCell(ptblL);

            ptblR = new PdfPTable(9);
            ptblR.setWidthPercentage(100f);
            float[] widthsPu = { 33, 8, 8, 8, 8, 8, 8, 8, 8 };
            ptblR.setWidths(widthsPu);
            ptblR.getDefaultCell().setPadding(0f);
            PdfPCell pcellR = new PdfPCell(new Paragraph("?", min_7));
            pcellR.setMinimumHeight(CELL_HIGHT_0);
            setAlignJustifiedAll(pcellR);
            setAlignMiddle(pcellR);
            pcellR.setBorderWidth(LINE_WIDTH_1);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[0]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[1]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[2]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[3]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[4]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_2);
            pcellR.setBorderWidthRight(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[5]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthTop(LINE_WIDTH_2);
            pcellR.setBorderWidthBottom(LINE_WIDTH_2);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[6]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_2);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setBorderWidthLeft(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[7]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph("???", min_7));
            pcellR.setPaddingTop(0.3f);
            setAlignJustifiedAll(pcellR);
            pcellR.setBorderWidth(LINE_WIDTH_1);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[0]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[1]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[2]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[3]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[4]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[5]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthRight(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[6]), min_14)); // @006
            pcellR.setBorderWidth(LINE_WIDTH_1);
            pcellR.setBorderWidthLeft(LINE_WIDTH_3);
            pcellR.setPadding(0f);
            setAlignCenterMiddle(pcellR);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell();
            pcellR.setBorderWidth(LINE_WIDTH_0);
            ptblR.addCell(pcellR);
            pcellR = new PdfPCell();
            pcellR.setBorderWidth(LINE_WIDTH_0);
            pcellR.setColspan(9);
            ptblR.addCell(pcellR);

            ptbl.addCell(ptblR);

            document.add(ptbl);

            ptbl = new PdfPTable(2);
            ptbl.setWidthPercentage(100f);
            float[] widthsMed = { 3.5f, 96.5f };
            ptbl.setWidths(widthsMed);
            ptbl.setSpacingBefore(3f);
            ptbl.getDefaultCell().setPadding(0f);
            ptbl.getDefaultCell().setBorder(Table.NO_BORDER);
            pcell = new PdfPCell(new Paragraph("????", min_7));
            pcell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(pcell);
            ptbl.addCell(pcell);

            ptblR = new PdfPTable(3);
            ptblR.setWidthPercentage(100f);
            float[] widthsPm = { 60, 20, 20 };
            ptblR.setWidths(widthsPm);
            ptblR.getDefaultCell().setPadding(0f);
            ptblR.getDefaultCell().setBorder(Table.NO_BORDER);
            // ????????
            PdfPTable pointTbl = new PdfPTable(7);
            pointTbl.setWidthPercentage(100f);
            float[] widthsPo = { 7, 15.5f, 15.5f, 15.5f, 15.5f, 15.5f, 15.5f };
            pointTbl.setWidths(widthsPo);
            pointTbl.getDefaultCell().setPadding(0f);
            pointTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("?", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("?", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            pointCell = new PdfPCell(new Paragraph("", min_7));
            pointCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(pointCell);
            pointTbl.addCell(pointCell);
            // ?
            PdfPCell blankCell = new PdfPCell();
            blankCell.setBorderWidth(LINE_WIDTH_1);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            pointTbl.addCell(blankCell);
            ptblR.addCell(pointTbl);
            // ?
            PdfPTable feeTbl = new PdfPTable(2);
            feeTbl.setWidthPercentage(100f);
            float[] widthsF = { 50, 50 };
            feeTbl.setWidths(widthsF);
            feeTbl.getDefaultCell().setPadding(0f);
            feeTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell feeCell = new PdfPCell(new Paragraph("    ", min_7));
            feeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCell);
            feeTbl.addCell(feeCell);
            feeCell = new PdfPCell(new Paragraph("    ", min_7));
            feeCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCell);
            feeTbl.addCell(feeCell);
            feeCell = new PdfPCell();
            feeCell.setBorderWidth(LINE_WIDTH_1);
            feeCell.setMinimumHeight(CELL_HIGHT_1);
            feeTbl.addCell(feeCell);
            feeTbl.addCell(feeCell);
            // ?etc..
            PdfPTable feeTblSub = new PdfPTable(4);
            feeTblSub.setWidthPercentage(100f);
            float[] widthsSub = { 28, 16, 28, 28 };
            feeTblSub.setWidths(widthsSub);
            feeTblSub.getDefaultCell().setPadding(0f);
            feeTblSub.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell feeCellSub = new PdfPCell(new Paragraph("?", min_7));
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeCellSub = new PdfPCell(new Paragraph("", min_7));
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeCellSub = new PdfPCell(new Paragraph("  ", min_7));
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeCellSub = new PdfPCell(new Paragraph("?  ", min_7));
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            // ?
            feeCellSub = new PdfPCell();
            feeCellSub.setBorderWidth(LINE_WIDTH_1);
            feeCellSub.setMinimumHeight(CELL_HIGHT_1);
            feeTblSub.addCell(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeTblSub.addCell(feeCellSub);
            feeCell = new PdfPCell(feeTblSub);
            feeCell.setBorder(Table.NO_BORDER);
            feeCell.setColspan(2);
            feeTbl.addCell(feeCell);
            // etc..?
            pcellR = new PdfPCell(feeTbl);
            pcellR.setPadding(0f);
            pcellR.setColspan(2);
            pcellR.setBorder(Table.NO_BORDER);
            ptblR.addCell(pcellR);
            // 
            noteTbl = new PdfPTable(2);
            noteTbl.setWidthPercentage(100f);
            float[] widthsNote = { 5.3f, 94.7f };
            noteTbl.setWidths(widthsNote);
            noteTbl.getDefaultCell().setPadding(0f);
            noteTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            noteCell = new PdfPCell(new Paragraph("", min_7));
            noteCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenterMiddle(noteCell);
            noteTbl.addCell(noteCell);
            noteCell = new PdfPCell();
            noteCell.setBorderWidth(LINE_WIDTH_1);
            noteTbl.addCell(noteCell);
            pcell = new PdfPCell(noteTbl);
            pcell.setBorderWidth(LINE_WIDTH_0);
            pcell.setPadding(0f);
            pcell.setColspan(2);
            ptblR.addCell(pcell);
            // ?
            PdfPTable sumTbl = new PdfPTable(1);
            sumTbl.setWidthPercentage(100f);
            sumTbl.getDefaultCell().setPadding(0f);
            sumTbl.getDefaultCell().setBorder(Table.NO_BORDER);
            PdfPCell sumCell = new PdfPCell(new Paragraph("?", min_7));
            sumCell.setBorderWidth(LINE_WIDTH_1);
            setAlignCenter(sumCell);
            sumTbl.addCell(sumCell);
            sumCell = new PdfPCell();
            sumCell.setBorderWidth(LINE_WIDTH_1);
            sumCell.setMinimumHeight(CELL_HIGHT_1);
            sumTbl.addCell(sumCell);
            ptblR.addCell(sumTbl);

            pcell = new PdfPCell(ptblR);
            pcell.setBorderWidth(LINE_WIDTH_0);
            pcell.setPadding(0f);
            ptbl.addCell(pcell);

            document.add(ptbl);
            // 
            if (ite.hasNext()) {
                document.newPage();
            }

        } while (ite.hasNext());

        document.close();
        bos.close();

        // pdf content bytes
        byte[] pdfbytes = byteo.toByteArray();

        // ????? File????
        //if (!ClientContext.is5mTest()) {
        FileOutputStream fout = new FileOutputStream(pathToPDF);
        FileChannel channel = fout.getChannel();
        ByteBuffer bytebuff = ByteBuffer.wrap(pdfbytes);

        while (bytebuff.hasRemaining()) {
            channel.write(bytebuff);
        }
        channel.close();
        //return pathToPDF;
        //}

        //            // ??? water Mark ??
        //            PdfReader pdfReader = new PdfReader(pdfbytes);
        //            PdfStamper pdfStamper = new PdfStamper(pdfReader,new FileOutputStream(pathToPDF));
        //
        //            Image image = Image.getInstance(ClientContext.getImageResource("water-mark.png"));
        //
        //            for(int i=1; i<= pdfReader.getNumberOfPages(); i++){
        //
        //                PdfContentByte content = pdfStamper.getUnderContent(i);
        //
        //                image.scaleAbsolute(PageSize.A5.getWidth(), PageSize.A5.getHeight());
        //                image.setAbsolutePosition(0.0f, 0.0f);
        //                content.addImage(image);
        //            }
        //
        //            pdfStamper.close();

        return getFileName(); //http://ip:8080/filename.pdf

    } catch (DocumentException e) {
        e.printStackTrace(System.err);
        throw new RuntimeException(e.getMessage());

    } catch (IOException e) {
        e.printStackTrace(System.err);
        throw new RuntimeException(e.getMessage());

    } catch (Exception e) {
        e.printStackTrace(System.err);
        throw new RuntimeException(e.getMessage());

    } finally {
        if (document != null && document.isOpen()) {
            document.close();
        }
    }
}

From source file:optika.sql.java

public void eksportoNePdf(String id) {
    Document document = new Document() {
    };/*  w w w . j  ava  2 s .  c  o  m*/
    try {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("receta.pdf"));
        document.open();
        document.setPageSize(PageSize.A3);

        Image img = Image.getInstance("receta.jpg");
        img.setAbsolutePosition(450f, 10f);

        img.scaleToFit(600, 849);

        img.setAlignment(Image.LEFT | Image.ALIGN_BOTTOM | Image.ALIGN_BASELINE);
        img.setAbsolutePosition(0, 0);
        document.add(img);
        String[][] receta = merrReceten("select * from recetat where id=" + parseInt(id) + ";");
        String[][] tabela = merrReceten("select * from tabela where recetat_id=" + parseInt(id) + ";");
        int[] white = new int[tabela.length];
        for (int i = 0; i < tabela.length; i++) {
            white[i] = 0;
            int bosh = 0;
            for (int j = 3; j < tabela[i].length; j++) {
                if (tabela[i][j] == tabela[i][6]) {
                    continue;
                }

                if (!tabela[i][j].isEmpty()) {
                    bosh = 1;
                }

            }

            if (bosh == 0) {
                white[i] = 1;
            }
        }
        Paragraph data = new Paragraph("Data: " + receta[0][7]);
        data.setSpacingBefore(38);
        data.setSpacingAfter(40);
        PdfPTable table = new PdfPTable(7);
        if (white[0] == 0) {
            table.addCell(getCellPadding("" + tabela[0][3], 1));
        } else {
            table.addCell(getCellWhite("_", 1, 30));
        }
        table.addCell(getCellPadding("" + tabela[0][4], 1));
        table.addCell(getCellPadding("" + tabela[0][5], 1));
        table.addCell(getCellPadding("", 1));
        table.addCell(getCellPadding("" + tabela[0][7], 1));
        table.addCell(getCellPadding("" + tabela[0][8], 1));
        table.addCell(getCellPadding("" + tabela[0][9], 1));
        table.setWidthPercentage(105);
        table.setHorizontalAlignment(-100);

        if (white[1] == 0) {
            table.addCell(getCellPadding("" + tabela[1][3], 1));
        } else {

            table.addCell(getCellWhite("_", 1, 36));
        }
        table.addCell(getCellPadding("" + tabela[1][4], 1));
        table.addCell(getCellPadding("" + tabela[1][5], 1));
        table.addCell(getCellPadding("", 1));
        table.addCell(getCellPadding("" + tabela[1][7], 1));
        table.addCell(getCellPadding("" + tabela[1][8], 1));
        table.addCell(getCellPadding("" + tabela[1][9], 1));
        table.setWidthPercentage(105);
        table.setHorizontalAlignment(-100);

        if (white[2] == 0) {
            if (white[1] == 0) {
                table.addCell(getCell("" + tabela[2][3], 1, 30));

            } else {
                table.addCell(getCellWhite("_", 1, 23));
            }
        } else {

            table.addCell(getCellWhite("_", 1, 28));

        }
        table.addCell(getCell("" + tabela[2][4], 1, 0));
        table.addCell(getCell("" + tabela[2][5], 1, 0));
        table.addCell(getCell("", 1, 0));
        table.addCell(getCell("" + tabela[2][7], 1, 0));
        table.addCell(getCell("" + tabela[2][8], 1, 0));
        table.addCell(getCell("" + tabela[2][9], 1, 0));
        table.setWidthPercentage(105);
        table.setSpacingBefore(27);
        table.setHorizontalAlignment(-100);

        String[][] distanca = merrReceten("select * from distanca where recetat_id=" + parseInt(id) + ";");

        PdfPTable largAfer = new PdfPTable(3);

        if (distanca[0][3].isEmpty()) {
            PdfPCell larg = getCellWhite("_", 2, 15);
            largAfer.addCell(larg);
        } else {
            PdfPCell larg = new PdfPCell(new Phrase("" + distanca[0][3]));
            larg.setPadding(0);
            larg.setHorizontalAlignment(2);
            larg.setBorder(PdfPCell.NO_BORDER);
            larg.setPaddingBottom(20);
            largAfer.addCell(larg);
        }
        largAfer.addCell(getCell("", PdfPCell.ALIGN_RIGHT, 25));

        if (distanca[0][8].isEmpty()) {
            largAfer.addCell(getCellWhite("_", PdfPCell.ALIGN_RIGHT, 15));
        } else {
            largAfer.addCell(getCell("" + distanca[0][8], PdfPCell.ALIGN_RIGHT, 25));
        }
        largAfer.setWidthPercentage(75);
        largAfer.setHorizontalAlignment(350);

        PdfPTable od_os = new PdfPTable(5);
        od_os.addCell(getCell("OD= " + distanca[0][4], 0, 195));
        od_os.addCell(getCell("OS= " + distanca[0][5], 2, 195));
        od_os.addCell(getCell("", 0, 0));
        od_os.addCell(getCell("OD= " + distanca[0][9], 0, 0));
        od_os.addCell(getCell("OS= " + distanca[0][10], 1, 0));
        od_os.setWidthPercentage(90);
        od_os.setHorizontalAlignment(150);

        PdfPTable visusi = new PdfPTable(2);
        if (distanca[0][6].isEmpty()) {
            PdfPCell od_pa = getCellWhite("_", 2, 17);
            od_pa.setPaddingRight(45);
            visusi.addCell(od_pa);
        } else {
            PdfPCell od_pa = getCell(distanca[0][6], 2, 17);
            od_pa.setPaddingRight(45);
            visusi.addCell(od_pa);
        }

        if (distanca[0][11].isEmpty()) {
            visusi.addCell(getCellWhite("_", 2, 17));
        } else {
            visusi.addCell(getCell(distanca[0][11], 2, 17));
        }

        if (distanca[0][7].isEmpty()) {
            PdfPCell os_pa = getCellWhite("_", 2, 17);
            os_pa.setPaddingRight(45);
            visusi.addCell(os_pa);
        } else {
            PdfPCell os_pa = getCell(distanca[0][7], 2, 17);
            os_pa.setPaddingRight(45);
            visusi.addCell(os_pa);
        }

        if (distanca[0][12].isEmpty()) {
            visusi.addCell(getCellWhite("_", 2, 17));
        } else {
            visusi.addCell(getCell(distanca[0][12], 2, 0));
        }
        visusi.setWidthPercentage(100);
        visusi.setHorizontalAlignment(50);

        String[][] admin = merrReceten("select * from admin where id=1;");
        PdfPTable klienti = new PdfPTable(3);
        klienti.addCell(getCell("", 0, 0));
        klienti.addCell(getCell("", 0, 0));
        klienti.addCell(getCell("Emri: " + receta[0][2], 0, 0));

        klienti.addCell(getCell("Celular: " + admin[0][4], 0, 0));
        klienti.addCell(getCell("", 0, 0));
        PdfPCell celReceta = getCell("Celular: " + receta[0][4], 0, 0);
        celReceta.setPaddingTop(5);
        klienti.addCell(celReceta);

        klienti.addCell(getCell("Email: " + admin[0][5], 0, 0));
        klienti.addCell(getCell("", 0, 0));
        PdfPCell emailReceta = getCell("Email: " + receta[0][5], 0, 0);
        emailReceta.setPaddingBottom(5);
        emailReceta.setPaddingTop(5);
        klienti.addCell(emailReceta);

        klienti.addCell(getCell("Adresa: " + admin[0][6], 0, 0));
        klienti.addCell(getCell("", 0, 0));
        klienti.addCell(getCell("Adresa: " + receta[0][6], 0, 0));
        klienti.setSpacingBefore(50);

        PdfPTable kreu = new PdfPTable(1);
        kreu.addCell(getCell(" ", 0, 0));

        document.add(kreu);
        document.add(klienti);
        document.add(data);
        document.add(table);
        document.add(largAfer);
        document.add(od_os);
        document.add(visusi);

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();

}