Example usage for com.itextpdf.text.pdf PdfPTable getDefaultCell

List of usage examples for com.itextpdf.text.pdf PdfPTable getDefaultCell

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable getDefaultCell.

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:org.unesco.jisis.printsort.BarCodeGenerator.java

public void generateBarCode() {
    /** Step 1: Create a Document*/
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {//from  www . j  ava 2 s.  c om

        /** Step 2: Create PDF Writer*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("sanjaalDotCom_BarCode1.pdf"));

        /** Step 3: Open the document so that we can write over it.*/
        document.open();

        /** Step 4: We have to create a set of contents.*/
        contentByte = writer.getDirectContent();

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.getDefaultCell().setFixedHeight(70);

        String myText = "www.sanjaal.com"; // Text to encode

        table.addCell("CODE 39");
        table.addCell(new Phrase(new Chunk(createBarCode39(myText.toUpperCase()), 0, 0)));

        table.addCell("CODE 39 EXTENDED");
        table.addCell(new Phrase(new Chunk(createBarcode39Extended(myText), 0, 0)));

        table.addCell("CODE 128");
        table.addCell(new Phrase(new Chunk(createBarcode128(myText), 0, 0)));

        table.addCell("CODE INTERLEAVED");
        String myTextNum = "12345";
        table.addCell(new Phrase(new Chunk(createBarcodeInter25(myTextNum), 0, 0)));

        table.addCell("CODE POSTNET");
        table.addCell(new Phrase(new Chunk(createBarcodePostnet(myTextNum), 0, 0)));

        table.addCell("CODE PLANET");
        table.addCell(new Phrase(new Chunk(createBarcodePostnetPlanet(myTextNum), 0, 0)));

        String myTextEAN13 = "1234567890123";
        table.addCell("CODE EAN");
        table.addCell(new Phrase(new Chunk(createBarcodeEAN(myTextEAN13), 0, 0)));

        table.addCell("CODE EAN\nWITH\nSUPPLEMENTAL 5");
        table.addCell(new Phrase(new Chunk(createBARCodeEANSUPP(myTextEAN13, "12345"), 0, 0)));

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }

    // step 5: we close the document
    document.close();
}

From source file:Output.QuotePDf.java

private PdfPTable packingListTable(JTable packingListTable) throws DocumentException {
    PdfPTable table = new PdfPTable(11);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setWidthPercentage(100f);// w  ww .j a va2s .c om
    table.setWidths(new int[] { 5, 2, 2, 2, 2, 3, 2, 2, 2, 3, 3 });
    table.setSpacingAfter(10f);

    cell = new PdfPCell(new Phrase("Packing List", tableHeadingFont));
    cell.setBackgroundColor(BaseColor.BLACK);
    cell.setColspan(11);
    cell.setPaddingBottom(5);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Commodity", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Qty", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("L(cm)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("W(cm)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("H(cm)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Kgs", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("L(in)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("W(in)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("H(in)", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("M3", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Lbs", plLabelFont));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    for (int row = 0; row < packingListTable.getRowCount(); row++) {
        for (int col = 0; col < 11; col++) {
            String packingListData = String.valueOf(packingListTable.getValueAt(row, col));
            if (packingListData.equals("null")) {
                packingListData = " ";
                cell = new PdfPCell(new Phrase(packingListData, textFont));
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            } else {
                cell = new PdfPCell(new Phrase(packingListData, textFont));
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            }
        }
    }

    return table;
}

From source file:pdf.FooterHeader.java

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {/* ww  w.j a  v  a2  s .com*/
        if (document.getPageNumber() > 1) {
            table.setWidths(new int[] { 24, 24, 2 });
            table.setTotalWidth(527);
            table.setLockedWidth(true);
            table.getDefaultCell().setFixedHeight(20);
            table.getDefaultCell().setBorder(Rectangle.BOTTOM);
            table.addCell(header);
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(String.format("Seite %d von", writer.getPageNumber()));
            PdfPCell cell = new PdfPCell(Image.getInstance(total));
            cell.setBorder(Rectangle.BOTTOM);
            table.addCell(cell);
            table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
        }
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }

    PdfContentByte cb = writer.getDirectContent();
    if (document.getPageNumber() > 1) {
        footer = new Phrase(document.getPageNumber() - 2);
        ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer,
                (document.right() - document.left() - 30) / 2 + document.leftMargin(), document.bottom() + 10,
                0);
    }

}

From source file:pdfMaker.MakePdfFile.java

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

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

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

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

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

        pdfPTable.setWidthPercentage(100f);

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

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

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

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

        PdfPCell cellUrlValue = new PdfPCell(new Paragraph(url, ipaGothic));
        cellUrlValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellUrlValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellUrlValue.setFixedHeight(50);
        pdfPTable.addCell(cellUrlValue);

        /*  */
        //cellUrlValue.getImage();
        writer.getDirectContent().addImage(cellUrlValue.getImage(), 100, 100, 100, 100, 100, 100);

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

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

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

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

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

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

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

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

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

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

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

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

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

    }
}

