Example usage for com.itextpdf.text ExceptionConverter ExceptionConverter

List of usage examples for com.itextpdf.text ExceptionConverter ExceptionConverter

Introduction

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

Prototype

public ExceptionConverter(Exception ex) 

Source Link

Document

Construct a RuntimeException based on another Exception

Usage

From source file:book.pdftemplates.FillTemplateHelper.java

@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte canvas = writer.getDirectContentUnder();
    // background
    canvas.addTemplate(background, 0, 0);
    try {// ww w. ja  v  a 2  s  . c o m
        // date
        ColumnText ct = new ColumnText(canvas);
        ct.setSimpleColumn(date);
        ct.addText(new Chunk(today, font));
        ct.go();
        // footer (page X of Y)
        ct.setSimpleColumn(footer);
        ct.addText(new Chunk("page " + writer.getPageNumber(), font));
        ct.addText(new Chunk(Image.getInstance(total), 0, 0));
        ct.go();
        // from address
        ct.setSimpleColumn(from);
        ct.addElement(new Paragraph(sender, font));
        ct.go();
        // to address
        ct.setSimpleColumn(to);
        ct.addElement(new Paragraph(receiver, font));
        ct.go();
    } catch (DocumentException e) {
        // can never happen, but if it does, we want to know!
        throw new ExceptionConverter(e);
    }
}

From source file:cl.preguntame.clases.Cabecera.java

/**
 * Esta es el metodo a llamar cuando ocurra el evento onEndPage, es en este
 * evento donde crearemos el encabeazado de la pagina con los elementos
 * indicados.//from  w  w  w .  jav a  2s . c om
 */
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {
        // Se determina el ancho y altura de la tabla 
        table.setWidths(new int[] { 24, 24, 2 });
        table.setTotalWidth(527);
        table.setLockedWidth(true);
        table.getDefaultCell().setFixedHeight(20);

        // Borde de la celda
        table.getDefaultCell().setBorder(Rectangle.BOTTOM);

        table.addCell(encabezado);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

        table.addCell(String.format("Pagina % 01d de ", writer.getPageNumber()));

        PdfPCell cell = new PdfPCell(Image.getInstance(total));

        cell.setBorder(Rectangle.BOTTOM);

        table.addCell(cell);
        // Esta linea escribe la tabla como encabezado
        table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}

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

License:Apache License

/**
 * header ? footer  //w  ww  .  j  ava  2 s .com
 */
public void onEndPage(PdfWriter writer, Document document) {

    if (titleFlag)
        return;

    Font font = new Font(bfKorean, 9);
    PdfPTable hTable = new PdfPTable(1);
    PdfPTable ftable = new PdfPTable(3);
    try {

        hTable.setWidths(new int[] { 100 });
        hTable.setTotalWidth(500);
        hTable.setLockedWidth(true);
        hTable.getDefaultCell().setFixedHeight(15);
        hTable.getDefaultCell().setBorder(Rectangle.BOTTOM);
        hTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        hTable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.header.title"), font));
        hTable.writeSelectedRows(0, -1, 50, 803, writer.getDirectContent());

        ftable.setWidths(new int[] { 100, 100, 100 });
        ftable.setTotalWidth(500);
        ftable.setLockedWidth(true);
        ftable.getDefaultCell().setBorder(Rectangle.TOP);
        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        ftable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.footer.left"), font));
        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        if (pagingFlag)
            ftable.addCell(new Phrase(
                    MessageUtil.getMessage("pdf.message.footer.center", String.valueOf(writer.getPageNumber())),
                    font));
        else
            ftable.addCell("");

        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        ftable.addCell(new Phrase(String.valueOf(new SimpleDateFormat("yyyy/MM/dd").format(new Date())), font));
        ftable.writeSelectedRows(0, -1, 50, 55, writer.getDirectContent());
    } catch (Exception de) {
        throw new ExceptionConverter(de);
    }
}

From source file:com.automaster.autoview.server.servlet.TableHeader.java

/**
 * Adds a header to every page/*w  w  w .  j  a  va  2  s . c  o m*/
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {
        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("Pgina %d de", 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);
    }
}

From source file:com.gp.cong.logisoft.reports.DeliveryOrderPdfCreator.java

