Example usage for com.lowagie.text ExceptionConverter ExceptionConverter

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

Introduction

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

Prototype

public ExceptionConverter(Exception ex) 

Source Link

Document

Construct a RuntimeException based on another Exception

Usage

From source file:ambit.data.qmrf.MyHandler.java

License:Open Source License

@Override
public void handleStartingTags(String name, Properties attributes) {
    System.out.println(name);//from   w  ww.j  a  va2  s.  co  m
    if (Image.isTag(name)) {
        try {
            //                Image img = Image.getInstance(attributes);
            System.out.println("ambit/data/qmrf/logo.png");
            Image img = Image
                    .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
            Object current;
            try {
                // if there is an element on the stack...
                current = stack.pop();
                // ...and it's a Chapter or a Section, the Image can be
                // added directly
                if (current instanceof Chapter || current instanceof Section || current instanceof Cell) {
                    ((TextElementArray) current).add(img);
                    stack.push(current);
                    return;
                }
                // ...if not, the Image is wrapped in a Chunk before it's
                // added
                else {
                    Stack newStack = new Stack();
                    try {
                        while (!(current instanceof Chapter || current instanceof Section
                                || current instanceof Cell)) {
                            newStack.push(current);
                            if (current instanceof Anchor) {
                                img.setAnnotation(new Annotation(0, 0, 0, 0, ((Anchor) current).reference()));
                            }
                            current = stack.pop();
                        }
                        ((TextElementArray) current).add(img);
                        stack.push(current);
                    } catch (EmptyStackException ese) {
                        document.add(img);
                    }
                    while (!newStack.empty()) {
                        stack.push(newStack.pop());
                    }
                    return;
                }
            } catch (EmptyStackException ese) {
                // if there is no element on the stack, the Image is added
                // to the document
                try {
                    document.add(img);
                } catch (DocumentException de) {
                    throw new ExceptionConverter(de);
                }
                return;
            }
        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }

    } else
        super.handleStartingTags(name, attributes);
}

From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextInputText.java

License:Open Source License

@Override
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
    PdfWriter writer = canvases[0].getPdfWriter();
    TextField text = new TextField(writer, rectangle, String.format("text_" + UUID.randomUUID().toString()));
    text.setBorderStyle(PdfBorderDictionary.STYLE_INSET);
    text.setText(value);// w  w  w.  j  av  a2  s  .co  m
    text.setFontSize(FONTSIZE);
    text.setAlignment(Element.ALIGN_LEFT);
    try {
        PdfFormField field = text.getTextField();
        if (locked) {
            field.setFieldFlags(BaseField.READ_ONLY);
        }
        writer.addAnnotation(field);
    } catch (IOException ioe) {
        throw new ExceptionConverter(ioe);
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}

From source file:biblivre3.administration.reports.BaseBiblivreReport.java

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    try {/*  w w w  .  j a v  a 2 s.c o  m*/
        Rectangle page = document.getPageSize();

        PdfPTable head = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Paragraph(this.getText("REPORTS_HEADER")));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.BOTTOM);
        head.addCell(cell);
        head.setTotalWidth((page.width() / 2) - document.leftMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        PdfPTable date = new PdfPTable(1);
        PdfPCell dateCell = new PdfPCell(new Paragraph(dateFormat.format(generationDate)));
        dateCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        dateCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        dateCell.setBorder(Rectangle.BOTTOM);
        date.addCell(dateCell);
        date.setTotalWidth((page.width() / 2) - document.rightMargin());
        date.writeSelectedRows(0, -1, (page.width() / 2),
                page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        PdfPTable foot = new PdfPTable(1);
        Chunk pageNumber = new Chunk(String.valueOf(document.getPageNumber()));
        pageNumber.setFont(footerFont);
        cell = new PdfPCell(new Paragraph(pageNumber));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.TOP);
        foot.addCell(cell);
        foot.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:br.org.acessobrasil.silvinha.util.HeaderAndFooter.java

License:Open Source License

/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 *//*ww  w. j a v  a 2 s.c o m*/
public void onEndPage(PdfWriter writer, Document document) {

    try {
        Rectangle page = document.getPageSize();
        PdfPTable head = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Paragraph(GERAL.RELATORIOS_ASES));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.BOTTOM);
        head.addCell(cell);
        head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());
        PdfPTable foot = new PdfPTable(1);
        cell = new PdfPCell(new Paragraph(String.valueOf(document.getPageNumber())));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.TOP);
        foot.addCell(cell);
        foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:com.aryjr.nheengatu.pdf.PDFPageBreak.java

