Example usage for com.itextpdf.text.pdf PdfWriter getDirectContentUnder

List of usage examples for com.itextpdf.text.pdf PdfWriter getDirectContentUnder

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfWriter getDirectContentUnder.

Prototype


public PdfContentByte getDirectContentUnder() 

Source Link

Document

Use this method to get the direct content under for this document.

Usage

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * prints a footer table with a line at the top, a date and page numbering, second cell will be right aligned
 *
 * @see #PAGEFOOTERTABLEKEY/*from  w ww. j  a va  2 s .com*/
 * @see #PAGEFOOTERSTYLEKEY
 *
 * @param writer
 * @param document
 * @throws DocumentException
 * @throws VectorPrintException
 */
protected void renderFooter(PdfWriter writer, Document document)
        throws DocumentException, VectorPrintException, InstantiationException, IllegalAccessException {
    if (!debugHereAfter && !failuresHereAfter) {
        PdfPTable footerTable = elementProducer.createElement(null, PdfPTable.class,
                getStylers(PAGEFOOTERTABLEKEY));

        footerTable.addCell(createFooterCell(ValueHelper.createDate(new Date())));

        String pageText = writer.getPageNumber() + getSettings().getProperty(" of ", UPTO);

        PdfPCell c = createFooterCell(pageText);
        c.setHorizontalAlignment(Element.ALIGN_RIGHT);
        footerTable.addCell(c);

        footerTable.addCell(createFooterCell(new Chunk()));
        footerTable.writeSelectedRows(0, -1, document.getPageSize().getLeft() + document.leftMargin(),
                document.getPageSize().getBottom(document.bottomMargin()), writer.getDirectContentUnder());
        footerBottom = document.bottom() - footerTable.getTotalHeight();
    }
}

From source file:ConexionBD.CreaPrefichaPDF.java