From source file:pipe.PdfMaker.java

/**
 * Builds and returns the main table.//from w  ww  .  j ava 2s .com
 * 
 * @return
 */
Element mainElement(ArrayList values) throws BadElementException {

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100f);
    table.getDefaultCell().setBorderWidth(0.5f);

    Element element;
    PdfPCell cell;
    element = this.firstElement((String) values.get(0));
    cell = this.createCell(1, 1);
    cell.setBorder(15);
    cell.setPadding(2f);
    cell.addElement(element);
    table.addCell(cell);
    String dirString = "pictures" + File.separator + (String) values.get(0) + "_" + (String) values.get(1) + "_"
            + (String) values.get(2) + File.separator + "01.jpg";
    element = this.fourthLogoElement(dirString);
    // You need to pass the image to the constructor.
    // If you add the image, it will be stretched to fill the cell.
    cell = new PdfPCell((Image) element);
    cell.setPadding(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_CENTER);
    cell.setBorderWidth(0.3f);
    cell.setRowspan(4);
    table.addCell(cell);

    element = this.thirdElement((String) values.get(1), (String) values.get(2));
    cell = this.createCell(1, 1);
    cell.addElement(element);
    table.addCell(cell);

    element = this.fifthElement((String) values.get(3), (String) values.get(4), (String) values.get(5));
    cell = this.createCell(1, 1);
    cell.addElement(element);
    table.addCell(cell);

    element = this.sixthElement((String) values.get(6), (String) values.get(7));
    cell = this.createCell(1, 1);
    cell.addElement(element);
    cell.setBorderWidth(0.3f);
    table.addCell(cell);

    element = this.seventhElement((String) values.get(8), (String) values.get(9));
    cell = this.createCell(1, 1);
    cell.addElement(element);
    table.addCell(cell);

    element = this.eightthElement((String) values.get(10), (String) values.get(11));
    cell = this.createCell(2, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.ninethElement((String) values.get(12), (String) values.get(13), (String) values.get(14));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.tenthElement((String) values.get(15), (String) values.get(16), (String) values.get(17));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.eleventhElement((String) values.get(18), (String) values.get(19), (String) values.get(20));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.twelvethElement((String) values.get(21), (String) values.get(22), (String) values.get(23));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.thirteenthElement((String) values.get(24), (String) values.get(25));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.fourteenthElement((String) values.get(26), (String) values.get(27));
    cell = this.createCell(1, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    element = this.fifteenthElement((String) values.get(28));
    cell = this.createCell(2, 1);
    cell.setBorderWidth(0.3f);
    cell.addElement(element);
    table.addCell(cell);

    return table;
}

From source file:psManage.StructSheet.java

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

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

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

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

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

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

        pdfPTable.setWidthPercentage(100f);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    }
}

From source file:Screens.Print.java

