Example usage for com.lowagie.text.pdf BaseFont createFont

List of usage examples for com.lowagie.text.pdf BaseFont createFont

Introduction

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

Prototype

public static BaseFont createFont(String name, String encoding, boolean embedded)
        throws DocumentException, IOException 

Source Link

Document

Creates a new font.

Usage

From source file:managedbean.aas.reportController.java

public static void concatPDFs(List<InputStream> streamOfPDFFiles, OutputStream outputStream, boolean paginate) {

    Document document = new Document();
    try {/*from   www. j a  v a  2  s .  co m*/
        List<InputStream> pdfs = streamOfPDFFiles;
        List<PdfReader> readers = new ArrayList<PdfReader>();
        int totalPages = 0;
        Iterator<InputStream> iteratorPDFs = pdfs.iterator();

        // Create Readers for the pdfs.
        while (iteratorPDFs.hasNext()) {
            InputStream pdf = iteratorPDFs.next();
            PdfReader pdfReader = new PdfReader(pdf);
            readers.add(pdfReader);
            totalPages += pdfReader.getNumberOfPages();
        }
        // Create a writer for the outputstream            
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);

        document.open();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        PdfContentByte cb = writer.getDirectContent(); // Holds the PDF
        // data

        PdfImportedPage page;
        int currentPageNumber = 0;
        int pageOfCurrentReaderPDF = 0;
        Iterator<PdfReader> iteratorPDFReader = readers.iterator();

        // Loop through the PDF files and add to the output.
        while (iteratorPDFReader.hasNext()) {
            PdfReader pdfReader = iteratorPDFReader.next();

            // Create a new page in the target for each source page.
            while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) {
                document.newPage();
                pageOfCurrentReaderPDF++;
                currentPageNumber++;
                page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF);
                cb.addTemplate(page, 0, 0);

                // Code for pagination.
                if (paginate) {
                    cb.beginText();
                    cb.setFontAndSize(bf, 9);
                    cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
                            "" + currentPageNumber + " of " + totalPages, 520, 5, 0);
                    cb.endText();
                }
            }
            pageOfCurrentReaderPDF = 0;
        }
        outputStream.flush();
        document.close();
        outputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (document.isOpen()) {
            document.close();
        }
        try {
            if (outputStream != null) {
                outputStream.close();
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
}

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

License:Open Source License

public FileFontProvider(File fontDir) {
    Check.notNull(fontDir, "fontDir");

    String[] fontFiles = fontDir.list(new SuffixFileFilter(".ttf"));

    if (fontFiles == null) {
        fontFiles = new String[] {};
    }//from  w  ww .j ava 2s.c om

    fonts = new ArrayList<Font>(fontFiles.length);

    for (String fontFile : fontFiles) {
        logger.info("Adding font " + fontFile);

        try {
            fonts.add(new Font(
                    BaseFont.createFont(new File(fontDir, fontFile).getPath(), BaseFont.IDENTITY_H, true)));
        } catch (Throwable e) {
            logger.error("Error loading font " + fontFile, e);
        }
    }
}

From source file:mpv5.utils.export.Export.java

License:Open Source License

private static File mergeFiles(List<File> p) {

    Document document = new Document();
    try {//w w w .  ja v  a 2s  . c om
        List<InputStream> pdfs = new ArrayList<InputStream>();
        for (int i = 0; i < p.size(); i++) {
            File inputStream = p.get(i);
            pdfs.add(new FileInputStream(inputStream));
        }
        List<PdfReader> readers = new ArrayList<PdfReader>();
        int totalPages = 0;
        Iterator<InputStream> iteratorPDFs = pdfs.iterator();

        while (iteratorPDFs.hasNext()) {
            InputStream pdf = iteratorPDFs.next();
            PdfReader pdfReader = new PdfReader(pdf);
            readers.add(pdfReader);
            totalPages += pdfReader.getNumberOfPages();
        }

        File f = FileDirectoryHandler.getTempFile("pdf");
        FileOutputStream outputstream = new FileOutputStream(f);
        PdfWriter writer = PdfWriter.getInstance(document, outputstream);

        document.open();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        PdfContentByte cb = writer.getDirectContent();

        PdfImportedPage page;
        int currentPageNumber = 0;
        int pageOfCurrentReaderPDF = 0;
        Iterator<PdfReader> iteratorPDFReader = readers.iterator();

        // Loop through the PDF files and add to the output.
        while (iteratorPDFReader.hasNext()) {
            PdfReader pdfReader = iteratorPDFReader.next();

            // Create a new page in the target for each source page.
            while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) {
                document.newPage();
                pageOfCurrentReaderPDF++;
                currentPageNumber++;
                page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF);
                cb.addTemplate(page, 0, 0);

            }
            pageOfCurrentReaderPDF = 0;
        }
        outputstream.flush();
        document.close();
        outputstream.close();

        return f;
    } catch (Exception e) {
        Log.Debug(e);
    } finally {
        if (document.isOpen()) {
            document.close();
        }
    }

    return null;
}

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 ww  .  jav  a 2  s  . 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("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   ww  w .j  a  v a2  s .  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:net.bull.javamelody.internal.web.pdf.PdfFonts.java

License:Apache License

private Font getChineseFont() {
    if (chineseFont == null) {
        try {/*from ww  w.jav a2  s  . co  m*/
            BaseFont bfChinese;
            try {
                bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            } catch (final DocumentException e) {
                // now CJKFont.propertiesLoaded==true, load properties renamed (cf issue 258)
                loadCJKFonts();
                bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            }
            chineseFont = new Font(bfChinese, font.getSize(), font.getStyle());
        } catch (final DocumentException e) {
            throw new IllegalStateException(e);
        } catch (final IOException e) {
            throw new IllegalStateException(e);
        }
    }
    return chineseFont;
}

From source file:net.bull.javamelody.swing.print.AdvancedPageNumberEvents.java

License:Apache License

/**
 * we override the onOpenDocument method.
 *
 * @param writer/*from  w  ww  .j a v a2  s  .  c  o m*/
 *           PdfWriter
 * @param document
 *           Document
 */
@Override
public void onOpenDocument(final PdfWriter writer, final Document document) {
    try {
        bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb = writer.getDirectContent();
        template = cb.createTemplate(50, 50);
    } catch (final DocumentException de) {
        throw new IllegalStateException(de);
    } catch (final IOException ioe) {
        throw new IllegalStateException(ioe);
    }
}

From source file:net.mitnet.tools.pdf.book.pdf.builder.PdfBookBuilder.java

License:Open Source License

public void buildBook(List<File> inputFileList, File outputFile) {

    try {//w  w w.j a va2  s . c  o  m

        float pageWidth = getConfig().getPageWidth();
        float pageHeight = getConfig().getPageHeight();

        // Create new Document

        /*
        float marginLeft = 36;
        float marginRight = 36;
        float marginTop = 36;
        float marginBottom = 36;
        */

        if (isVerboseEnabled()) {
            verbose("Building output PDF file " + outputFile);
        }

        // TableOfContents toc = new TableOfContents();

        ProgressMonitor progressMonitor = getConfig().getProgressMonitor();
        TocRowChangeListener tocRowChangeListener = getConfig().getTocRowChangeListener();

        Document outputDocument = new Document(getConfig().getPageSize());
        // Document outputDocument = new Document( getPageSize(), marginLeft, marginRight, marginTop, marginBottom );

        PdfWriter pdfWriter = PdfWriter.getInstance(outputDocument, new FileOutputStream(outputFile));

        // TODO - review PDF page event forwarder
        PdfPageEventLogger pdfPageEventLogger = new PdfPageEventLogger();
        pdfWriter.setPageEvent(pdfPageEventLogger);

        outputDocument.open();

        String metaTitle = getConfig().getMetaTitle();
        if (!StringUtils.isEmpty(metaTitle)) {
            outputDocument.addTitle(metaTitle);
        }
        String metaAuthor = getConfig().getMetaAuthor();
        if (!StringUtils.isEmpty(metaAuthor)) {
            outputDocument.addAuthor(metaAuthor);
        }

        PdfContentByte pdfContent = pdfWriter.getDirectContent();

        // Loop through and pull pages
        int outputPageCount = 0;
        int currentSourceFileIndex = 0;
        int maxSourceFileIndex = inputFileList.size();

        // BaseFont pageLabelFont = BaseFont.createFont( PdfBookBuilderConfig.DEFAULT_FONT, BaseFont.CP1250, BaseFont.EMBEDDED );
        BaseFont pageLabelFont = BaseFont.createFont(PdfBookBuilderConfig.DEFAULT_FONT_PATH, BaseFont.CP1250,
                BaseFont.EMBEDDED);
        if (isVerboseEnabled()) {
            verbose("Using page label font " + pageLabelFont);
        }

        if (isVerboseEnabled()) {
            verbose("Assembling pages using n-up " + getConfig().getNup());
        }

        for (File sourceFile : inputFileList) {

            currentSourceFileIndex++;

            // TODO - refactor current file PDF page processing to another method
            // TODO - handle failover to ensure processing continues ???

            if (sourceFile.isFile()) {

                if (isVerboseEnabled()) {
                    verbose("Reading source PDF file " + sourceFile);
                }

                int sourcePageIndex = 0;

                PdfReader sourcePdfReader = new PdfReader(sourceFile.getCanonicalPath());
                PdfReaderHelper sourcePdfReaderHelper = new PdfReaderHelper(sourcePdfReader);
                if (isVerboseEnabled()) {
                    verbose("PDF reader is " + sourcePdfReader);
                    verbose("PDF reader helper is " + sourcePdfReaderHelper);
                }

                String currentSourcePdfTitle = FilenameUtils.getBaseName(sourceFile.getName());
                String currentSourcePdfAuthor = getSystemUserName();
                if (isVerboseEnabled()) {
                    verbose("PDF title is " + currentSourcePdfTitle);
                    verbose("PDF author is " + currentSourcePdfAuthor);
                }

                currentSourcePdfTitle = sourcePdfReaderHelper.getDocumentTitle(currentSourcePdfTitle);
                currentSourcePdfAuthor = sourcePdfReaderHelper.getDocumentTitle(currentSourcePdfAuthor);
                if (isVerboseEnabled()) {
                    verbose("PDF info title is " + currentSourcePdfTitle);
                    verbose("PDF info author is " + currentSourcePdfAuthor);
                }

                boolean firstPageOfCurrentSource = true;

                int maxSourcePages = sourcePdfReader.getNumberOfPages();
                if (isVerboseEnabled()) {
                    verbose("There are " + maxSourcePages + " page(s) in source PDF file " + sourceFile);
                }

                // process all pages from source doc
                while (sourcePageIndex < maxSourcePages) {

                    // add new page to current document
                    outputDocument.newPage();

                    outputPageCount++;
                    if (isVerboseEnabled()) {
                        verbose("Building output PDF page " + outputPageCount + " ...");
                    }

                    // add first page of current source to TOC listener
                    if (firstPageOfCurrentSource) {
                        int currentPageIndex = outputPageCount;
                        if (tocRowChangeListener != null) {
                            TocRow tocEntry = new TocRow(currentSourcePdfTitle, currentPageIndex);
                            tocRowChangeListener.addTocRow(tocEntry);
                            if (isVerboseEnabled()) {
                                verbose("Added TOC entry " + tocEntry + " to listener");
                            }
                        }
                        firstPageOfCurrentSource = false;
                    }

                    // extract first page from source document
                    sourcePageIndex++;
                    if (isVerboseEnabled()) {
                        verbose("Adding page " + sourcePageIndex + " of " + maxSourcePages
                                + " from source to output");
                    }
                    PdfImportedPage page1 = pdfWriter.getImportedPage(sourcePdfReader, sourcePageIndex);

                    // n-up is 1
                    if (config.getNup() == 1) {
                        // add first page to top half of current page
                        // TODO - review magic transformation matrix numbers and offsets
                        // TODO - calculate scaling/transform based on page rect and template rect
                        float p1a = 0.65f;
                        float p1b = 0;
                        float p1c = 0;
                        float p1d = 0.65f;
                        float p1e = 20;
                        float p1f = 160;
                        pdfContent.addTemplate(page1, p1a, p1b, p1c, p1d, p1e, p1f);

                        // n-up is 2 (default)
                    } else {

                        // add first page to top half of current page
                        // TODO - review magic transformation matrix numbers and offsets
                        float p1a = 0.5f;
                        float p1b = 0;
                        float p1c = 0;
                        float p1d = 0.5f;
                        float p1e = (125);
                        float p1f = ((pageWidth / 2) + 120 + 20);
                        pdfContent.addTemplate(page1, p1a, p1b, p1c, p1d, p1e, p1f);

                        // extract second page from source document ?
                        PdfImportedPage page2 = null;
                        if (sourcePageIndex < maxSourcePages) {
                            sourcePageIndex++;
                            if (isVerboseEnabled()) {
                                verbose("Adding page " + sourcePageIndex + " of " + maxSourcePages
                                        + " from source to output");
                            }
                            page2 = pdfWriter.getImportedPage(sourcePdfReader, sourcePageIndex);
                        }

                        // add second page to bottom half of current page
                        if (page2 != null) {
                            // TODO - review magic transformation matrix numbers and offsets
                            float p2a = 0.5f;
                            float p2b = 0;
                            float p2c = 0;
                            float p2d = 0.5f;
                            float p2e = 125;
                            float p2f = 120;
                            pdfContent.addTemplate(page2, p2a, p2b, p2c, p2d, p2e, p2f);
                        }
                    }

                    /*
                    // add first page to top half of current page
                    // TODO - review magic transformation matrix numbers and offsets
                    float p1a = 0.5f;
                    float p1b = 0;
                    float p1c = 0;
                    float p1d = 0.5f;
                    float p1e = (125);
                    float p1f = ((pageWidth / 2) + 120 + 20);
                    pdfContent.addTemplate( page1, p1a, p1b, p1c, p1d, p1e, p1f );
                            
                    // add second page to bottom half of current page
                    if (page2 != null) {
                       // TODO - review magic transformation matrix numbers and offsets
                       float p2a = 0.5f; 
                       float p2b = 0;
                       float p2c = 0;
                       float p2d = 0.5f;
                       float p2e = 125;
                       float p2f = 120;
                       pdfContent.addTemplate( page2, p2a, p2b, p2c, p2d, p2e, p2f );
                    }
                    */

                    // Add current page number to page footer
                    String pageCountLabel = "Page " + outputPageCount;
                    pdfContent.beginText();
                    pdfContent.setFontAndSize(pageLabelFont, PdfBookBuilderConfig.DEFAULT_FONT_SIZE);
                    pdfContent.showTextAligned(PdfContentByte.ALIGN_CENTER, pageCountLabel, (pageWidth / 2), 40,
                            0);
                    pdfContent.endText();
                }

                if (isVerboseEnabled()) {
                    verbose("Finished reading " + maxSourcePages + " page(s) from source PDF file "
                            + sourceFile);
                }

                // update progress
                if (isVerboseEnabled()) {
                    if (progressMonitor != null) {
                        int fileProgressPercentage = MathHelper.calculatePercentage(currentSourceFileIndex,
                                maxSourceFileIndex);
                        progressMonitor.setProgressPercentage(fileProgressPercentage);
                    }
                }
            }
        }

        // close document
        outputDocument.close();

        if (isVerboseEnabled()) {
            verbose("Output PDF file " + outputFile + " contains " + outputPageCount + " page(s)");
        }

        // TODO - output ODT page stats summary

    } catch (Exception e) {

        String msg = "Error building PDF book: " + e.getMessage();
        e.printStackTrace(System.err);
        System.err.println(msg);

    }

}

From source file:open.dolphin.client.AuditController.java

License:Open Source License

private void makePDF() {

    //- ?//from  ww  w. j  a  v a  2  s.  c o  m
    Document doc = new Document(PageSize.A4, 20.0F, 20.0F, 40.0F, 40.0F);

    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String fileName = "_" + sdf.format(new java.util.Date()) + ".pdf";

        //()??
        FileOutputStream fos = new FileOutputStream(outputDir.getText() + fileName);
        PdfWriter pdfwriter = PdfWriter.getInstance(doc, fos);
        Font font_header = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 15.0F, 1);
        Font font_g11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F);
        Font font_g10 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 10.0F);
        //- ?
        Font font_m8 = new Font(BaseFont.createFont("HeiseiMin-W3", "UniJIS-UCS2-HW-H", false), 8.0F);
        Font font_underline_11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F,
                4);
        Font font_red_11 = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 11.0F);
        font_red_11.setColor(new Color(255, 0, 0));
        Font font_empty = new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 9.0F);
        font_empty.setColor(new Color(255, 255, 255));

        Paragraph para_NF = new Paragraph(5, "\r\n",
                new Font(BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", false), 13, Font.NORMAL));
        para_NF.setAlignment(Element.ALIGN_CENTER);

        // ??
        String author = Project.getProjectStub().getUserModel().getCommonName();
        doc.addAuthor(author);
        doc.addSubject("");

        HeaderFooter header = new HeaderFooter(new Phrase("", font_header),
                false);
        header.setAlignment(1);
        doc.setHeader(header);

        HeaderFooter footer = new HeaderFooter(new Phrase("--"), new Phrase("--"));
        footer.setAlignment(1);
        footer.setBorder(0);
        doc.setFooter(footer);

        doc.open();

        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy''MM''dd'' HH''mm''");
        String today = sdf1.format(new java.util.Date());
        Paragraph para_0 = new Paragraph("?" + today, font_g11);
        para_0.setAlignment(2);
        doc.add(para_0);
        Paragraph para_1 = new Paragraph("?" + author, font_g11);
        para_1.setAlignment(2);
        doc.add(para_1);
        doc.add(new Paragraph(""));
        // 
        doc.add(para_NF);
        doc.add(para_NF);

        for (int cnt = 0; cnt < outputList.size(); cnt++) {

            InnerBean bean = outputList.get(cnt);
            Person person = bean.getPerson();

            Paragraph para_2 = new Paragraph("ID" + person.idProperty().get(), font_underline_11);
            para_2.setAlignment(0);
            doc.add(para_2);
            Paragraph para_3 = new Paragraph("???" + person.nameProperty().get(),
                    font_underline_11);
            para_3.setAlignment(0);
            doc.add(para_3);
            Paragraph para_4 = new Paragraph("" + person.nameKanaProperty().get(),
                    font_underline_11);
            para_4.setAlignment(0);
            doc.add(para_4);
            Paragraph para_5 = new Paragraph("" + person.sexProperty().get(), font_underline_11);
            para_5.setAlignment(0);
            doc.add(para_5);
            Paragraph para_6 = new Paragraph("" + person.birthdayProperty().get(),
                    font_underline_11);
            para_6.setAlignment(0);
            doc.add(para_6);

            Table karteHistoryTable = new Table(5);
            karteHistoryTable.setWidth(100.0F);
            int[] uriage_table_width = { 25, 20, 30, 20, 25 };
            karteHistoryTable.setWidths(uriage_table_width);
            //karteHistoryTable.setDefaultHorizontalAlignment(1);
            //karteHistoryTable.setDefaultVerticalAlignment(5);
            karteHistoryTable.setPadding(3.0F);
            karteHistoryTable.setSpacing(0.0F);
            karteHistoryTable.setBorderColor(new Color(0, 0, 0));

            Cell cell_01 = new Cell(new Phrase("?", font_g10));
            cell_01.setGrayFill(0.8F);
            cell_01.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_11 = new Cell(new Phrase("?", font_g10));
            cell_11.setGrayFill(0.8F);
            cell_11.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_21 = new Cell(new Phrase("", font_g10));
            cell_21.setGrayFill(0.8F);
            cell_21.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_31 = new Cell(new Phrase("", font_g10));
            cell_31.setGrayFill(0.8F);
            cell_31.setHorizontalAlignment(Element.ALIGN_CENTER);
            Cell cell_41 = new Cell(new Phrase("", font_g10));
            cell_41.setGrayFill(0.8F);
            cell_41.setHorizontalAlignment(Element.ALIGN_CENTER);

            karteHistoryTable.addCell(cell_01);
            karteHistoryTable.addCell(cell_11);
            karteHistoryTable.addCell(cell_21);
            karteHistoryTable.addCell(cell_31);
            karteHistoryTable.addCell(cell_41);

            List<KarteBean> list = bean.getResult();
            KarteBean karteInfo = list.get(0);
            List<DocInfoModel> docInfoList = karteInfo.getDocInfoList();

            //- ???
            int stepCount = 22;
            int tempCount = 0;
            int pageCount = 0;

            String firstKarteMaker = null;
            String karteMakeDate = null;
            if (docInfoList != null) {
                for (int i = 0; i < docInfoList.size(); ++i) {
                    DocInfoModel docInfo = docInfoList.get(i);
                    Cell cell = new Cell(new Phrase(docInfo.getFirstConfirmDateTime(), font_m8));
                    if (karteMakeDate == null || !karteMakeDate.equals(docInfo.getFirstConfirmDateTime())) {
                        karteMakeDate = docInfo.getFirstConfirmDateTime();
                        firstKarteMaker = docInfo.getPurpose();
                    }
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);
                    cell = new Cell(new Phrase(firstKarteMaker, font_m8));
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);
                    //- 
                    String addTitle = docInfo.getTitle();
                    addTitle = addTitle.replace("\r\n", "");
                    addTitle = addTitle.replace("\n", "");
                    cell = new Cell(new Phrase(addTitle, font_m8));
                    cell.setHorizontalAlignment(0);
                    karteHistoryTable.addCell(cell);
                    cell = new Cell(new Phrase(docInfo.getPurpose(), font_m8));
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);
                    cell = new Cell(new Phrase(docInfo.getConfirmDateTime(), font_m8));
                    cell.setHorizontalAlignment(0);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    karteHistoryTable.addCell(cell);

                    if (stepCount == tempCount) {
                        if (pageCount == 0) {
                            stepCount += 5;
                            pageCount++;
                        }
                        tempCount = 0;
                        doc.add(karteHistoryTable);
                        doc.newPage();
                        karteHistoryTable.deleteAllRows();
                        karteHistoryTable.addCell(cell_01);
                        karteHistoryTable.addCell(cell_11);
                        karteHistoryTable.addCell(cell_21);
                        karteHistoryTable.addCell(cell_31);
                        karteHistoryTable.addCell(cell_41);
                    } else {
                        tempCount++;
                    }
                }

                //                    Cell Empty_Cell = new Cell(new Phrase("empty", font_empty));
                //                    for (int i = docInfoList.size(); i < docInfoList.size() + 4; ++i) {
                //                        for (int j = 0; j < 4; ++j) {
                //                            karteHistoryTable.addCell(Empty_Cell);
                //                        }
                //                    }
                //
                //            Cell cell_goukei = new Cell(new Phrase("?", font_g10));
                //            cell_goukei.setGrayFill(0.8F);
                //            cell_goukei.setColspan(3);
                //            karteHistoryTable.addCell(cell_goukei);
                //            Cell cell_sum = new Cell(new Phrase("136,900", font_m10));
                //            cell_sum.setHorizontalAlignment(2);
                //            karteHistoryTable.addCell(cell_sum);
                doc.add(karteHistoryTable);
                doc.newPage();

            } else {
                // 
                doc.add(para_NF);

                Paragraph noData = new Paragraph("??", font_m8);
                noData.setAlignment(0);
                doc.add(noData);
                doc.newPage();
            }
        }
    } catch (DocumentException | IOException e) {
        Logger.getLogger(AuditController.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        doc.close();
    }
}

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

/**
 * ??/*from   w  ww . j a  v  a 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);
        // @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();
        }
    }
}