public ByteArrayOutputStream ElaboraPreficha(String curp, ServletContext d) throws IOException {
    System.out.println("Elaborando preficha....");

    PrefichaModel prefichaR = VerificaDAO.recuperaPreficha(Constants.BD_NAME, Constants.BD_PASS, curp);
    Paragraph vacio = new Paragraph("  ", FontFactory.getFont("arial", 10, Font.BOLD));
    vacio.setAlignment(Element.ALIGN_CENTER);
    Document preficha = new Document();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {//from w  ww  . j  a  va2 s  .c  om
        PdfWriter writer = PdfWriter.getInstance(preficha, baos);
        preficha.open();
        Paragraph depto = new Paragraph("Departamento de servicios escolares",
                FontFactory.getFont("arial", 20, Font.BOLD));
        depto.setAlignment(Element.ALIGN_CENTER);
        preficha.add(depto);

        PdfContentByte rectangulo_general = writer.getDirectContentUnder();
        rectangulo_general.rectangle(50, 48, 500, 710);
        rectangulo_general.fill();
        drawRectangleSC(rectangulo_general, 50, 48, 500, 710);

        if (prefichaR.getExiste() == 1) {
            preficha.add(vacio);
            preficha.add(vacio);
            Paragraph periodo_text = new Paragraph(
                    "Convocatoria de nuevo ingreso periodo: " + prefichaR.getPeriodobd(),
                    FontFactory.getFont("arial", 10, Font.BOLD));
            periodo_text.setAlignment(Element.ALIGN_CENTER);
            preficha.add(periodo_text);

            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph fotografia = new Paragraph("", FontFactory.getFont("arial", 10, Font.BOLD));
            fotografia.setAlignment(Element.ALIGN_CENTER);
            preficha.add(fotografia);
            preficha.add(vacio);
            String url_logo = "/Imagenes/itt_logo_opt.jpg";
            String absolute_url_logo = d.getRealPath(url_logo);
            Image itt_logo = Image.getInstance(absolute_url_logo);

            Image Logo_itt = Image.getInstance(itt_logo);
            Logo_itt.setAbsolutePosition(260f, 640f);
            preficha.add(Logo_itt);

            PdfContentByte rectangulo_periodo = writer.getDirectContentUnder();
            rectangulo_periodo.rectangle(125, 725, 350, 20);
            rectangulo_periodo.fill();
            drawRectangleSC(rectangulo_periodo, 125, 725, 350, 20);

            String url_logo_bnmx = "/Imagenes/bnmx_color_opt.jpg";
            String absolute_url_logo_bnmx = d.getRealPath(url_logo_bnmx);
            Image bnmx_logo = Image.getInstance(absolute_url_logo_bnmx);

            Image Logo_banco = Image.getInstance(bnmx_logo);
            Logo_banco.setAbsolutePosition(380f, 310f);
            preficha.add(Logo_banco);

            preficha.add(vacio);

            PdfContentByte fechaimpr = writer.getDirectContentUnder();
            fechaimpr.rectangle(416, 635, 100, 35);
            fechaimpr.fill();
            drawRectangleSC(fechaimpr, 416, 635, 100, 35);

            Paragraph fechapdf_impr = new Paragraph("\tFecha de impresin                ",
                    FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD));
            fechapdf_impr.setAlignment(Element.ALIGN_RIGHT);
            preficha.add(fechapdf_impr);

            Paragraph fechapdf_fec = new Paragraph(
                    "\t" + prefichaR.getFechapdf() + "                          ",
                    FontFactory.getFont("arial", 10, com.itextpdf.text.Font.BOLD));
            fechapdf_fec.setAlignment(Element.ALIGN_RIGHT);
            preficha.add(fechapdf_fec);

            preficha.add(vacio);

            Paragraph no_preficha = new Paragraph("Preficha N: " + prefichaR.getPrefichabd(),
                    FontFactory.getFont("arial", 20, Font.BOLD));
            no_preficha.setAlignment(Element.ALIGN_CENTER);
            preficha.add(no_preficha);

            preficha.add(vacio);

            PdfContentByte rectangulo_preficha_no = writer.getDirectContentUnder();
            rectangulo_preficha_no.rectangle(85, 590, 430, 25);
            rectangulo_preficha_no.fill();
            drawRectangleSC(rectangulo_preficha_no, 85, 590, 430, 25);

            PdfContentByte rectangulo_datos = writer.getDirectContentUnder();
            rectangulo_datos.rectangle(85, 480, 430, 105);
            rectangulo_datos.fill();
            drawRectangleSC(rectangulo_datos, 85, 480, 430, 105);

            Paragraph nombre = new Paragraph(
                    "                                                                              Nombre:   "
                            + prefichaR.getNombrebd(),
                    FontFactory.getFont("arial", 10, Font.BOLD));
            nombre.setAlignment(Element.ALIGN_LEFT);
            preficha.add(nombre);

            Paragraph apellidos = new Paragraph(
                    "                                                                                               "
                            + prefichaR.getApellidosbd(),
                    FontFactory.getFont("arial", 10, Font.BOLD));
            apellidos.setAlignment(Element.ALIGN_LEFT);
            preficha.add(apellidos);

            Paragraph CURP = new Paragraph(
                    "                                                                                 CURP:   "
                            + prefichaR.getCurpbd(),
                    FontFactory.getFont("arial", 10, Font.BOLD));
            CURP.setAlignment(Element.ALIGN_LEFT);
            preficha.add(CURP);

            Paragraph carrera = new Paragraph("Carrera Solicitada:",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            carrera.setAlignment(Element.ALIGN_CENTER);
            preficha.add(carrera);

            Paragraph Nomcarrera = new Paragraph(prefichaR.getCarrerabd(),
                    FontFactory.getFont("arial", 10, Font.BOLD));
            Nomcarrera.setAlignment(Element.ALIGN_CENTER);
            preficha.add(Nomcarrera);

            Paragraph modalidad = new Paragraph(
                    "                                                                          Modalidad:   "
                            + prefichaR.getModalidadbd(),
                    FontFactory.getFont("arial", 10, Font.BOLD));
            modalidad.setAlignment(Element.ALIGN_LEFT);
            preficha.add(modalidad);

            preficha.add(vacio);
            //                    preficha.add(vacio);

            Paragraph formatoBanamex = new Paragraph(
                    "\nFORMATO UNIVERSAL PARA DEPSITOS EN SUCURSALES BANAMEX",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            formatoBanamex.setAlignment(Element.ALIGN_CENTER);
            preficha.add(formatoBanamex);

            PdfContentByte rectanguloDepositoB = writer.getDirectContentUnder();
            rectanguloDepositoB.rectangle(85, 440, 430, 20);
            rectanguloDepositoB.fill();
            drawRectangle(rectanguloDepositoB, 85, 440, 430, 20);

            PdfContentByte rectanguloPago = writer.getDirectContentUnder();
            rectanguloPago.rectangle(85, 250, 430, 190);
            rectanguloPago.fill();
            drawRectangleSC(rectanguloPago, 85, 250, 430, 190);

            preficha.add(vacio);

            PdfContentByte rectanguloConcepto = writer.getDirectContentUnder();
            rectanguloConcepto.rectangle(150, 395, 295, 35);
            rectanguloConcepto.fill();
            drawRectangleSC(rectanguloConcepto, 150, 395, 295, 35);

            Paragraph formatoConceptoPre = new Paragraph("CONCEPTO: PAGO DE DERECHO A EXAMEN DE ADMISIN",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            formatoConceptoPre.setAlignment(Element.ALIGN_CENTER);
            preficha.add(formatoConceptoPre);
            Paragraph fechaEmision = new Paragraph("FECHA L?MITE DE PAGO: " + prefichaR.getFecha_limite_pago(),
                    FontFactory.getFont("arial", 10, Font.BOLD));
            fechaEmision.setAlignment(Element.ALIGN_CENTER);
            preficha.add(fechaEmision);

            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph importe = new Paragraph("IMPORTE A PAGAR: $" + prefichaR.getImporte_bd() + ".",
                    FontFactory.getFont("arial", 15, Font.BOLD));
            importe.setAlignment(Element.ALIGN_CENTER);
            preficha.add(importe);

            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);

            String ref = prefichaR.getRef_bancaria();

            Paragraph referencia = new Paragraph(
                    "                                                   REFERENCIA (B): " + ref,
                    FontFactory.getFont("arial", 10, Font.BOLD));
            referencia.setAlignment(Element.ALIGN_LEFT);
            preficha.add(referencia);

            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph atencion = new Paragraph("Atencin", FontFactory.getFont("arial", 15, Font.BOLD));
            atencion.setAlignment(Element.ALIGN_CENTER);
            preficha.add(atencion);

            PdfContentByte rectangulo_atencion = writer.getDirectContentUnder();
            rectangulo_atencion.rectangle(245, 198, 100, 25);
            rectangulo_atencion.fill();
            drawRectangle(rectangulo_atencion, 245, 198, 100, 25);

            PdfContentByte rectangulo_info = writer.getDirectContentUnder();
            rectangulo_info.rectangle(85, 60, 430, 100);
            rectangulo_info.fill();
            drawRectangle(rectangulo_info, 85, 60, 430, 120);

            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph informacion = new Paragraph(
                    "                        Para continuar con el proceso de preinscripcin deber:\n"
                            + "                           - Realizar el pago para su examen de admisin con la \"REFERENCIA\" que aparece\n"
                            + "                             en este documento en cualquier sucursal BANAMEX.\n"
                            + "                           - Recibir la notificacin en su correo electrnico y estar al pendiente de \n"
                            + "                             las notificaciones que sern enviadas al mismo de que el pago ya fue procesado \n"
                            + "                             para completar su proceso de preinscripcin.\n",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            informacion.setAlignment(Element.ALIGN_LEFT);
            preficha.add(informacion);

            preficha.addTitle("Preficha");
            preficha.addSubject("Instituto Tecnolgico de Toluca");
            preficha.addKeywords("Instituto Tecnolgico de Toluca");
            preficha.addAuthor("Departamento de Servicios escolares");
            preficha.addCreator("Departamento de Servicios escolares");
        } else {

            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph curpNoEncontrada = new Paragraph(
                    "                                                              Lo sentimos, no se encontraron "
                            + "                                                                                coincidencias con su clave CURP.",
                    FontFactory.getFont("arial", 14, Font.BOLD));
            curpNoEncontrada.setAlignment(Element.ALIGN_LEFT);
            preficha.add(curpNoEncontrada);

            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph curp_no = new Paragraph(curp, FontFactory.getFont("arial", 19, Font.PLAIN));
            curp_no.setAlignment(Element.ALIGN_CENTER);
            preficha.add(curp_no);
            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph lamenta = new Paragraph(""
                    + "El deparamento de servicios escolares lamenta los inconvenientes ocurridos al intentar recuperar su preficha."
                    + "", FontFactory.getFont("arial", 19, Font.BOLD));
            lamenta.setAlignment(Element.ALIGN_CENTER);
            preficha.add(lamenta);

            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph se_le_aconseja = new Paragraph("           RECOMENDACIONES",
                    FontFactory.getFont("arial", 14, Font.BOLD));
            se_le_aconseja.setAlignment(Element.ALIGN_LEFT);
            preficha.add(se_le_aconseja);

            Paragraph msjCurp = new Paragraph("\n"
                    + "              - Le aconsejamos revisar su CURP, ya que sin esta, no podr recuperar su preficha.\n"
                    + "              - Si el problema contina, acuda con esta hoja al departamento de SERVICIOS ESCOLARES (Edif.\n"
                    + "                X) de lunes a viernes de 9:00 a 18:00 horas, de lo contrario \n"
                    + "                haga su registro.\n"
                    + "              - Revise que en el proceso de registro cada paso se haya terminado correctamente\n"
                    + "              - Revise el manual de proceso de registro que se encuentra en la pgina www.ittoluca.edu.mx\n"
                    + "              - Revise el apartado de preguntas frecuentes que se encuentra en la pgina www.ittoluca.edu.mx\n"
                    + "              - En la seccin de contacto, se encuentran el telfono de contacto y la extensin.\n"
                    + "              - Otra alternativa es enviar un correo exponiendo su situacin al departamento de servicios \n"
                    + "                escolares." + "\n" + "" + "",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            msjCurp.setAlignment(Element.ALIGN_LEFT);
            preficha.add(msjCurp);

            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);

            Paragraph no_comprobante = new Paragraph(""
                    + "Este documento carece de validz oficial, su funcin es servir como medio de comunicacin.",
                    FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.RED));
            no_comprobante.setAlignment(Element.ALIGN_CENTER);
            preficha.add(no_comprobante);

            //                    preficha.add(vacio);
            String url_logo = "/Imagenes/itt_logo_opt.jpg";
            String absolute_url_logo = d.getRealPath(url_logo);
            Image itt_logo = Image.getInstance(absolute_url_logo);

            Image Logo_itt = Image.getInstance(itt_logo);
            Logo_itt.setAbsolutePosition(140f, 640f);
            preficha.add(Logo_itt);
        }
        preficha.close();
        return baos;
    } catch (DocumentException docE) {
        throw new IOException(docE.getMessage());
    }
}

From source file:gov.utah.dts.det.ccl.actions.facility.information.license.reports.LicenseCertificate.java

private static void writePdf(License license, ByteArrayOutputStream ba, HttpServletRequest request)
        throws DocumentException, BadElementException {
    SimpleDateFormat df = new SimpleDateFormat("MMMM d, yyyy");
    StringBuilder sb;//from  w ww .  j a v  a2  s  .  c  o  m

    // Retrieve the certificate template to use as watermark
    ServletContext context = request.getSession().getServletContext();
    String templatefile = context.getRealPath("/resources") + "/LicenseCertificateTemplate.pdf";
    PdfReader reader = getTemplateReader(templatefile);
    if (reader != null && reader.getNumberOfPages() > 0) {
        Phrase phrase;

        // Create new document using the page size of the certificate template document
        Document document = new Document(reader.getPageSizeWithRotation(1), 0, 0, 0, 0);
        PdfWriter writer = PdfWriter.getInstance(document, ba);
        document.open();

        // Get the writer under content byte for placing of watermark
        PdfContentByte under = writer.getDirectContentUnder();
        PdfContentByte over = writer.getDirectContent();

        // Retrieve the first page of the template document and wrap as an Image to use as new document watermark
        PdfImportedPage page = writer.getImportedPage(reader, 1);
        Image img = Image.getInstance(page);
        // Make sure the image has an absolute page position
        if (!img.hasAbsoluteX() || !img.hasAbsoluteY()) {
            img.setAbsolutePosition(0, 0);
        }

        under.addImage(img);

        /*
         * THE FOLLOWING TWO FUNCTION CALLS DISPLAY THE PAGE MARGINS AND TEXT COLUMN BORDERS FOR DEBUGGING TEXT PLACEMENT.
         * UNCOMMENT EACH FUNCTION CALL TO HAVE BORDERS DISPLAYED ON THE OUTPUT DOCUMENT.  THIS WILL HELP WHEN YOU NEED
         * TO SEE WHERE TEXT WILL BE PLACED ON THE CERTIFICATE FORM.
         */
        // Show the page margins
        //showPageMarginBorders(over);

        // Show the text column borders
        //showColumnBorders(over);

        ColumnText ct = new ColumnText(over);
        ct.setLeading(fixedLeading);

        // Add Facility Name to column
        String text = license.getFacility().getName();
        if (text != null) {
            phrase = new Phrase(text.toUpperCase(), mediumfontB);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }
        // Add Facility Site to column
        text = license.getFacility().getSiteName();
        if (text != null) {
            phrase = new Phrase(text.toUpperCase(), mediumfontB);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }
        // Add Facility Address to column
        text = license.getFacility().getLocationAddress().getAddressOne();
        if (text != null) {
            phrase = new Phrase(text.toUpperCase(), mediumfontB);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }
        text = license.getFacility().getLocationAddress().getCityStateZip();
        if (text != null) {
            phrase = new Phrase(text.toUpperCase(), mediumfontB);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }
        // Write column to document
        ct.setAlignment(Element.ALIGN_CENTER);
        ct.setSimpleColumn(COLUMNS[0][0], COLUMNS[0][1], COLUMNS[0][2], COLUMNS[0][3]);
        ct.go();

        // Add Certification Service Code to column
        ct = new ColumnText(over);
        ct.setLeading(fixedLeading);
        String service = "";
        if (license.getSpecificServiceCode() != null
                && StringUtils.isNotBlank(license.getSpecificServiceCode().getValue())
                && DV_TREATMENT.equalsIgnoreCase(license.getSpecificServiceCode().getValue())) {
            service += DOMESTIC_VIOLENCE;
        }
        if (!license.getProgramCodeIds().isEmpty()) { // redmine 25410
            mentalHealthLoop: for (PickListValue pkv : license.getProgramCodeIds()) {
                String program = pkv.getValue();
                int idx = program.indexOf(" -");
                if (idx >= 0) {
                    String code = program.substring(0, idx);
                    if (MENTAL_HEALTH_CODES.indexOf(code + ":") >= 0) {
                        if (service.length() > 0) {
                            service += " / ";
                        }
                        service += MENTAL_HEALTH;
                        break mentalHealthLoop;
                    }
                }
            }
            substanceAbuseLoop: for (PickListValue pkv : license.getProgramCodeIds()) {
                String program = pkv.getValue();
                int idx = program.indexOf(" -");
                if (idx >= 0) {
                    String code = program.substring(0, idx);
                    if (SUBSTANCE_ABUSE_CODES.indexOf(code + ":") >= 0) {
                        if (service.length() > 0) {
                            service += " / ";
                        }
                        service += SUBSTANCE_ABUSE;
                        break substanceAbuseLoop;
                    }
                }
            }
        }
        if (StringUtils.isNotBlank(license.getServiceCodeDesc())) {
            if (service.length() > 0) {
                service += " / ";
            }
            service += license.getServiceCodeDesc();
        }
        if (StringUtils.isNotEmpty(service)) {
            phrase = new Phrase(service.toUpperCase(), mediumfont);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }

        // Add CLIENTS Info to column
        sb = new StringBuilder("FOR ");
        if (license.getAgeGroup() == null
                || license.getAgeGroup().getValue().equalsIgnoreCase("Adult & Youth")) {
            // Adult & Youth
            if (license.getAdultTotalSlots() != null) {
                sb.append(license.getAdultTotalSlots().toString());
            }
            sb.append(" ADULT AND YOUTH CLIENTS");
        } else if (license.getAgeGroup().getValue().equalsIgnoreCase("Adult")) {
            // Adult
            if (license.getAdultTotalSlots() != null) {
                // Are male or female counts specified?
                sb.append(license.getAdultTotalSlots().toString());
                sb.append(" ADULT");
                if (license.getAdultFemaleCount() != null || license.getAdultMaleCount() != null) {
                    // Does either the male or female count equal the total slot count?
                    if ((license.getAdultFemaleCount() != null
                            && license.getAdultFemaleCount().equals(license.getAdultTotalSlots()))) {
                        sb.append(" FEMALE CLIENTS");
                    } else if (license.getAdultMaleCount() != null
                            && license.getAdultMaleCount().equals(license.getAdultTotalSlots())) {
                        sb.append(" MALE CLIENTS");
                    } else {
                        sb.append(" CLIENTS, ");
                        if (license.getAdultMaleCount() != null) {
                            sb.append(license.getAdultMaleCount().toString() + " MALE");
                        }
                        if (license.getAdultFemaleCount() != null) {
                            if (license.getAdultMaleCount() != null) {
                                sb.append(" AND ");
                            }
                            sb.append(license.getAdultFemaleCount().toString() + " FEMALE");
                        }
                        if (license.getFromAge() != null || license.getToAge() != null) {
                            sb.append(",");
                        }
                    }
                } else {
                    sb.append(" CLIENTS");
                }
            } else {
                sb.append(" ADULT CLIENTS");
            }
        } else {
            // Youth
            if (license.getYouthTotalSlots() != null) {
                // Are male or female counts specified?
                sb.append(license.getYouthTotalSlots().toString());
                sb.append(" YOUTH");
                if (license.getYouthFemaleCount() != null || license.getYouthMaleCount() != null) {
                    // Does either the male or female count equal the total slot count?
                    if ((license.getYouthFemaleCount() != null
                            && license.getYouthFemaleCount().equals(license.getYouthTotalSlots()))) {
                        sb.append(" FEMALE CLIENTS");
                    } else if (license.getYouthMaleCount() != null
                            && license.getYouthMaleCount().equals(license.getYouthTotalSlots())) {
                        sb.append(" MALE CLIENTS");
                    } else {
                        sb.append(" CLIENTS, ");
                        if (license.getYouthMaleCount() != null) {
                            sb.append(license.getYouthMaleCount().toString() + " MALE");
                        }
                        if (license.getYouthFemaleCount() != null) {
                            if (license.getYouthMaleCount() != null) {
                                sb.append(" AND ");
                            }
                            sb.append(license.getYouthFemaleCount().toString() + " FEMALE");
                        }
                        if (license.getFromAge() != null || license.getToAge() != null) {
                            sb.append(",");
                        }
                    }
                } else {
                    sb.append(" CLIENTS");
                }
            } else {
                sb.append(" YOUTH CLIENTS");
            }
        }
        if (license.getFromAge() != null || license.getToAge() != null) {
            sb.append(" AGES ");
            if (license.getFromAge() != null) {
                sb.append(license.getFromAge().toString());
                if (license.getToAge() != null) {
                    sb.append(" TO " + license.getToAge().toString());
                } else {
                    sb.append(" AND OLDER");
                }
            } else {
                sb.append("TO " + license.getToAge().toString());
            }
        }
        phrase = new Phrase(sb.toString(), mediumfont);
        phrase.setLeading(noLeading);
        ct.addText(phrase);
        ct.addText(Chunk.NEWLINE);

        // Add Certificate Comments
        if (StringUtils.isNotBlank(license.getCertificateComment())) {
            phrase = new Phrase(license.getCertificateComment().toUpperCase(), mediumfont);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
        }

        // Write column to document
        ct.setAlignment(Element.ALIGN_CENTER);
        ct.setSimpleColumn(COLUMNS[1][0], COLUMNS[1][1], COLUMNS[1][2], COLUMNS[1][3]);
        ct.go();

        // Add Certificate Start Date
        if (license.getStartDate() != null) {
            phrase = new Phrase(df.format(license.getStartDate()), mediumfont);
            phrase.setLeading(noLeading);
            ct = new ColumnText(over);
            ct.setSimpleColumn(phrase, COLUMNS[2][0], COLUMNS[2][1], COLUMNS[2][2], COLUMNS[2][3], fixedLeading,
                    Element.ALIGN_RIGHT);
            ct.go();
        }

        // Add Certificate End Date
        if (license.getEndDate() != null) {
            phrase = new Phrase(df.format(license.getEndDate()), mediumfont);
            phrase.setLeading(noLeading);
            ct = new ColumnText(over);
            ct.setSimpleColumn(phrase, COLUMNS[3][0], COLUMNS[3][1], COLUMNS[3][2], COLUMNS[3][3], fixedLeading,
                    Element.ALIGN_LEFT);
            ct.go();
        }

        // Add License Number
        if (license.getLicenseNumber() != null) {
            phrase = new Phrase(license.getLicenseNumber().toString(), largefontB);
            phrase.setLeading(noLeading);
            ct = new ColumnText(over);
            ct.setSimpleColumn(phrase, COLUMNS[4][0], COLUMNS[4][1], COLUMNS[4][2], COLUMNS[4][3],
                    numberLeading, Element.ALIGN_CENTER);
            ct.go();
        }
        document.close();
    }
}

From source file:gravabncertificado.GerandoArquivoCarimbado_1.java

public static void GerandoArquivoCarimbadoPDF(String caminhoarquivo, String BN) throws InvalidPdfException {
    //Copiando arquivo informado.
    try {/*from   w  w  w.  j a va 2 s. c  o  m*/

        // Adicionado parametro para nao retornar erro quando o documento for protegido.
        PdfReader.unethicalreading = true;
        //Cria o reader para o primeiro PDF

        PdfReader reader = new PdfReader(caminhoarquivo);

        // n recebe o numero total de paginas
        int n = reader.getNumberOfPages();

        //Tamanho da primeira Pagina
        ;

        //Cria Segundo PDF

        Document document = new Document(PageSize.A4, 36, 36, 36, 36);

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf"));

        document.open();

        // Adiciona conteudo ao PDF Carimbado.
        PdfContentByte cb = writer.getDirectContent();
        int i = 0;
        int p = 0;
        String caminhodestino = (caminhoarquivo.substring(0, caminhoarquivo.length() - BN.length()));

        // DESABILITADO PORQUE O MOVER NAO ESTAVA FUNCIONANDO.
        File destinooriginal = new File(caminhodestino + "ORIGINAL\\");
        if (!destinooriginal.exists()) {
            destinooriginal.mkdir();
        }

        caminhodestino = (caminhodestino + "ORIGINAL\\" + BN);

        //TESTANDO NOVA FORMA DE COPIAR

        File origem = new File(caminhoarquivo);
        File destino = new File(caminhodestino);

        FileInputStream fis = new FileInputStream(origem);
        FileOutputStream fos = new FileOutputStream(destino);

        FileChannel inChannel = fis.getChannel();
        FileChannel outChannel = fos.getChannel();

        long transferFrom = outChannel.transferFrom(inChannel, 0, inChannel.size());

        fis.close();
        fos.close();
        inChannel.close();
        outChannel.close();

        // Thread.sleep(10);

        BN = BN.substring(0, BN.length() - 4);

        while (i < n) {
            document.newPage();
            p++;
            i++;

            PdfContentByte under = writer.getDirectContentUnder();
            PdfImportedPage page1 = writer.getImportedPage(reader, i);
            cb.addTemplate(page1, 0, i * 0.2f);

            // Page 1: a rectangle
            /* RETANGULO DESATIVADO
            drawRectangle(under, 100, 50);
            under.setRGBColorFill(255, 220, 220);
            under.rectangle(width /50, 5, 118, 40);
            under.fill();
            */

            //CARIMBO DA BN

            BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            cb.beginText();
            cb.setFontAndSize(bf, 14);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 32, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 22, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 12, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0);
            cb.endText();

        }

        document.close();
        writer.close();
        reader.close();
        origem.delete();

        /* PdfContentByte under = writer.getDirectContentUnder();
                 
         // Page 1: a rectangle
             drawRectangle(under, 20, 20);
             under.setRGBColorFill(0xFF, 0xD7, 0x00);
             under.rectangle(5, 5, 15, 15);
             under.fill(); */
        //document.newPage();

        //COPIANDO ARQUIVO CARIMBADO

        /* DESABILITADO PORQUE NAO ESTAVA FUNCIONANDO.
        boolean bool;
                
         //caminhoarquivo = caminhoarquivo.replace("\\", "\\\\");
         //caminhodestino = caminhodestino.replace("\\", "\\\\");
                    
        File origem = new File(caminhoarquivo);
        File destino = new File(caminhodestino);
                
                    
        bool = origem.renameTo(destino);
        System.out.println(origem);
        System.out.println(caminhodestino);
        */

    } catch (IOException | DocumentException ex) {
    }

}