public void ConvertPDF() throws DocumentException, FileNotFoundException, UnsupportedEncodingException,
        IOException, ParserConfigurationException, SAXException {
    FontFactory.register("tahoma.ttf", "MY_FONT");
    Document document = new Document(PageSize.A5, 20, 20, 10, 10);
    Image image = Image.getInstance("123.jpg");
    PdfPTable table = new PdfPTable(2);
    table.getDefaultCell().setBorder(0);
    //        table.setBorderColor(BaseColor.WHITE);

    PdfPTable tablefooter = new PdfPTable(3);
    tablefooter.getDefaultCell().setBorder(0);
    try {/*  w ww  . j  a va  2s .c  o m*/

        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        image.setAbsolutePosition(350f, 520f);
        document.add(image);
        document.add(new Paragraph("\n\n        Telefon: " + PrintTel + "\n\n\n",
                FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph("Ad, Soyad, ID kod", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph(DataPrint.Ad + " " + DataPrint.Soyad + " (#" + DataPrint.idDaxilOlan + ")",
                FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Model, Marka", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph(DataPrint.Model + " " + DataPrint.Marka,
                FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Aksesuar", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph(DataPrint.Aksesuar, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Problem", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph(DataPrint.Problem, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Tarix", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph(DataPrint.DatePlan, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(new Paragraph("Telefon", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        table.addCell(
                new Paragraph(DataPrint.Telefon, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        document.add(table);
        document.add(
                new Paragraph(jEditorPane1.getText(), FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        //            document.add(new Paragraph(footer, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(
                new Paragraph("Thvil Verdi:", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(new Paragraph("" + DataPrint.Ad + " " + DataPrint.Soyad + "",
                FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(
                new Paragraph("_____________", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        tablefooter.addCell(new Paragraph("  ", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        tablefooter.addCell(new Paragraph("  ", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        tablefooter.addCell(new Paragraph("  ", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        tablefooter.addCell(
                new Paragraph("Thvil ald:", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(
                new Paragraph("Elxan ?sgrli", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10)));
        tablefooter.addCell(
                new Paragraph("_____________", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12)));
        document.add(tablefooter);
    } catch (FileNotFoundException | DocumentException e) {
    }
    document.close();
}

From source file:se.inera.intyg.rehabstod.service.export.pdf.PageNumberingEventHandler.java

License:Open Source License

/**
 * Adds a header to every page.//from w ww. j  a v a2  s  .c  o  m
 *
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(com.itextpdf.text.pdf.PdfWriter,
 *      com.itextpdf.text.Document)
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {

    try {
        PdfPTable table = new PdfPTable(2);

        table.setTotalWidth(document.getPageSize().getWidth());

        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        table.addCell(new Phrase(String.valueOf(writer.getPageNumber()), PdfExportConstants.TABLE_CELL_NORMAL));
        PdfPCell cell = new PdfPCell(Image.getInstance(total));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        table.writeSelectedRows(0, -1, document.left(), document.bottom(), writer.getDirectContent());

    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}

From source file:se.inera.intyg.rehabstod.service.export.pdf.PdfExportServiceImpl.java

License:Open Source License

private PdfPTable createSjukfallTable(List<SjukfallEnhet> sjukfallList, Urval urval, boolean showPatientId,
        boolean showSrsRisk) throws DocumentException {

    // Setup column widths (relative to each other)
    PdfPTable table = createTableColumns(urval, showPatientId, showSrsRisk);

    table.setWidthPercentage(100.0f);//from   w  w  w .  j  ava2  s. c om

    table.getDefaultCell().setBackgroundColor(TABLE_HEADER_BASE_COLOR);
    table.getDefaultCell().setBorderColor(TABLE_HEADER_BASE_COLOR);
    table.getDefaultCell().setNoWrap(true);
    table.getDefaultCell().setPadding(3f);
    table.getDefaultCell().setPaddingLeft(2f);

    addCell(table, TABLEHEADER_NR, PdfExportConstants.TABLE_HEADER_FONT);

    if (showPatientId) {
        addCell(table, TABLEHEADER_PERSONNUMMER, PdfExportConstants.TABLE_HEADER_FONT);
    }

    addCell(table, TABLEHEADER_ALDER, PdfExportConstants.TABLE_HEADER_FONT);

    if (showPatientId) {
        addCell(table, TABLEHEADER_NAMN, PdfExportConstants.TABLE_HEADER_FONT);
    }

    addCell(table, TABLEHEADER_KON, PdfExportConstants.TABLE_HEADER_FONT);
    addCell(table, TABLEHEADER_NUVARANDE_DIAGNOS, PdfExportConstants.TABLE_HEADER_FONT);
    addCell(table, TABLEHEADER_STARTDATUM, PdfExportConstants.TABLE_HEADER_FONT);
    addCell(table, TABLEHEADER_SLUTDATUM, PdfExportConstants.TABLE_HEADER_FONT);
    addCell(table, TABLEHEADER_SJUKSKRIVNINGSLANGD, PdfExportConstants.TABLE_HEADER_FONT);
    addCell(table, TABLEHEADER_ANTAL, PdfExportConstants.TABLE_HEADER_FONT);
    addCell(table, TABLEHEADER_SJUKSKRIVNINGSGRAD, PdfExportConstants.TABLE_HEADER_FONT);
    if (Urval.ALL.equals(urval)) {
        addCell(table, TABLEHEADER_NUVARANDE_LAKARE, PdfExportConstants.TABLE_HEADER_FONT);
    }

    if (showSrsRisk) {
        addCell(table, TABLEHEADER_SRS_RISK, PdfExportConstants.TABLE_HEADER_FONT);
    }

    // Set cell styles for the non-header cells following hereafter
    table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);
    table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY);
    table.getDefaultCell().setNoWrap(false);
    table.getDefaultCell().setPadding(2f);

    table.setHeaderRows(1);
    int rowNumber = 1;
    for (SjukfallEnhet is : sjukfallList) {
        if (rowNumber % 2 == 0) {
            table.getDefaultCell().setBackgroundColor(TABLE_EVEN_ROW_COLOR);
        } else {
            table.getDefaultCell().setBackgroundColor(TABLE_ODD_ROW_COLOR);
        }

        addCell(table, String.valueOf(rowNumber));

        if (showPatientId) {
            addCell(table, getPersonnummerColumn(is));
        }

        addCell(table, is.getPatient().getAlder());

        if (showPatientId) {
            addCell(table, is.getPatient().getNamn());
        }
        addCell(table, is.getPatient().getKon().getDescription());
        addCell(table, getCompoundDiagnoseText(is, showPatientId));
        addCell(table, is.getStart() != null ? YearMonthDateFormatter.print(is.getStart()) : "?");
        addCell(table, is.getSlut() != null ? YearMonthDateFormatter.print(is.getSlut()) : "?");
        addCell(table, getlangdText(is));
        addCell(table, is.getIntyg());
        addCell(table, getGrader(is));
        if (Urval.ALL.equals(urval)) {
            addCell(table, is.getLakare().getNamn());
        }
        if (showSrsRisk) {
            addCell(table, getRiskKategoriDesc(is.getRiskSignal()));
        }
        rowNumber++;
    }

    return table;

}

From source file:servlet.AdministrarRestriccion.java

public void genDocTren(HttpServletRequest request, HttpServletResponse response) throws Exception {

    int linea = Integer.parseInt(request.getParameter("idLinea"));
    //PrintWriter salida = response.getWriter();
    HttpSession session = request.getSession();
    // PrintWriter out = response.getWriter();
    Usuario usr = (Usuario) session.getAttribute("usuario");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {//from w  ww.ja v  a 2  s .  com

        String nota = new String(request.getParameter("nota").getBytes(), "UTF-8");
        String nota2 = new String(request.getParameter("nota2").getBytes(), "UTF-8");
        MaterialRodanteJpaController mrjc = new MaterialRodanteJpaController(Conex.getEmf());
        MaterialRodante mr = mrjc
                .findMaterialRodante(Integer.parseInt(request.getParameter("materialRodante")));
        String comunicaciones = new String(request.getParameter("comunicaciones").getBytes(), "UTF-8");
        String instrucciones = new String(request.getParameter("instrucciones").getBytes(), "UTF-8");
        String precauciones = new String(request.getParameter("precauciones").getBytes(), "UTF-8");
        String nombre = new String(request.getParameter("nombre").getBytes(), "UTF-8");
        String vigencia = request.getParameter("vigencia");

        String[] fecha = vigencia.split("-");

        LineaJpaController ljc = new LineaJpaController(Conex.getEmf());
        Linea l = ljc.findLinea(linea);

        Document documento = new Document(PageSize.A4);
        com.itextpdf.text.Font arialNegrita = FontFactory.getFont("arial", 9, Font.BOLD);
        com.itextpdf.text.Font arial = FontFactory.getFont("arial", 9, Font.PLAIN);
        com.itextpdf.text.Font saltoDeLinea = FontFactory.getFont("arial", 5, Font.BOLD);
        Paragraph parrafo = new Paragraph();
        int numResAs = 0;
        int numResDes = 0;
        RestriccionJpaController rjc = new RestriccionJpaController(Conex.getEmf());
        List<Restriccion> restDes = rjc.buscarIdLineaDescendenteDocTren(linea, l.getVelocidadLinea());
        List<Restriccion> restAsc = rjc.buscarIdLineaAscendenteDocTren(linea, l.getVelocidadLinea());
        int restAscTotal = restAsc.size() - 1;
        int restDescTotal = restDes.size() - 1;
        System.out.println(restAscTotal);
        System.out.println(restDescTotal);
        PdfWriter.getInstance(documento, baos);
        documento.open();

        do {

            try {
                URL url = getClass().getResource("/img/cintillo_s1.png");
                Image foto = Image.getInstance(url);
                foto.scaleToFit(500, 70);
                foto.setAlignment(Chunk.ALIGN_MIDDLE);
                documento.add(foto);
            } catch (Exception e) {
                e.printStackTrace();
            }
            documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita));

            documento.add(new Paragraph(
                    "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes",
                    arialNegrita));
            documento.add(new Paragraph(" ", saltoDeLinea));

            PdfPTable tabla = new PdfPTable(1);

            tabla.setHorizontalAlignment(10);
            tabla.setWidthPercentage(100f);
            tabla.addCell(new Paragraph("Operaciones Del Tren: circular a una velocidad no mayor de "
                    + l.getVelocidadLinea() + " Km/h", arial));
            tabla.addCell(new Paragraph("Nota: " + nota, arial));
            //tabla.getDefaultCell().setBorder(2);
            if (numResAs < restAscTotal) {
                tabla.getDefaultCell().setBorderWidthBottom(0);
                tabla.addCell(new Paragraph("Restricciones Ascendentes ", arialNegrita));
            }

            tabla.getDefaultCell().setBorderColorBottom(BaseColor.WHITE);

            int c = 0;
            for (int i = numResAs; i <= restAscTotal; i++) {
                if (c > 30) {
                    break;
                }
                //  System.out.println("imrimiento asc: "+numResAs);

                int pkI = (int) (restAsc.get(numResAs).getProgInicio() / 1000);
                int pkI1 = (int) (((restAsc.get(numResAs).getProgInicio() / 1000) - pkI) * 1000);
                int pkF = (int) (restAsc.get(numResAs).getProgFinal() / 1000);
                int pkF1 = (int) (((restAsc.get(numResAs).getProgFinal() / 1000) - pkF) * 1000);

                tabla.getDefaultCell().setBorder(14);
                tabla.getDefaultCell().setBorderWidthBottom(0);
                tabla.getDefaultCell().setBorderWidthTop(0);
                tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1
                        + " circular a una velocidad no mayor de "
                        + restAsc.get(numResAs).getVelocidadMaxAscendente() + " "
                        + restAsc.get(numResAs).getObservacion(), arial));
                numResAs++;

                c++;
            }

            if (c < 30) {
                tabla.getDefaultCell().setBorderWidthBottom(1);
                tabla.getDefaultCell().setBorderWidthTop(1);
                tabla.getDefaultCell().setBorder(14);

                tabla.addCell(new Paragraph("Restricciones Descendentes ", arialNegrita));

            }
            int d = c;
            if (c < 30) {

                for (int i = numResDes; i <= restDescTotal; i++) {
                    if (d > 30) {
                        break;
                    }

                    tabla.getDefaultCell().setBorder(14);
                    tabla.getDefaultCell().setBorderWidthBottom(0);
                    tabla.getDefaultCell().setBorderWidthTop(0);

                    int pkI = (int) (restDes.get(numResDes).getProgFinal() / 1000);
                    int pkI1 = (int) (((restDes.get(numResDes).getProgFinal() / 1000) - pkI) * 1000);
                    int pkF = (int) (restDes.get(numResDes).getProgInicio() / 1000);
                    int pkF1 = (int) (((restDes.get(numResDes).getProgInicio() / 1000) - pkF) * 1000);

                    tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1
                            + " circular a una velocidad no mayor de "
                            + restDes.get(numResDes).getVelocidadMaxDescendente() + " "
                            + restDes.get(numResDes).getObservacion(), arial));
                    numResDes++;
                    d++;

                }
            }

            int espacios = d;
            while (espacios < 30) {
                tabla.getDefaultCell().setBorderWidthBottom(0);
                tabla.getDefaultCell().setBorderWidthTop(0);
                tabla.addCell(new Paragraph(" ", arial));
                espacios++;

            }
            tabla.getDefaultCell().setBorder(15);
            tabla.getDefaultCell().setBorderWidthBottom(1);
            tabla.getDefaultCell().setBorderWidthTop(1);
            tabla.getDefaultCell().setMinimumHeight(50f);
            tabla.addCell(new Paragraph("Instrucciones: " + instrucciones, arial));
            tabla.addCell(new Paragraph("Comunicaciones: " + comunicaciones, arial));
            tabla.addCell(new Paragraph("Precauciones: " + precauciones, arial));
            tabla.getDefaultCell().setMinimumHeight(10f);
            tabla.addCell(new Paragraph("Vigencia A Partir De: " + fecha[0] + "/" + fecha[1] + "/" + fecha[2],
                    arial));
            tabla.getDefaultCell().setBorder(1);
            Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER,
                    "Realizado Por: " + usr.toString() + " - Gerencia de Gestin de Trfico", arialNegrita);
            preface.setAlignment(Element.ALIGN_CENTER);
            tabla.addCell(preface);
            tabla.getDefaultCell().setBorder(0);
            tabla.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);
            preface = new Paragraph(Paragraph.ALIGN_CENTER,
                    "EL NO CUMPLIR CON LAS LIMITACIONES PRESCRITAS EN ESTE"
                            + " DOCUMENTO VA EN CONTRA DE LA SEGURIDAD EN LA CIRCULACIN, POR LO TANTO SER?  MOTIVO DE SANCIN",
                    FontFactory.getFont("arial", 8f));
            tabla.addCell(preface);
            preface = new Paragraph(Paragraph.ALIGN_CENTER,
                    "Nota: Informacin sustentada con el informe tcnico "
                            + "de limitaciones de velocidad, emitido por el CCF (Centro de Control de Fallas)",
                    FontFactory.getFont("arial", 8f));
            tabla.addCell(preface);
            preface = new Paragraph(Paragraph.ALIGN_CENTER,
                    "Sentido Ascendente: Sentido en el cual aumenta la progresiva ej: 0+0 -> 41+000 -- Sentido Descendente: Sentido en el cual disminuye la progresiva ej: 41+000 -> 0+0 ",
                    FontFactory.getFont("arial", 6f));
            tabla.addCell(preface);
            preface = new Paragraph(Paragraph.ALIGN_CENTER,
                    "En la lnea Caracas-Cua el sentido ASCENDENTE corresponde a la V?A PAR y el DESCENDENTE a la V?A IMPAR",
                    FontFactory.getFont("arial", 6f));
            tabla.addCell(preface);

            documento.add(tabla);

            if (numResAs < restAscTotal || numResDes < restDescTotal) {
                documento.newPage();
            }
        } while (numResAs < restAscTotal || numResDes < restDescTotal);

        System.out.println("Termine");
        //CARACTER?STICAS DE MATERIAL RODANTE
        documento.newPage();

        try {
            URL url = getClass().getResource("/img/cintillo_s1.png");
            Image foto = Image.getInstance(url);
            foto.scaleToFit(500, 70);
            foto.setAlignment(Chunk.ALIGN_MIDDLE);
            documento.add(foto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita));

        documento.add(new Paragraph(
                "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes", arialNegrita));
        documento.add(new Paragraph(" ", saltoDeLinea));

        documento.add(
                new Paragraph("CARACTER?STICAS DE LA UNIDAD: " + mr.getNombreMaterialRodante(), arialNegrita));
        documento.add(new Paragraph(" ", saltoDeLinea));

        PdfPTable tablaMT = new PdfPTable(2);
        tablaMT.addCell(new Paragraph("ITEM", arialNegrita));
        tablaMT.addCell(new Paragraph("DESCRIPCIN", arialNegrita));
        tablaMT.addCell(new Paragraph("Nmero de Unidades Remolque", arial));
        tablaMT.addCell(new Paragraph(mr.getNumeroRemolque() + " Unidades", arial));
        tablaMT.addCell(new Paragraph("Nmero de Unidades Motriz", arial));
        tablaMT.addCell(new Paragraph(mr.getNumeroMotriz() + " Unidades", arial));
        tablaMT.addCell(new Paragraph("Longitud Total", arial));
        tablaMT.addCell(new Paragraph(mr.getLongitudTotal() + " m", arial));
        tablaMT.addCell(new Paragraph("Longitud Coche Remolque", arial));
        tablaMT.addCell(new Paragraph(mr.getLongitudRemolque() + " m", arial));
        tablaMT.addCell(new Paragraph("Longitud Coche Motriz", arial));
        tablaMT.addCell(new Paragraph(mr.getLongitudMotriz() + " m", arial));
        tablaMT.addCell(new Paragraph("Alto x Ancho Coche Motriz", arial));
        tablaMT.addCell(new Paragraph(mr.getAltoXAnchoMotriz() + " m", arial));
        tablaMT.addCell(new Paragraph("Alto x Ancho Coche Remolque", arial));
        tablaMT.addCell(new Paragraph(mr.getAltoXAnchoRemolque() + " m", arial));
        tablaMT.addCell(new Paragraph("Masa o Tara Total", arial));
        tablaMT.addCell(new Paragraph(mr.getMasa() + " t", arial));
        tablaMT.addCell(new Paragraph("Masa Coche Remolque", arial));
        tablaMT.addCell(new Paragraph(mr.getMasaRemolque() + " t", arial));
        tablaMT.addCell(new Paragraph("Masa Coche Motriz", arial));
        tablaMT.addCell(new Paragraph(mr.getMasaMotriz() + " t", arial));
        tablaMT.addCell(new Paragraph("Frenado", arial));
        tablaMT.addCell(new Paragraph(mr.getFrenadoDescripcion() + "", arial));
        tablaMT.addCell(new Paragraph("Trocha", arial));
        tablaMT.addCell(new Paragraph(l.getTrocha() + " m", arial));
        tablaMT.addCell(new Paragraph("Velocidad Comercial", arial));
        tablaMT.addCell(new Paragraph(mr.getVelocidadOperativa() + " Km/h", arial));
        tablaMT.addCell(new Paragraph("Aceleracin Mx.", arial));
        tablaMT.addCell(new Paragraph(mr.getAceleracionMax() + " m/s^2", arial));
        tablaMT.addCell(new Paragraph("Desaceleracin de Servicio", arial));
        tablaMT.addCell(new Paragraph(mr.getDesaceleracionMax() + " m/s^2", arial));
        tablaMT.addCell(new Paragraph("Desaceleracion de Emergencia", arial));
        tablaMT.addCell(new Paragraph(mr.getDesaceleracionEmergencia() + " m/s^2", arial));
        tablaMT.addCell(new Paragraph("Voltaje", arial));
        tablaMT.addCell(new Paragraph(mr.getVoltaje() + " V", arial));
        tablaMT.addCell(new Paragraph("Voltaje de Bateras", arial));
        tablaMT.addCell(new Paragraph(mr.getVoltajeBateria() + " V", arial));
        tablaMT.addCell(new Paragraph("Presin de Trabajo", arial));
        tablaMT.addCell(new Paragraph(mr.getPresionTrabajo() + "", arial));
        if (mr.getSubTipo().equals("Tren de Viajeros")) {
            tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial));
            tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " pasajeros", arial));
            tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial));
            tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " pasajeros", arial));
            tablaMT.addCell(new Paragraph("Capacidad Total", arial));
            tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " pasajeros", arial));
        } else {
            tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial));
            tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " t", arial));
            tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial));
            tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " t", arial));
            tablaMT.addCell(new Paragraph("Capacidad Total", arial));
            tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " t", arial));
        }
        documento.add(tablaMT);
        documento.add(new Paragraph(" ", saltoDeLinea));
        documento.add(new Paragraph(" ", saltoDeLinea));

        try {
            URL url = getClass().getResource("/img/" + request.getParameter("materialRodante") + ".jpg");
            Image foto = Image.getInstance(url);
            foto.scaleToFit(300, 300);
            foto.setAlignment(Chunk.ALIGN_MIDDLE);
            documento.add(foto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        documento.add(new Paragraph(" ", saltoDeLinea));
        documento.add(new Paragraph(" ", saltoDeLinea));
        PdfPTable t = new PdfPTable(1);
        t.setWidthPercentage(100f);
        t.addCell("Nota: " + nota2);
        documento.add(t);

        documento.add(new Paragraph(" ", saltoDeLinea));
        documento.add(new Paragraph(" ", saltoDeLinea));

        Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER, "Realizado Por: " + usr.toString(),
                arialNegrita);
        documento.add(preface);

        documento.close();

        response.addHeader("Content-Disposition", "attachment; filename=DocumentoDeTren.pdf");
        response.addHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.addHeader("Pragma", "public");
        response.setContentType("application/pdf");

        DataOutput output = new DataOutputStream(response.getOutputStream());

        byte[] bytes = baos.toByteArray();
        response.setContentLength(bytes.length);

        for (int i = 0; i < bytes.length; i++) {
            output.writeByte(bytes[i]);

        }

    } catch (Exception e) {
        e.printStackTrace();
        //            salida.print("http://localhost:8084/MODULO2.3/img/error.png");
    }

}