License:Open Source License

@Override
public void onEndPage(final PdfWriter writer, final Document document) {
    try {//from w w w  .  j av  a2  s  .  c o m
        final Rectangle page = document.getPageSize();
        PDFTable head = null;
        PDFTable foot = null;

        if (writer.getPageNumber() == 1) {
            if (headFirstPageTag != null)
                head = createTable(writer, document, headFirstPageTag);
            if (footFirstPageTag != null)
                foot = createTable(writer, document, footFirstPageTag);
        } else {
            if (headTag != null)
                head = createTable(writer, document, headTag);
            if (footTag != null)
                foot = createTable(writer, document, footTag);
        }

        if (head != null) {
            head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - topMargin,
                    writer.getDirectContent());
        }
        if (foot != null) {
            foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            foot.writeSelectedRows(0, -1, document.leftMargin(), bottomMargin + foot.getTotalHeight(),
                    writer.getDirectContent());
        }
    } catch (final Exception e) {
        throw new ExceptionConverter(e);
    }

    document.setMargins(document.leftMargin(), document.rightMargin(), topMargin + headHeight,
            bottomMargin + footHeight);
}

From source file:com.gp.cong.logisoft.lcl.report.FreightInvoiceLclPdfCreator.java

@Override
public void onOpenDocument(PdfWriter writer, Document document) {
    total = writer.getDirectContent().createTemplate(100, 100);
    total.setBoundingBox(new Rectangle(-20, -20, 100, 100));
    try {// w  w w . j  a  va  2  s .co  m
        helv = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    } catch (Exception e) {
        log.info("onOpenDocument failed on " + new Date(), e);
        throw new ExceptionConverter(e);
    }
}

From source file:com.gp.cong.logisoft.lcl.report.FreightInvoiceLclPdfCreator.java