public String createDeliveryOrderReport(FclBl bl, String fileName, String contextPath,
        MessageResources messageResources) throws Exception {
    try {//w w  w  . jav a  2s  . co  m
        this.initialize(fileName, bl);
        this.createBody(bl, fileName, contextPath, messageResources);
        this.destroy();
    } catch (Exception e) {
        log.info("createDeliveryOrderReport failed on" + new Date(), e);
        throw new ExceptionConverter(e);
    }
    return "fileName";
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

/**
 * @see com.itextpdf.text.xml.simpleparser.SimpleXMLDocHandler#startElement(java.lang.String, java.util.Map)
 *///from   ww  w .  j av  a 2  s .  co m
public void startElement(final String tag, final Map<String, String> attrs) {
    HTMLTagProcessor htmlTag = tags.get(tag);
    if (htmlTag == null) {
        return;
    }
    // apply the styles to attrs
    style.applyStyle(tag, attrs);
    // deal with the style attribute
    StyleSheet.resolveStyleAttribute(attrs, chain);
    // process the tag
    try {
        htmlTag.startElement(this, tag, attrs);
    } catch (DocumentException e) {
        throw new ExceptionConverter(e);
    } catch (IOException e) {
        throw new ExceptionConverter(e);
    }
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

/**
 * @see com.itextpdf.text.xml.simpleparser.SimpleXMLDocHandler#endElement(java.lang.String)
 *//*from w  w  w .  ja v  a2  s  .co  m*/
public void endElement(final String tag) {
    HTMLTagProcessor htmlTag = tags.get(tag);
    if (htmlTag == null) {
        return;
    }
    // process the tag
    try {
        htmlTag.endElement(this, tag);
    } catch (DocumentException e) {
        throw new ExceptionConverter(e);
    }
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

/**
 * @see com.itextpdf.text.xml.simpleparser.SimpleXMLDocHandler#endDocument()
 *//*from w w  w . j  a v a2s  . c o m*/
public void endDocument() {
    try {
        // flush the stack
        for (int k = 0; k < stack.size(); ++k)
            document.add(stack.elementAt(k));
        // add current paragraph
        if (currentParagraph != null)
            document.add(currentParagraph);
        currentParagraph = null;
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:itext_result.Main.java

private int developScreeningSheet() {
    new SwingWorker<Object, Object>() {
        String filename;// www. j  a  va2 s . c om

        @Override
        protected void done() {

            // ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. ");
        }

        public PdfPCell createBarcode(PdfWriter writer, String code) throws DocumentException, IOException {
            BarcodeEAN barcode = new BarcodeEAN();
            barcode.setCodeType(Barcode.EAN8);
            barcode.setCode(code);
            PdfPCell cell = new PdfPCell(
                    barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY),
                    true);
            cell.setPadding(10);
            return cell;
        }

        class ImageContent implements PdfPTableEvent {

            protected com.itextpdf.text.Image content;

            public ImageContent(com.itextpdf.text.Image content) {
                this.content = content;
            }

            public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows,
                    int rowStart, PdfContentByte[] canvases) {
                try {
                    PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS];
                    float x = widths[3][1] + 10;
                    float y = heights[3] - 10 - content.getScaledHeight();
                    content.setAbsolutePosition(x, y);
                    canvas.addImage(content);
                } catch (DocumentException e) {
                    throw new ExceptionConverter(e);
                }
            }
        }

        @Override
        protected Object doInBackground() throws Exception {
            //   System.err.println(" Roll No Received ....." + rollno);
            Document doc = new Document();
            try {
                PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("12345" + ".pdf"));
                doc.open();
                doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : ");
                doc.addSubject("Confidential Report Eyes Only");
                doc.addKeywords("");
                doc.addAuthor("SOS");
                doc.addCreator("SOS");

                // A4 = 210mm x 297mm ~ 605points x 855points
                doc.setPageSize(PageSize.A5);
                doc.setMargins(15f, 15f, 15f, 15f);

                /////////////////////////////////////////////////////////////
                int pageno = 1;

                for (int i = 0; i == pageno; i++) {

                    //    doc.add(imageRight);
                }

                PdfContentByte cb = writer.getDirectContent();
                //DONE
                BarcodeEAN codeEAN = new BarcodeEAN();
                codeEAN.setCodeType(Barcode.EAN8);
                Barcode128 code128 = new Barcode128();
                code128.setCode(String.valueOf("123456"));

                Barcode128 code128_jacket = new Barcode128();
                code128_jacket.setCode(String.valueOf("10345"));

                codeEAN.setCode(String.valueOf("123456"));
                com.itextpdf.text.Image imageEAN = code128.createImageWithBarcode(cb, null, null);
                // imageEAN.scalePercent(10f);
                //464f, 725f
                //  imageEAN.setAbsolutePosition(474f, 662f);

                int i = 1;
                while (i <= pageno) {
                    doc.newPage();
                    //   cb.addImage(imageRight);
                    //   cb.addImage(imageEAN);
                    i++;
                }

                com.itextpdf.text.Image carcode = code128_jacket.createImageWithBarcode(cb, null, null);
                carcode.scaleAbsolute(100f, 35f);
                carcode.setAbsolutePosition(500f, 600f);
                writer.addDirectImageSimple(carcode);
                //     cb.addImage(carcode);

                com.itextpdf.text.Image carcode2 = code128.createImageWithBarcode(cb, null, null);
                carcode2.scaleAbsolute(100f, 35f);
                carcode2.setAbsolutePosition(450f, 760f);
                writer.addDirectImageSimple(carcode2);
                //    cb.addImage(carcode2);

                Image image1 = Image.getInstance("jklogo.gif");

                PdfPTable table = new PdfPTable(1);
                table.setWidthPercentage(99);
                table.addCell(image1);
                doc.add(table);
                table = new PdfPTable(4);
                table.setWidthPercentage(99);

                float[] columnWidths = { 6, 2 };
                PdfPTable CandidateTable = new PdfPTable(columnWidths);
                Font f = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK);
                Font fsmall = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK);
                PdfPCell rollno = new PdfPCell(new Phrase("Roll No# " + String.valueOf("123456"), fsmall));
                PdfPCell cname = new PdfPCell(new Phrase("Name #" + String.valueOf("John Doe"), fsmall));
                //                    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
                //                    String today = formatter.format(cInfo.getDob());
                PdfPCell dob = new PdfPCell(new Phrase("DOB#" + String.valueOf("12-03-1989"), fsmall));
                PdfPCell fname = new PdfPCell(new Phrase("F/H Name #" + String.valueOf("Big John"), fsmall));
                PdfPCell type = new PdfPCell(new Phrase("Total Time  #" + String.valueOf("350.00"), fsmall));

                //  String scrtoday = formatter.format(cInfo.getScreeningdate());
                //  System.out.println("Today : " + today);
                PdfPCell scrdate = new PdfPCell(new Phrase("Laps  #" + String.valueOf("4"), fsmall));
                PdfPCell cell = new PdfPCell(new Phrase(" ", fsmall));

                rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                cname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                dob.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                fname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                type.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                scrdate.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                cell.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);

                CandidateTable.addCell(rollno);
                CandidateTable.addCell(cell);
                CandidateTable.addCell(cname);
                CandidateTable.addCell(cell);
                CandidateTable.addCell(dob);
                CandidateTable.addCell(cell);

                PdfPTable CandidateOtherTable = new PdfPTable(columnWidths);
                CandidateOtherTable.addCell(fname);
                CandidateOtherTable.addCell(cell);
                CandidateOtherTable.addCell(scrdate);
                CandidateOtherTable.addCell(cell);
                CandidateOtherTable.addCell(type);
                CandidateOtherTable.addCell(cell);

                PdfPCell race_start_time = new PdfPCell(new Phrase("Start Time :XX-XX-XX ", fsmall));
                PdfPCell race_end_time = new PdfPCell(new Phrase("End Time :XX-XX-XX", fsmall));
                PdfPCell race_total_time = new PdfPCell(new Phrase("Total Time : 350.00   ", fsmall));
                race_start_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                race_end_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                race_total_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);

                PdfPTable CandidateRaceDetails = new PdfPTable(columnWidths);
                CandidateRaceDetails.addCell(race_start_time);
                CandidateRaceDetails.addCell(cell);
                CandidateRaceDetails.addCell(race_end_time);
                CandidateRaceDetails.addCell(cell);
                CandidateRaceDetails.addCell(race_total_time);
                CandidateRaceDetails.addCell(cell);

                PdfPTable tablewith3cells = new PdfPTable(3);
                //1 St Col for Roll No Name and DOB
                tablewith3cells.addCell(CandidateTable);
                //2 nd Col for Father Name sCREEning Date Gurkha 
                tablewith3cells.addCell(CandidateOtherTable);
                //3rd Col for Barcode to be Printed
                tablewith3cells.addCell(CandidateRaceDetails);
                // Setting the Width here to 101
                tablewith3cells.setWidthPercentage(99);
                doc.add(tablewith3cells);

                PdfPTable userArea = new PdfPTable(1);
                userArea.setWidthPercentage(99);
                userArea.addCell(" \n \n Congratulations \n \n ");

                doc.add(userArea);

                PdfPTable footerCSBC = new PdfPTable(2);
                footerCSBC.setWidthPercentage(99);

                PdfPCell height_box = new PdfPCell(new Phrase("Height  \n\n\n", f));
                height_box.setBorder(com.itextpdf.text.Rectangle.BOX);
                PdfPCell chest_box = new PdfPCell(new Phrase("Chest  \n\n\n", f));
                chest_box.setBorder(com.itextpdf.text.Rectangle.BOX);
                PdfPCell chest_exp_box = new PdfPCell(new Phrase("Chest Exp  \n\n\n", f));
                chest_exp_box.setBorder(com.itextpdf.text.Rectangle.BOX);
                PdfPCell pushup_box = new PdfPCell(new Phrase("Pushup  \n\n\n", f));
                pushup_box.setBorder(com.itextpdf.text.Rectangle.BOX);

                //CSignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX);
                // ASignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX);
                footerCSBC.addCell(height_box);
                footerCSBC.addCell(chest_box);
                footerCSBC.addCell(chest_exp_box);
                footerCSBC.addCell(pushup_box);

                doc.add(footerCSBC);

                float[] columnWidths_ForBarcode = { 6, 3 };
                PdfPTable terminalinfo = new PdfPTable(columnWidths_ForBarcode);
                // terminalinfo.setWidthPercentage(99);
                String computername = InetAddress.getLocalHost().getHostName();
                System.out.println(computername);
                PdfPCell pcname = new PdfPCell(new Phrase("\t Jacket \n\n ", f));

                String UserMatchScore = "\t Barcode\n\n";

                PdfPCell score = new PdfPCell(new Phrase(UserMatchScore, f));
                PdfPCell barcode = new PdfPCell(carcode2);
                PdfPCell jacketnumber = new PdfPCell(carcode);
                pcname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                score.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                barcode.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                jacketnumber.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);

                terminalinfo.addCell(score);
                terminalinfo.addCell(pcname);
                terminalinfo.addCell(barcode);
                terminalinfo.addCell(jacketnumber);

                doc.add(terminalinfo);

                PdfPCell eula_notice = new PdfPCell(new Phrase("  ", f));
                eula_notice.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);

                cell.setHorizontalAlignment(Element.ALIGN_CENTER);

                PdfPTable eula_notice_table = new PdfPTable(1);
                eula_notice_table.setWidthPercentage(25);
                eula_notice_table.addCell(eula_notice);

                doc.add(eula_notice_table);

            } catch (Exception e) {
                System.err.println(e.getMessage());

                // ConsoleMsg(e.getMessage());
            } finally {
                doc.close();
                doc.close();
                doc.close();
            }

            //ConsoleMsg("PDF... GENERATED");
            return null;
            //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }.execute();

    return 0;
}

From source file:jdbreport.model.io.pdf.itext5.ReportFontMapper.java

License:Apache License

public com.itextpdf.text.Font styleToPdf(CellStyle style) {
    try {//from   www . ja v a  2 s  .  c o m
        java.awt.Font font = new java.awt.Font(style.getFamily(), style.getStyle(), style.getSize());
        BaseFont baseFont = awtToPdf(font);
        if (baseFont != null) {
            return new com.itextpdf.text.Font(baseFont, (float) style.getSize(), style.getStyle(),
                    new BaseColor(style.getForegroundColor().getRGB()));
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }

    return null;
}