From source file:gravabncertificado007.CarimboCertificado.java

public void aplicaCarimboBin(String BN, String caminhoarquivo)
        throws DocumentException, IOException, RuntimeException {

    PdfReader.unethicalreading = true;/*from w  ww . j a  va2 s .c  o  m*/
    //Cria o reader para o primeiro PDF

    PdfReader reader = new PdfReader(caminhoarquivo);
    Rectangle psize = reader.getPageSize(1);
    float width = psize.getWidth();
    float height = psize.getHeight();

    Document document = new Document(new Rectangle(width, height));

    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf"));

    document.open();

    int i = 0;
    BN = BN.substring(BN.length() - 13, BN.length() - 4);
    PdfContentByte cb = writer.getDirectContent();
    while (i < reader.getNumberOfPages()) {
        i++;

        document.newPage();

        PdfContentByte under = writer.getDirectContentUnder();
        PdfImportedPage page1 = writer.getImportedPage(reader, i);
        cb.addTemplate(page1, 0, i * 0.2f);

        //CARIMBO DA BN
        BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 14);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 32, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 22, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 12, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0);
        cb.endText();

    }

    document.close();
    writer.close();
    reader.close();

}

From source file:gravabncertificado007.CarimboCertificado.java

public void aplicaCariboGedi(String BN, String caminhoarquivo)
        throws DocumentException, IOException, RuntimeException {

    PdfReader.unethicalreading = true;//  ww w .  ja v a2s . co m
    //Cria o reader para o primeiro PDF

    PdfReader reader = new PdfReader(caminhoarquivo);
    Rectangle psize = reader.getPageSize(1);
    float width = psize.getWidth();
    float height = psize.getHeight();

    Document document = new Document(new Rectangle(width, height));

    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-G.pdf"));

    document.open();

    int i = 0;
    BN = BN.substring(BN.length() - 13, BN.length() - 4);
    PdfContentByte cb = writer.getDirectContent();
    while (i < reader.getNumberOfPages()) {
        i++;

        document.newPage();

        PdfContentByte under = writer.getDirectContentUnder();
        PdfImportedPage page1 = writer.getImportedPage(reader, i);
        cb.addTemplate(page1, 0, i * 0.2f);

        BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 14);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "  _________________  ", width / 6, 44, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 32, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 22, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |Copia Controlada |", width / 6, 28, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 16, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 12, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |_________________|", width / 6, 14, 0);
        cb.endText();
    }

    document.close();
    writer.close();
    reader.close();

}