public void onStartArRedInvoicePage(PdfWriter writer, Document document) {
    try {//from www.  j  a  v  a2 s. c  o m
        SystemRulesDAO systemRulesDAO = new SystemRulesDAO();
        String companyAddress = systemRulesDAO.getSystemRulesByCode("CompanyAddress");
        String companyPhone = systemRulesDAO.getSystemRulesByCode("CompanyPhone");
        String companyFax = systemRulesDAO.getSystemRulesByCode("CompanyFax");
        PdfPCell cell = new PdfPCell();
        PdfPTable headingMainTable = new PdfPTable(1);
        headingMainTable.setWidthPercentage(100);
        PdfPTable headingTable = new PdfPTable(1);
        headingTable.setWidths(new float[] { 100 });
        PdfPTable imgTable = new PdfPTable(1);
        imgTable.setWidthPercentage(100);
        Image img = null;
        String logoImage = "";
        String brand = this.setBrand(fileNumberId);
        if (CommonUtils.isNotEmpty(brand)) {
            if ("ECI".equalsIgnoreCase(brand)) {
                logoImage = LoadLogisoftProperties.getProperty("application.image.econo.logo");
                img = Image.getInstance(realPath + logoImage);
                img.scalePercent(75);
            } else if ("OTI".equalsIgnoreCase(brand)) {
                logoImage = LoadLogisoftProperties.getProperty("application.image.econo.logo");
                img = Image.getInstance(realPath + logoImage);
                img.scalePercent(45);
            } else {
                logoImage = LoadLogisoftProperties.getProperty("application.image.logo");
                img = Image.getInstance(realPath + logoImage);
                img.scalePercent(45);
            }
        }
        img.scalePercent(75);
        PdfPCell logoCell = new PdfPCell(img);
        logoCell.setBorder(Rectangle.NO_BORDER);
        logoCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        logoCell.setVerticalAlignment(Element.ALIGN_LEFT);
        logoCell.setPaddingLeft(+27);
        imgTable.addCell(logoCell);
        PdfPTable addrTable = new PdfPTable(1);
        addrTable.setWidthPercentage(100);
        PdfPTable invoiceFacturaTable = new PdfPTable(3);
        invoiceFacturaTable.setWidthPercentage(100);
        invoiceFacturaTable.setWidths(new float[] { 40, 20, 40 });
        StringBuilder stringBuilder = new StringBuilder();
        addrTable.addCell(makeCellCenterNoBorderFclBL("MAILING ADDRESS: "
                + (CommonUtils.isNotEmpty(companyAddress) ? companyAddress.toUpperCase() : "")));
        stringBuilder.append("TEL: ");
        stringBuilder.append(CommonUtils.isNotEmpty(companyPhone) ? companyPhone : "").append(" / ");
        stringBuilder.append("FAX: ");
        stringBuilder.append(CommonUtils.isNotEmpty(companyFax) ? companyFax : "");
        addrTable.addCell(makeCellCenterNoBorderFclBL(stringBuilder.toString()));
        addrTable.addCell(makeCellLeftNoBorderFclBL(""));
        addrTable.addCell(makeCellLeftNoBorderFclBL(""));
        invoiceFacturaTable.addCell(makeCellLeftNoBorderFclBL(""));
        cell = makeCell("INVOICE", Element.ALIGN_CENTER, new Font(Font.HELVETICA, 12, Font.BOLD, Color.RED),
                0.06f);
        invoiceFacturaTable.addCell(cell);
        invoiceFacturaTable.addCell(makeCellLeftNoBorderFclBL(""));
        cell = new PdfPCell();
        cell.addElement(invoiceFacturaTable);
        cell.setBorder(0);
        addrTable.addCell(cell);
        addrTable.addCell(makeCellLeftNoBorderFclBL(""));
        addrTable.addCell(makeCellLeftNoBorderFclBL(""));

        cell = new PdfPCell();
        cell.addElement(imgTable);
        cell.setBorder(0);
        cell.setPaddingLeft(+150);
        headingMainTable.addCell(cell);
        //            headingTable.addCell(cell);
        cell = new PdfPCell();
        cell.addElement(addrTable);
        cell.setBorder(0);
        headingTable.addCell(cell);
        cell = makeCellLeftNoBorderFclBL("");
        cell.setBorderWidthRight(0.06f);
        cell.setBorderWidthLeft(0.06f);
        cell.setBorderWidthTop(0.06f);
        cell.setBorderWidthBottom(0.0f);
        cell.addElement(headingTable);
        headingMainTable.addCell(cell);
        document.add(headingMainTable);
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

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

public String createReport(SearchBookingReportDTO searchBookingReportDTO, String simpleRequest,
        MessageResources messageResources, String printFromBl, String documentName) throws Exception {
    try {/*from   ww  w .  ja  v a2 s.com*/
        this.initialize(searchBookingReportDTO, simpleRequest, messageResources, documentName);
        this.createBody(searchBookingReportDTO, simpleRequest, messageResources, printFromBl, documentName);
        this.destroy();
    } catch (Exception e) {
        log.info("create FCL Booking Cover Note failed on " + new Date(), e);
        throw new ExceptionConverter(e);
    }
    return searchBookingReportDTO.getFileName();
}

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

public void onStartPage(PdfWriter writer, Document document) {
    try {/* w  w  w .ja va 2s . c  om*/

        PdfPCell cell = new PdfPCell();
        PdfPCell celL = new PdfPCell();
        PdfPTable table = new PdfPTable(1);
        FclBl fclBl = null;
        String brand = "";
        String path = LoadLogisoftProperties.getProperty("application.image.logo");
        String econoPath = LoadLogisoftProperties.getProperty("application.image.econo.logo");
        String companyCode = new SystemRulesDAO().getSystemRulesByCode("CompanyCode");
        BookingFcl bookingFcl = searchBookingReportDTO.getBookingflFcl();
        fclBl = new FclBlDAO().getOriginalBl(bookingFcl.getFileNo());
        if (null != fclBl && null != fclBl.getBrand()) {
            brand = fclBl.getBrand();
        } else if (null != bookingFcl && null != bookingFcl.getBrand()) {
            brand = bookingFcl.getBrand();
        }
        if (brand.equals("Econo") && ("03").equals(companyCode)) {
            Image img = Image.getInstance(searchBookingReportDTO.getContextPath() + econoPath);
            table.setWidthPercentage(100);
            img.scalePercent(60);
            //img.scaleAbsoluteWidth(200);
            celL.addElement(new Chunk(img, 180, -20));
            celL.setBorder(0);
            celL.setHorizontalAlignment(Element.ALIGN_CENTER);
            celL.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(celL);
            //            DateFormat df7 = new SimpleDateFormat("dd-MMM-yyyy HH:mm a");
            //            Date currentDate = new Date();
            //            cell = makeCellRightNoBorder("Date Printed : " + df7.format(currentDate));
            cell = makeCellRightNoBorder("  ");
            cell.setPaddingTop(10f);
            table.addCell(cell);
        } else if (brand.equals("OTI") && ("02").equals(companyCode)) {
            Image img = Image.getInstance(searchBookingReportDTO.getContextPath() + econoPath);
            table.setWidthPercentage(100);
            img.scalePercent(60);
            //img.scaleAbsoluteWidth(200);
            celL.addElement(new Chunk(img, 180, -20));
            celL.setBorder(0);
            celL.setHorizontalAlignment(Element.ALIGN_CENTER);
            celL.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(celL);
            //            DateFormat df7 = new SimpleDateFormat("dd-MMM-yyyy HH:mm a");
            //            Date currentDate = new Date();
            //            cell = makeCellRightNoBorder("Date Printed : " + df7.format(currentDate));
            cell = makeCellRightNoBorder("  ");
            cell.setPaddingTop(10f);
            table.addCell(cell);
        } else if (brand.equalsIgnoreCase("Ecu Worldwide")) {
            Image img = Image.getInstance(searchBookingReportDTO.getContextPath() + path);
            table.setWidthPercentage(100);
            img.scalePercent(60);
            //img.scaleAbsoluteWidth(200);
            celL.addElement(new Chunk(img, 180, -20));
            celL.setBorder(0);
            celL.setHorizontalAlignment(Element.ALIGN_CENTER);
            celL.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(celL);
            //            DateFormat df7 = new SimpleDateFormat("dd-MMM-yyyy HH:mm a");
            //            Date currentDate = new Date();
            //            cell = makeCellRightNoBorder("Date Printed : " + df7.format(currentDate));
            cell = makeCellRightNoBorder("  ");
            cell.setPaddingTop(10f);
            table.addCell(cell);
        }

        // table for heading
        //            PdfPTable heading = makeTable(1);
        //            heading.setWidthPercentage(100);            
        //             heading.addCell(makeCellCenterForDoubleHeading("FCL Booking Confirmation " + messageResources.getMessage("fileNumberPrefix") + String.valueOf(bookingFcl.getFileNo())));
        //            
        document.add(table);
        //            document.add(heading);
    } catch (Exception e) {
        log.info("onStartPage failed on " + new Date(), e);
        throw new ExceptionConverter(e);
    }
}

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

@Override
public void onEndPage(PdfWriter writer, Document document) {
    try {//from w w  w  .  jav  a 2s.  c  o  m

        //---------------
        //this for print page number at the bottom in the format x of y
        //            PdfContentByte cb = writer.getDirectContent();
        //            cb.saveState();
        //            String text = "Page " + writer.getPageNumber() + " of ";
        //            float textBase = document.bottom() - (document.bottomMargin() - 10);
        //            //float textBase = document.bottom() - 20;
        //            float textSize = helv.getWidthPoint(text, 12);
        //            cb.beginText();
        //            cb.setFontAndSize(helv, 7);
        //            cb.setTextMatrix(document.left() + 280, textBase);
        //            cb.showText(text);
        //            cb.endText();
        //            cb.addTemplate(total, document.left() + 260 + textSize, textBase);
        //            cb.restoreState();
    } catch (Exception e) {
        log.info("onEndPage failed on " + new Date(), e);
        throw new ExceptionConverter(e);
    }
}