From source file:it.vige.magazzino.pdf.Format1DocumentReceipt.java

License:Apache License

@Model
public void build(Receipt receipt) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle("messages");

    Document document = new Document();
    ByteArrayOutputStream bytesOS = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, bytesOS);
    document.open();//from   w w  w .  j  a  va  2s .  c  o  m

    Font normalFont = new Font();
    Font headerFont = FontFactory.getFont(FontFactory.TIMES, 9);

    PdfContentByte canvas = writer.getDirectContentUnder();
    List<Data> imagesJar = receipt.getJar().getFiles();

    if (imagesJar != null && imagesJar.size() > 0) {
        Image image1 = Image.getInstance(imagesJar.get(0).getData());
        image1.setAbsolutePosition(166, 738);
        image1.scalePercent(60);
        document.add(image1);
        if (imagesJar.size() > 1) {
            Image image2 = Image.getInstance(imagesJar.get(1).getData());
            image2.setAbsolutePosition(326, 748);
            image2.scalePercent(40);
            document.add(image2);
        }
    }

    Phrase phrase1 = new Phrase(receipt.getJar().getRagSoc1(), normalFont);
    Phrase phrase2 = new Phrase(
            receipt.getJar().getAddress().getAddress() + " " + receipt.getJar().getAddress().getCivicNumber(),
            normalFont);
    Phrase phrase3 = new Phrase("Loc. " + receipt.getJar().getAddress().getTown() + " - "
            + receipt.getJar().getAddress().getCap() + " " + receipt.getJar().getAddress().getCity() + " ("
            + receipt.getJar().getAddress().getProvince() + ")", normalFont);
    Phrase phrase4 = new Phrase("Tel. " + receipt.getJar().getAddress().getPhone() + " r.a.Fax "
            + receipt.getJar().getAddress().getFax(), normalFont);
    Phrase phrase5 = new Phrase(
            receipt.getJar().getAddress().getSite() + " E-mail: " + receipt.getJar().getAddress().getEmail(),
            normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 36, 784, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 36, 774, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 36, 764, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 36, 754, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 36, 744, 0);

    Phrase phrase6 = new Phrase(bundle.getString("magazzino_iva") + " " + receipt.getJar().getIva(),
            normalFont);
    Phrase phrase7 = new Phrase(bundle.getString("magazzino_capsoc") + " " + receipt.getJar().getCapSoc()
            + " - " + bundle.getString("magazzino_reapi") + " n. " + receipt.getJar().getReaPI(), normalFont);
    Phrase phrase8 = new Phrase("Reg. Impr. PI n. " + receipt.getJar().getIva(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 36, 724, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 36, 714, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 36, 704, 0);

    Phrase phrase9 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase10 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase11 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase12 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase13 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase14 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase15 = new Phrase("prova 4: prova 4", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 664, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 36, 654, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 644, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 36, 634, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 624, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 36, 614, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 604, 0);

    List<Data> imagesCustomer = receipt.getCustomer().getFiles();

    if (imagesCustomer != null && imagesCustomer.size() > 0) {
        Image image3 = Image.getInstance(imagesCustomer.get(0).getData());
        image3.setAbsolutePosition(212, 664);
        image3.scalePercent(40);
        document.add(image3);
    }

    Phrase phrase16 = new Phrase(receipt.getCustomer().getName(), normalFont);
    Phrase phrase17 = new Phrase(receipt.getCustomer().getAddress().getAddress() + ", "
            + receipt.getCustomer().getAddress().getCivicNumber(), normalFont);
    Phrase phrase18 = new Phrase(
            receipt.getCustomer().getAddress().getCap() + " " + receipt.getCustomer().getAddress().getCity()
                    + " " + receipt.getCustomer().getAddress().getProvince(),
            normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 206, 644, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 206, 624, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 206, 604, 0);

    Phrase phrase19 = new Phrase("prova", normalFont);
    Phrase phrase20 = new Phrase("prova", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 316, 694, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 356, 694, 0);

    Phrase phrase21 = new Phrase(
            bundle.getString("customer_code").toUpperCase() + " " + bundle.getString("customer").toUpperCase(),
            headerFont);
    Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva").toUpperCase(), headerFont);
    Phrase phrase23 = new Phrase(bundle.getString("pdf_agent").toUpperCase(), headerFont);
    Phrase phrase24 = new Phrase(bundle.getString("pdf_number_receipt").toUpperCase(), headerFont);
    Phrase phrase25 = new Phrase(
            bundle.getString("receipt_date").toUpperCase() + " " + bundle.getString("receipt").toUpperCase(),
            headerFont);
    Phrase phrase26 = new Phrase(bundle.getString("pdf_number_page").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 24, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 100, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 176, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 390, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 466, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase26, 542, 540, 0);

    Phrase phrase27 = new Phrase("aaqaqaq", normalFont);
    Phrase phrase28 = new Phrase("cddcddcd", normalFont);
    Phrase phrase29 = new Phrase("cnjcndkd", normalFont);
    Phrase phrase30 = new Phrase(receipt.getCodeReceipt() + "", normalFont);
    Phrase phrase31 = new Phrase(receipt.getDate(), normalFont);
    Phrase phrase32 = new Phrase("tgsb", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase27, 36, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase28, 106, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase29, 176, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase30, 396, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase31, 470, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase32, 546, 530, 0);

    Phrase phrase33 = new Phrase("aaqaqaq", headerFont);
    Phrase phrase34 = new Phrase("cddcddcd", headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 24, 513, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 264, 513, 0);

    Phrase phrase35 = new Phrase("cnjcndkd", normalFont);
    Phrase phrase36 = new Phrase("dddedreqq", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 36, 503, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 276, 503, 0);

    Phrase phrase37 = new Phrase(bundle.getString("article_code").toUpperCase(), headerFont);
    Phrase phrase38 = new Phrase(bundle.getString("article_description").toUpperCase(), headerFont);
    Phrase phrase39 = new Phrase(bundle.getString("article_um").toUpperCase(), headerFont);
    Phrase phrase40 = new Phrase(bundle.getString("pdf_number_articles").toUpperCase(), headerFont);
    Phrase phrase41 = new Phrase(bundle.getString("article_prize").toUpperCase(), headerFont);
    Phrase phrase42 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont);
    Phrase phrase43 = new Phrase(bundle.getString("pdf_amount").toUpperCase(), headerFont);
    Phrase phrase44 = new Phrase(bundle.getString("pdf_iva").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase37, 47, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase38, 126, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase39, 286, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase40, 324, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase41, 373, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase42, 440, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 488, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 552, 480, 0);

    Phrase phrase45 = null;
    Phrase phrase46 = null;
    Phrase phrase47 = null;
    Phrase phrase48 = null;
    Phrase phrase49 = null;
    Phrase phrase50 = null;
    Phrase phrase51 = null;
    Phrase phrase52 = null;

    int i = 0;
    for (i = 0; i < 70; i = i + 15) {
        phrase45 = new Phrase("dgbsbb", normalFont);
        phrase46 = new Phrase("323232", normalFont);
        phrase47 = new Phrase("bbg", normalFont);
        phrase48 = new Phrase("wefwe", normalFont);
        phrase49 = new Phrase("ewrew", normalFont);
        phrase50 = new Phrase("ewr5", normalFont);
        phrase51 = new Phrase("dsadasd", normalFont);
        phrase52 = new Phrase("ds", normalFont);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase45, 59, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase46, 126, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase47, 280, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 306, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase49, 368, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 436, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase51, 480, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 556, 460 - i, 0);
    }

    int j = 298;
    if (i - 298 < 0)
        i = 298;
    else {
        j = i;
        i = 460 - i;
    }

    Phrase phrase81 = new Phrase(receipt.getCause(), normalFont);
    Phrase phrase82 = new Phrase(receipt.getDescription(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase81, 59, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase82, 326, i, 0);

    Phrase phrase53 = new Phrase(bundle.getString("pdf_total_goods").toUpperCase(), headerFont);
    Phrase phrase54 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont);
    Phrase phrase55 = new Phrase(bundle.getString("pdf_total_net").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase53, 26, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase54, 104, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase55, 182, i - 30, 0);

    Phrase phrase56 = new Phrase("opoppp", normalFont);
    Phrase phrase57 = new Phrase("2ws", normalFont);
    Phrase phrase58 = new Phrase("78900", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase56, 96, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase57, 176, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase58, 252, i - 50, 0);

    Phrase phrase59 = new Phrase(bundle.getString("pdf_expiries").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase59, 36, i - 70, 0);

    Phrase phrase60 = new Phrase("78900", normalFont);
    Phrase phrase61 = new Phrase("opoppp", normalFont);
    Phrase phrase62 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase60, 166, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase61, 166, i - 110, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase62, 166, i - 130, 0);

    Phrase phrase63 = new Phrase("78900", normalFont);
    Phrase phrase64 = new Phrase("opoppp", normalFont);
    Phrase phrase65 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase63, 256, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase64, 256, i - 110, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase65, 256, i - 130, 0);

    Phrase phrase66 = new Phrase(bundle.getString("pdf_transport").toUpperCase(), headerFont);
    Phrase phrase67 = new Phrase(bundle.getString("pdf_caching").toUpperCase(), headerFont);
    Phrase phrase68 = new Phrase(bundle.getString("pdf_various_costs").toUpperCase(), headerFont);
    Phrase phrase69 = new Phrase(bundle.getString("pdf_stamps").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase66, 260, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase67, 340, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase68, 418, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase69, 496, i - 30, 0);

    Phrase phrase70 = new Phrase("2ws", normalFont);
    Phrase phrase71 = new Phrase("78900", normalFont);
    Phrase phrase72 = new Phrase("opoppp", normalFont);
    Phrase phrase73 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase70, 300, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase71, 390, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase72, 468, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase73, 546, i - 50, 0);

    Phrase phrase74 = new Phrase(bundle.getString("article_imponible").toUpperCase(), headerFont);
    Phrase phrase75 = new Phrase(bundle.getString("pdf_tax").toUpperCase(), headerFont);
    Phrase phrase76 = new Phrase(bundle.getString("pdf_total_receipt").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase74, 260, i - 70, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase75, 352, i - 70, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase76, 484, i - 70, 0);

    Phrase phrase77 = new Phrase("2ws", normalFont);
    Phrase phrase78 = new Phrase("78900", normalFont);
    Phrase phrase79 = new Phrase("opoppp", normalFont);
    Phrase phrase80 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase77, 310, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase78, 352, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase79, 450, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase80, 536, i - 110, 0);

    PdfPTable table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    PdfPCell cell = new PdfPCell();
    cell.setPadding(127);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(6);
    table.getDefaultCell().setPadding(5);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 7, 7, 20, 7, 7, 3 });
    cell = new PdfPCell();
    cell.setPadding(14);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(2);
    table.getDefaultCell().setPadding(5);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 15.5f, 20 });
    cell = new PdfPCell();
    cell.setPadding(14);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(3);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(100);
    table.setWidths(new float[] { 23.5f, 2, 5, 6, 4, 7, 3 });
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(j * 8 - 2279);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(5);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(17);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(5);
    table.setWidths(new float[] { 10.5f, 4, 6, 4 });
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(48);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    document.close();

    HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
    response.setContentType("application/pdf");
    response.addHeader("Content-disposition",
            "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\"");

    ServletOutputStream os = response.getOutputStream();
    os.write(bytesOS.toByteArray());
    os.flush();
    os.close();

    facesContext.responseComplete();
}

From source file:it.vige.magazzino.pdf.Format2DocumentReceipt.java

License:Apache License

@Model
public void build(Receipt receipt) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle("messages");

    Document document = new Document();
    ByteArrayOutputStream bytesOS = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, bytesOS);

    document.open();/* ww  w . j  a v a 2  s  .  c om*/

    Font normalFont = new Font();

    PdfContentByte canvas = writer.getDirectContentUnder();
    List<Data> imagesJar = receipt.getJar().getFiles();

    if (imagesJar != null && imagesJar.size() > 0) {
        Image image1 = Image.getInstance(imagesJar.get(0).getData());
        image1.setAbsolutePosition(36, 742);
        image1.scalePercent(60);
        document.add(image1);
    }

    Phrase phrase1 = new Phrase(bundle.getString("pdf_number_receipt"), normalFont);
    Phrase phrase2 = new Phrase(receipt.getCodeReceipt() + "", normalFont);
    Phrase phrase3 = new Phrase(bundle.getString("receipt_date"), normalFont);
    Phrase phrase4 = new Phrase(receipt.getDate(), normalFont);
    Phrase phrase5 = new Phrase(receipt.getCause(), normalFont);
    Phrase phrase6 = new Phrase(receipt.getDescription(), normalFont);
    Phrase phrase7 = new Phrase(bundle.getString("customer_code") + " " + bundle.getString("customer"),
            normalFont);
    Phrase phrase8 = new Phrase("prova 4: prova 4", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 286, 797, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 386, 797, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 286, 777, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 386, 777, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 286, 757, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 386, 757, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 286, 737, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 386, 737, 0);

    Phrase phrase9 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase10 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase11 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase12 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase13 = new Phrase(bundle.getString("pdf_tel"), normalFont);
    Phrase phrase14 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase15 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont);
    Phrase phrase16 = new Phrase("prova 4: prova 4", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 718, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 136, 718, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 698, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 136, 698, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 678, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 136, 678, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 658, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 136, 658, 0);

    Phrase phrase17 = new Phrase("Ditta", normalFont);
    Phrase phrase18 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase19 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase20 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase21 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont);
    Phrase phrase23 = new Phrase("prova 2: ", normalFont);
    Phrase phrase24 = new Phrase(bundle.getString("pdf_cod_fisc"), normalFont);
    Phrase phrase25 = new Phrase("prova 2: ", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 236, 736, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 236, 708, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 236, 688, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 236, 668, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 386, 668, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 236, 648, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 286, 648, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 356, 648, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 416, 648, 0);

    Phrase phrase26 = new Phrase(bundle.getString("article_code"), normalFont);
    Phrase phrase27 = new Phrase(bundle.getString("article_description"), normalFont);
    Phrase phrase28 = new Phrase(bundle.getString("pdf_number_articles"), normalFont);
    Phrase phrase29 = new Phrase(bundle.getString("article_prize"), normalFont);
    Phrase phrase30 = new Phrase(bundle.getString("pdf_reduction"), normalFont);
    Phrase phrase31 = new Phrase(bundle.getString("pdf_amount"), normalFont);
    Phrase phrase32 = new Phrase(bundle.getString("pdf_iva"), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase26, 59, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase27, 146, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase28, 208, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase29, 280, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase30, 353, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase31, 422, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase32, 498, 618, 0);

    Phrase phrase33 = null;
    Phrase phrase34 = null;
    Phrase phrase35 = null;
    Phrase phrase36 = null;
    Phrase phrase37 = null;
    Phrase phrase38 = null;
    Phrase phrase39 = null;

    int i = 0;
    for (i = 0; i < 70; i = i + 15) {
        phrase33 = new Phrase("dsadasd", normalFont);
        phrase34 = new Phrase("dgbsbb", normalFont);
        phrase35 = new Phrase("323232", normalFont);
        phrase36 = new Phrase("bbgdbdfbdb", normalFont);
        phrase37 = new Phrase("wefwew", normalFont);
        phrase38 = new Phrase("ewrew", normalFont);
        phrase39 = new Phrase("ewr5", normalFont);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 59, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 136, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 196, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 266, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase37, 351, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase38, 416, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase39, 496, 598 - i, 0);
    }
    int j = 298;
    if (i - 298 < 0)
        i = 298;
    else {
        j = i;
        i = 588 - i;
    }
    Phrase phrase40 = new Phrase(bundle.getString("pdf_references").toUpperCase(), normalFont);
    Phrase phrase41 = new Phrase(bundle.getString("pdf_delivery").toUpperCase(), normalFont);
    Phrase phrase42 = new Phrase(bundle.getString("pdf_payments").toUpperCase(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase40, 105, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase41, 206, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase42, 316, i, 0);

    Phrase phrase43 = new Phrase("opoppp", normalFont);
    Phrase phrase44 = new Phrase("2ws", normalFont);
    Phrase phrase45 = new Phrase("78900", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 59, i - 20, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 186, i - 20, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase45, 276, i - 20, 0);

    Phrase phrase46 = new Phrase(bundle.getString("pdf_sign_producer").toUpperCase(), normalFont);
    Phrase phrase47 = new Phrase(bundle.getString("pdf_sign_receiver").toUpperCase(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase46, 154, i - 40, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase47, 321, i - 40, 0);

    Phrase phrase48 = new Phrase(bundle.getString("article_imponible"), normalFont);
    Phrase phrase49 = new Phrase("opoppp", normalFont);
    Phrase phrase50 = new Phrase(bundle.getString("pdf_tax"), normalFont);
    Phrase phrase51 = new Phrase("78900", normalFont);
    Phrase phrase52 = new Phrase(bundle.getString("pdf_total_receipt"), normalFont);
    Phrase phrase53 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 356, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase49, 566, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 356, i - 25, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase51, 566, i - 25, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 356, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase53, 566, i - 50, 0);

    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    PdfPCell cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(3);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(3);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 38, 48, 14 });
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(40);
    table.addCell(cell);
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    table.addCell(cell);
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(3);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(j * 8 - 2234);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(5);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 20, 20, 20, 20, 20 });
    cell = new PdfPCell();
    cell.setPadding(20);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 30, 30, 20, 20 });
    cell = new PdfPCell();
    cell.setPadding(20);
    table.addCell(cell);
    table.addCell(cell);
    cell.disableBorderSide(PdfPCell.TOP);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    document.close();

    HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
    response.setContentType("application/pdf");
    response.addHeader("Content-disposition",
            "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\"");

    ServletOutputStream os = response.getOutputStream();
    os.write(bytesOS.toByteArray());
    os.flush();
    os.close();

    facesContext.responseComplete();
}

From source file:jati.GerandoArquivoCarimbado.java

public static void GerandoArquivoCarimbadoPDF(String caminhoarquivo, String BN)
        throws InvalidPdfException, IOException {
    //Copiando arquivo informado.

    try {//from  w w  w.ja va 2  s .  c o m

        // Adicionado parametro para nao retornar erro quando o documento for protegido.
        PdfReader.unethicalreading = true;

        PdfWriter writer = PdfWriter.getInstance(montaraAquivo(caminhoarquivo),
                new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf"));
        // ABRE O DOCUMENTO CRIADO PARA MANUSEIO
        montaraAquivo(caminhoarquivo).open();

        //SUBSTRING RETIRA PARTE DO TEXTO ENTRE OS INDICES ESPECIFICADOS 
        //caminhoDestino RECEBE UM NOVO CAMINHO RESULTANTE DOS INDICES DE CAMINHO.LENGTH - BN.LENGTH
        // QUE FORMAM UMA NOVA STRING
        String caminhodestino = (caminhoarquivo.substring(0, caminhoarquivo.length() - BN.length()));

        File destinooriginal = new File(caminhodestino + "ORIGINAL\\");
        if (!destinooriginal.exists()) {
            destinooriginal.mkdir();
        }

        caminhodestino = (caminhodestino + "ORIGINAL\\" + BN);

        //TESTANDO NOVA FORMA DE COPIAR
        File origem = new File(caminhoarquivo);
        File destino = new File(caminhodestino);

        FileInputStream fis = new FileInputStream(origem);
        FileOutputStream fos = new FileOutputStream(destino);

        FileChannel inChannel = fis.getChannel();
        FileChannel outChannel = fos.getChannel();

        long transferFrom = outChannel.transferFrom(inChannel, 0, inChannel.size());

        fis.close();
        fos.close();
        inChannel.close();
        outChannel.close();

        // Thread.sleep(10);
        BN = BN.substring(0, BN.length() - 4);

        PdfContentByte cb = writer.getDirectContent();

        int i = 0;
        while (i < reader.getNumberOfPages()) {
            montaraAquivo(caminhodestino).newPage();

            i++;

            //PDFCONTETBYTE GERA UMA ESPECIE DE CODIGO DE BARRAS 
            PdfContentByte under = writer.getDirectContentUnder();
            PdfImportedPage page1 = writer.getImportedPage(reader, i);
            cb.addTemplate(page1, 0, i * 0.2f);

            //CARIMBO DA BN
            BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            cb.beginText();
            cb.setFontAndSize(bf, 14);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 32, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 22, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 12, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0);
            cb.endText();

        }

        montaraAquivo(caminhodestino).close();
        writer.close();
        reader.close();
        origem.delete();

    } catch (IOException | DocumentException ex) {
    }

}

From source file:org.cejug.yougi.web.report.EventAttendeeCertificate.java

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    writer.getDirectContentUnder().addTemplate(page, 0, 0);
}