Example usage for com.itextpdf.text FontFactory getFont

List of usage examples for com.itextpdf.text FontFactory getFont

Introduction

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

Prototype


public static Font getFont(final String fontname, final float size, final int style) 

Source Link

Document

Constructs a Font-object.

Usage

From source file:PrefichaPDF.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {//from  w  ww  .  j a  v  a  2 s  .co m
        response.setContentType("application/pdf");

        String curp = new String(request.getParameter("curp").getBytes("ISO-8859-1"), "UTF-8");

        ConexionOracle conexionOracle = new ConexionOracle();

        String sql = "select * from PERSONALDATA_ASP_TAB where curp=" + "'" + curp + "'";
        System.out.println(sql);
        System.out.println("Esta es la curp: " + curp);

        conexionOracle.conectar();
        Connection conn = conexionOracle.getConnection();
        // driver@machineName:port:SID           ,  userid,  password
        Statement stmt = conn.createStatement();

        ResultSet rset = stmt.executeQuery(sql);

        while (rset.next()) {

            fichabd = rset.getString("id_aspirante");
            periodobd = rset.getString("periodo_solicitud");
            prefichabd = rset.getString("preficha");
            nombrebd = rset.getString("nombre");
            String appat = rset.getString("apellido_pat");
            String apmat = rset.getString("apellido_mat");
            apellidosbd = appat + " " + apmat;
            curpbd = rset.getString("curp");
            carrerabd = rset.getString("carrera");
            modalidadbd = rset.getString("modalidad");
        }

        try {

            Document preficha = new Document();
            PdfWriter writer = PdfWriter.getInstance(preficha, response.getOutputStream());
            preficha.open();
            //encabezado
            //encabezado
            //encabezado
            //encabezado

            //                documento.add(vacio);
            //                documento.add(vacio);
            //                documento.add(vacio);
            Paragraph depto = new Paragraph("Departamento de servicios escolares",
                    FontFactory.getFont("arial", 20, Font.BOLD));
            depto.setAlignment(Element.ALIGN_CENTER);

            preficha.add(depto);

            Paragraph vacio = new Paragraph("  ", FontFactory.getFont("arial", 10, Font.BOLD));
            vacio.setAlignment(Element.ALIGN_CENTER);
            preficha.add(vacio);
            preficha.add(vacio);
            //                preficha.add(vacio);
            //cuerpo
            //cuerpo
            //cuerpo
            //cuerpo
            //cuerpo

            Paragraph periodo_text = new Paragraph("Convocatoria de nuevo ingreso periodo: " + periodobd,
                    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("Fotografa", FontFactory.getFont("arial", 10, Font.BOLD));
            fotografia.setAlignment(Element.ALIGN_CENTER);
            preficha.add(fotografia);

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

            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 = "/Imagenes/itt_logo_opt.jpg";
            String absolute_url_logo = getServletContext().getRealPath(url_logo);
            Image itt_logo = Image.getInstance(absolute_url_logo);

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

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

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

            PdfContentByte espacio_imagen = writer.getDirectContentUnder();
            espacio_imagen.rectangle(255, 635, 85, 80);
            espacio_imagen.fill();
            drawRectangleSC(espacio_imagen, 255, 635, 85, 80);

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

            PdfContentByte fechaimpr = writer.getDirectContentUnder();
            fechaimpr.rectangle(416, 635, 100, 35);
            fechaimpr.fill();
            drawRectangleSC(fechaimpr, 416, 635, 100, 35);
            //            drawRectangle(fechaimpr, 85, 530, 430, 25);

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

            Paragraph fechapdf_fec = new Paragraph("\t" + fecha_hoy() + "                          ",
                    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: " + prefichabd,
                    FontFactory.getFont("arial", 20, Font.BOLD));
            no_preficha.setAlignment(Element.ALIGN_CENTER);
            preficha.add(no_preficha);

            preficha.add(vacio);
            //                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, 500, 430, 80);
            //                rectangulo_datos.rec
            rectangulo_datos.fill();
            drawRectangleSC(rectangulo_datos, 85, 500, 430, 80);

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

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

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

            //                preficha.add(vacio);
            Paragraph carrera = new Paragraph(
                    "                                                            Carrera Solicitada:   "
                            + carrerabd,
                    FontFactory.getFont("arial", 10, Font.BOLD));
            carrera.setAlignment(Element.ALIGN_LEFT);
            preficha.add(carrera);

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

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

            Paragraph formatoBanamex = new Paragraph("FORMATO 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, 470, 430, 20);
            rectanguloDepositoB.fill();
            drawRectangle(rectanguloDepositoB, 85, 470, 430, 20);

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

            preficha.add(vacio);

            PdfContentByte rectanguloConcepto = writer.getDirectContentUnder();
            rectanguloConcepto.rectangle(150, 425, 295, 35);
            //                rectangulo_datos.rec
            rectanguloConcepto.fill();
            drawRectangleSC(rectanguloConcepto, 150, 425, 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 DE EMISIN: 18/12/2014",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            fechaEmision.setAlignment(Element.ALIGN_CENTER);
            preficha.add(fechaEmision);

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

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

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

            String ref = "44353452342353464765634523434";

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

            preficha.add(vacio);

            //                Paragraph descrConcepto = new Paragraph("DESCRIPCIN DEL CONCEPTO: CUOTA POR CONCEPTO DE PREINCRIPCIN.", FontFactory.getFont("arial", 10, Font.BOLD));
            //                descrConcepto.setAlignment(Element.ALIGN_CENTER);
            //                preficha.add(descrConcepto);

            preficha.add(vacio);
            preficha.add(vacio);
            preficha.add(vacio);
            //                preficha.add(vacio);
            //                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, 229, 100, 25);
            rectangulo_atencion.fill();
            drawRectangle(rectangulo_atencion, 245, 229, 100, 25);

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

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

            Paragraph informacion = new Paragraph(
                    "                        Para continuar con el proceso de preinscripcin debers:\n"
                            + "                           - Realizar el pago para tu examen de admisin con la \"REFERENCIA\" que aparece\n"
                            + "                             en este documento en cualquier sucursal BANAMEX.\n"
                            + "                           - Recibir la notificacin en tu 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 tu proceso de preinscripcin.\n",
                    FontFactory.getFont("arial", 10, Font.BOLD));
            informacion.setAlignment(Element.ALIGN_LEFT);
            preficha.add(informacion);
            //  pie
            //  pie
            //  pie
            //  pie
            //  pie
            preficha.add(vacio);
            preficha.add(vacio);

            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");

            preficha.close();

            preficha.close();
        } catch (DocumentException de) {
            throw new IOException(de.getMessage());
        }
    } catch (SQLException ex) {
        Logger.getLogger(PrefichaPDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:user_details.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

    int option = JOptionPane.showConfirmDialog(null, "Are you sure?");

    if (option == 0) {

        Document document = new Document();
        PdfWriter writer;/*w w  w .  j  ava  2s .c  o  m*/
        try {
            try {
                writer = PdfWriter.getInstance(document, new FileOutputStream("Your_Resume.pdf"));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(user_details.class.getName()).log(Level.SEVERE, null, ex);
            }

            Font fontdesign1 = FontFactory.getFont("Times-Roman", 20, Font.BOLD);
            Font fontdesign2 = FontFactory.getFont("Times-Roman", 10, Font.ITALIC);
            Font fontdesign4 = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
            Font fontdesign3 = FontFactory.getFont("Times-Roman", 11);
            document.open();

            Paragraph namepara = new Paragraph(fname + " " + lname, fontdesign1);
            namepara.setAlignment(Element.ALIGN_CENTER);
            document.add(namepara);

            document.add(Chunk.NEWLINE);

            if (edu_details.equals("") || edu_details.equals("-")) {

            } else {
                Paragraph eduTitle = new Paragraph("EDUCATIONAL QUALIFICATION:", fontdesign4);
                document.add(eduTitle);

                Paragraph edupara = new Paragraph(edu_details, fontdesign3);
                document.add(edupara);
            }

            document.add(Chunk.NEWLINE);

            if (present_comp.equals("") || present_comp.equals("-")) {

            } else {
                Paragraph Present_compTitle = new Paragraph("CURRENT COMPANY AND POSITION:", fontdesign4);
                document.add(Present_compTitle);

                Paragraph Present_compPara = new Paragraph(present_comp, fontdesign3);

                document.add(Present_compPara);
            }

            document.add(Chunk.NEWLINE);

            if (past_emp.equals("") || past_emp.equals("-")) {

            } else {
                Paragraph Past_compTitle = new Paragraph("PAST EMPLOYMENT DETAILS:", fontdesign4);
                document.add(Past_compTitle);

                Paragraph Past_compPara = new Paragraph(past_emp, fontdesign3);
                document.add(Past_compPara);
            }

            document.add(Chunk.NEWLINE);

            if (key_responsibility.equals("") || key_responsibility.equals("-")) {

            } else {
                Paragraph KeyTitle = new Paragraph("KEY RESPONSIBILITIES: ", fontdesign4);
                document.add(KeyTitle);

                Paragraph Keypara = new Paragraph(key_responsibility, fontdesign3);
                document.add(Keypara);
            }

            document.add(Chunk.NEWLINE);

            if (accomplishments.equals("") || accomplishments.equals("-")) {

            } else {
                Paragraph AccTitle = new Paragraph("ACCOMPLISHMENTS AND ACHIEVEMENTS:", fontdesign4);
                document.add(AccTitle);

                Paragraph Accpara = new Paragraph(accomplishments, fontdesign3);
                document.add(Accpara);
            }

            document.add(Chunk.NEWLINE);

            if (training.equals("") || training.equals("-")) {

            } else {
                Paragraph TrainingTitle = new Paragraph("On-Job TRAININGS/SEMINARS/WORKSHOPS:", fontdesign4);
                document.add(TrainingTitle);

                Paragraph Trainingpara = new Paragraph(training, fontdesign3);
                document.add(Trainingpara);
            }

            document.add(Chunk.NEWLINE);

            Paragraph RefTitle = new Paragraph("REFERENCES:", fontdesign4);
            document.add(RefTitle);

            for (int i = 0; i < refno; i++) {
                Paragraph refpara = new Paragraph(i + 1 + "." + ref[i], fontdesign3);
                document.add(refpara);

            }
            document.add(Chunk.NEWLINE);
            document.add(Chunk.NEWLINE);

            Paragraph contactpara = new Paragraph("PHONE: " + contactNo, fontdesign2);
            document.add(contactpara);

            if (fthername.equals("") || fthername.equals("-")) {

            } else {
                Paragraph fthrnamepara = new Paragraph("FATHER'S NAME: " + fthername, fontdesign2);
                document.add(fthrnamepara);
            }

            Paragraph dobpara = new Paragraph("DOB: " + dob, fontdesign2);
            document.add(dobpara);

            Paragraph addresspara = new Paragraph("PERMANENT ADDRESS: " + pa, fontdesign2);
            document.add(addresspara);

            document.close();

        } catch (DocumentException ex) {
            Logger.getLogger(user_details.class.getName()).log(Level.SEVERE, null, ex);
        }

        references.dispose();
        new user_details().setVisible(true);
        JOptionPane.showMessageDialog(null,
                "Congratulations! Your resume has been created. Kindly check the directory.");
    } else {
        JOptionPane.showMessageDialog(null, "Okay! You can edit your Information.");

    }

}

From source file:app.App.java

private void setLink(int pageId, PdfStamper stamper) throws ClassNotFoundException, IOException {
    // load the sqlite-JDBC driver using the current class loader
    Class.forName("org.sqlite.JDBC");

    Connection connection = null;
    try {/*from  w ww. java  2s .co m*/
        // create a database connection
        connection = DriverManager.getConnection("jdbc:sqlite:" + DATABASE);
        Statement statement = connection.createStatement();
        statement.setQueryTimeout(30); // set timeout to 30 sec.

        ResultSet rs = statement.executeQuery(
                "select * from page_annotations " + "where annotation_type = 'goto' and page_id = " + pageId);
        float spendX = 0;
        float spendY = 0;
        float coordX = 0;
        float coordY = 0;
        int pageDest = 0;
        Rectangle rect;
        PdfAnnotation annotation;
        while (rs.next()) {
            spendX = rs.getFloat("pdf_width");
            spendY = rs.getFloat("pdf_height");
            coordX = rs.getFloat("pdf_x");// + rs.getFloat("pdf_width");
            coordY = rs.getFloat("pdf_y");
            pageDest = rs.getInt("annotation_target");

            Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.UNDERLINE);
            // Blue
            font.setColor(0, 0, 255);
            Chunk chunk = new Chunk("GOTO", font);
            Anchor anchor = new Anchor(chunk);
            ColumnText.showTextAligned(stamper.getUnderContent(pageId), Element.ALIGN_LEFT, anchor,
                    coordX + spendX, coordY, 0);

            rect = new Rectangle(coordX, coordY, spendX, spendY);
            annotation = PdfAnnotation.createLink(stamper.getWriter(), rect, PdfAnnotation.HIGHLIGHT_INVERT,
                    new PdfAction("#" + pageDest));
            stamper.addAnnotation(annotation, pageId);
        }
    } catch (SQLException e) {
        // if the error message is "out of memory", 
        // it probably means no database file is found
        System.err.println(e.getMessage());
    } finally {
        try {
            if (connection != null)
                connection.close();
        } catch (SQLException e) {
            // connection close failed.
            System.err.println(e);
        }
    }
}

From source file:ara.Confirmsec.java

public void myfunction() throws IOException, DocumentException {
    String a = preres.getText();//w  w w.jav  a  2s .c  o m
    File file = new File(DEST);
    file.getParentFile().mkdirs();
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(DEST));
    document.open();
    Image image = Image.getInstance("logo.jpg");
    document.add(image);
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Font small = FontFactory.getFont(FontFactory.HELVETICA, 5, Font.BOLD);
    String date = new Date().toString();
    Paragraph paragraph1 = new Paragraph(date);
    Paragraph paragraph2 = new Paragraph("To Whom it May Concern", chapterFont);
    paragraph2.setAlignment(Element.ALIGN_CENTER);
    paragraph1.setAlignment(Element.ALIGN_RIGHT);
    paragraph2.setSpacingBefore(20f);
    paragraph2.setSpacingAfter(10f);
    Paragraph paragraph3 = new Paragraph(a, paragraphFont);
    paragraph3.setSpacingAfter(20f);
    Paragraph paragraph4 = new Paragraph("Registrar");
    paragraph4.setAlignment(Element.ALIGN_RIGHT);
    paragraph4.setSpacingAfter(100f);
    Paragraph paragraph5 = new Paragraph(
            "This is a digitally signed document. Use Ref No. " + c + " to verify.", small);
    document.add(paragraph1);
    document.add(paragraph2);
    document.add(paragraph3);
    document.add(paragraph4);
    document.add(paragraph5);
    document.close();
    JOptionPane.showMessageDialog(null, "Document Generated.");
}

From source file:at.jps.sanction.core.io.file.PDFFileOutputWorker.java

License:Open Source License

@Override
public void handleMessage(final AnalysisResult message) {

    super.handleMessage(message);

    try {//from w  ww . j a  v  a 2s  .  co  m

        logger.info("write Message: " + message.getMessage().getId());

        final Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(getFilename()));
        document.open();

        final Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD);
        final Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL);

        Chunk chunk = new Chunk("Message", chapterFont);
        Chapter chapter = new Chapter(new Paragraph(chunk), 1);
        chapter.setNumberDepth(0);
        chapter.add(new Paragraph(message.getMessage().toString(), paragraphFont));
        document.add(chapter);

        getWriter().write(message.getMessage().toString());

        if (message.getHitList() != null) {

            chapter.add(new Paragraph("Hits", paragraphFont));

            for (final HitResult hit : message.getHitList()) {
                final PdfPTable table = new PdfPTable(2);

                table.addCell("Description");
                table.addCell(hit.getHitDescripton());
                table.addCell("Field");
                table.addCell(hit.getHitDescripton());
                table.addCell("Absolute Value");
                table.addCell(hit.getAbsolutHit() + "");
                table.addCell("Relative Value");
                table.addCell(hit.getRelativeHit() + "");
                table.addCell("Phrase Value");
                table.addCell(hit.getPhraseHit() + "");
                table.addCell("HitType");
                table.addCell(hit.getHitType());

                document.add(table);
            }
        } else {
            final String exception = message.getException();
            if (exception != null) {
                chunk = new Chunk("Error:", chapterFont);
                chapter = new Chapter(new Paragraph(chunk), 1);
                chapter.add(new Paragraph(message.getException().toString(), paragraphFont));
                document.add(chapter);
            }
        }
        document.close();
    } catch (final Exception e) {
        logger.error("Error writing to file:" + getFilename());
        logger.debug("Exception: ", e);
    }
}

From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java

public ByteArrayOutputStream generatePDFDocumentBytes(final HttpServletRequest req, ServletContext application,
        boolean filterApplied, int partsOfTransactionToPrint) throws DocumentException {
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    PdfWriter docWriter = null;/*w  w  w  .  j a va 2  s.com*/
    this.req = req;
    this.application = application;
    sContextPath = req.getContextPath();

    try {
        docWriter = PdfWriter.getInstance(doc, baosPDF);

        //*** META TAGS ***********************************************************************
        doc.addProducer();
        doc.addAuthor(user.person.firstname + " " + user.person.lastname);
        doc.addCreationDate();
        doc.addCreator("OpenClinic Software for Hospital Management");
        doc.addTitle("Medical Record Data for " + patient.firstname + " " + patient.lastname);
        doc.addKeywords(patient.firstname + ", " + patient.lastname);
        doc.setPageSize(PageSize.A4);

        //*** FOOTER **************************************************************************
        PDFFooter footer = new PDFFooter("OpenClinic pdf engine (c)2007, Post-Factum bvba\n"
                + MedwanQuery.getInstance().getLabel("web.occup", "medwan.common.patientrecord", sPrintLanguage)
                + " " + patient.getID("immatnew") + " " + patient.firstname + " " + patient.lastname);
        docWriter.setPageEvent(footer);
        doc.open();

        //*** HEADER **************************************************************************
        printDocumentHeader(req);

        //*** TITLE ***************************************************************************
        String title = getTran("Web.Occup", "medwan.common.occupational-health-record").toUpperCase();

        // add date restriction to document title
        title += "\n(" + getTran("web", "printdate") + ": " + dateFormat.format(new Date()) + ")";
        /*
        if(dateFrom!=null && dateTo!=null){
        if(dateFrom.getTime() == dateTo.getTime()){
            title+= "\n("+getTran("web","on")+" "+dateFormat.format(dateTo)+")";
        }
        else{
            title+= "\n("+getTran("pdf","date.from")+" "+dateFormat.format(dateFrom)+" "+getTran("pdf","date.to")+" "+dateFormat.format(dateTo)+")";
        }
        }
        else if(dateFrom!=null){
        title+= "\n("+getTran("web","since")+" "+dateFormat.format(dateFrom)+")";
        }
        else if(dateTo!=null){
        title+= "\n("+getTran("pdf","date.to")+" "+dateFormat.format(dateTo)+")";
        }*/

        Paragraph par = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        par.setAlignment(Paragraph.ALIGN_CENTER);
        doc.add(par);

        //*** OTHER DOCUMENT ELEMENTS *********************************************************
        printAdminHeader(patient);
        //printKeyData(sessionContainerWO);
        printMedication(sessionContainerWO);
        printActiveDiagnosis(sessionContainerWO);
        printWarnings(sessionContainerWO);
        doc.add(new Paragraph(" "));

        //*** VACCINATION CARD ****************************************************************
        new be.mxs.common.util.pdf.general.oc.examinations.PDFVaccinationCard().printCard(doc,
                sessionContainerWO, transactionVO, patient, req, sProject, sPrintLanguage,
                new Integer(partsOfTransactionToPrint));

        //*** TRANSACTIONS ********************************************************************
        Enumeration e = req.getParameterNames();
        String paramName, paramValue, sTranID, sServerID;
        boolean transactionIDsSpecified = false;

        while (e.hasMoreElements()) {
            paramName = (String) e.nextElement();

            // transactionIDs were specified as request-parameters
            if (paramName.startsWith("tranAndServerID_")) {
                transactionIDsSpecified = true;

                paramValue = checkString(req.getParameter(paramName));
                sTranID = paramValue.substring(0, paramValue.indexOf("_"));
                sServerID = paramValue.substring(paramValue.indexOf("_") + 1);

                this.transactionVO = MedwanQuery.getInstance().loadTransaction(Integer.parseInt(sServerID),
                        Integer.parseInt(sTranID));
                loadTransaction(transactionVO, 2); // 2 = print whole transaction
            }
        }

        if (!transactionIDsSpecified) {
            printTransactions(filterApplied, partsOfTransactionToPrint);
        }
        doc.add(new Paragraph(" "));
        printSignature();
    } catch (DocumentException dex) {
        baosPDF.reset();
        throw dex;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (doc != null)
            doc.close();
        if (docWriter != null)
            docWriter.close();
    }

    if (baosPDF.size() < 1) {
        throw new DocumentException("document has " + baosPDF.size() + " bytes");
    }

    return baosPDF;
}

From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java

protected void printSignature() {
    try {/*from   www  .  j  a  va2s  . c  o  m*/
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(
                new Paragraph(getTran("report.monthly", "signature").toUpperCase() + "\n\n\n\n\n\n\n\n",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC)));
        cell.setColspan(1);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
        table.addCell(cell);
        doc.add(table);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java

protected void printActiveDiagnosis(SessionContainerWO sessionContainerWO) {
    try {//from   ww w . j  av  a2 s. c  om
        Vector activeProblems = Problem.getActiveProblems(patient.personid);

        if (activeProblems.size() > 0) {
            doc.add(new Paragraph(" "));
            table = new PdfPTable(1);
            table.setWidthPercentage(100);

            // title
            cell = new PdfPCell(new Paragraph(getTran("web.occup", "medwan.common.problemlist").toUpperCase(),
                    FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC)));
            cell.setColspan(1);
            cell.setBorder(PdfPCell.BOX);
            cell.setBorderColor(BaseColor.LIGHT_GRAY);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            // run thru diagnoses
            Problem activeProblem;
            String value;

            for (int n = 0; n < activeProblems.size(); n++) {
                activeProblem = (Problem) activeProblems.elementAt(n);
                value = MedwanQuery.getInstance().getCodeTran(
                        activeProblem.getCodeType() + "code" + activeProblem.getCode(), sPrintLanguage);
                cell = new PdfPCell(new Paragraph(
                        value + " (" + getTran("Web", "since") + " "
                                + dateFormat.format(activeProblem.getBegin()) + ")",
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));

                cell.setColspan(1);
                cell.setBorder(PdfPCell.BOX);
                cell.setBorderColor(BaseColor.LIGHT_GRAY);
                cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                table.addCell(cell);
            }

            doc.add(table);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java

protected void printWarnings(SessionContainerWO sessionContainerWO) {
    try {// ww  w  .  jav a2  s  . c  o  m
        if (sessionContainerWO.getHealthRecordVO() != null) {
            Collection alerts = MedwanQuery.getInstance().getTransactionsByType(
                    sessionContainerWO.getHealthRecordVO(), IConstants.TRANSACTION_TYPE_ALERT);
            sessionContainerWO.setAlerts(alerts);

            if (sessionContainerWO.getActiveAlerts().size() > 0) {
                doc.add(new Paragraph(" "));
                table = new PdfPTable(4);
                table.setWidthPercentage(100);

                // title
                cell = new PdfPCell(new Paragraph(getTran("curative", "warning.status.title").toUpperCase(),
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC)));
                cell.setColspan(4);
                cell.setBorder(PdfPCell.BOX);
                cell.setBorderColor(BaseColor.LIGHT_GRAY);
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
                table.addCell(cell);

                // list alerts
                Collection activeAlerts = sessionContainerWO.getActiveAlerts();
                Iterator alertsIter = activeAlerts.iterator();
                TransactionVO transactionVO;
                String sLabel, sComment;
                ItemVO itemVO;

                while (alertsIter.hasNext()) {
                    transactionVO = (TransactionVO) alertsIter.next();

                    // label
                    sLabel = "";
                    itemVO = transactionVO.getItem(IConstants_PREFIX + "ITEM_TYPE_ALERTS_LABEL");
                    if (itemVO != null) {
                        sLabel = checkString(itemVO.getValue());
                    }

                    cell = new PdfPCell(new Paragraph(sLabel, FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));
                    cell.setColspan(1);
                    cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP + PdfPCell.BOTTOM); // no right border
                    cell.setBorderColor(BaseColor.LIGHT_GRAY);
                    cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                    table.addCell(cell);

                    // comment
                    sComment = "";
                    itemVO = transactionVO.getItem(IConstants_PREFIX + "ITEM_TYPE_ALERTS_DESCRIPTION");
                    if (itemVO != null) {
                        sComment = checkString(itemVO.getValue());
                    }

                    cell = new PdfPCell(new Paragraph(sComment, FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));
                    cell.setColspan(4);
                    cell.setBorder(PdfPCell.RIGHT + PdfPCell.TOP + PdfPCell.BOTTOM); // no left border
                    cell.setBorderColor(BaseColor.LIGHT_GRAY);
                    cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                    table.addCell(cell);
                }

                doc.add(table);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java

protected void printMedication(SessionContainerWO sessionContainerWO) {
    try {//from w  w w  .j a  v  a2  s . c  om
        doc.add(new Paragraph(" "));
        table = new PdfPTable(2);
        table.setWidthPercentage(100);

        // main title
        cell = new PdfPCell(new Paragraph(getTran("curative", "medication.status.title").toUpperCase(),
                FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0),
                        Font.ITALIC)));
        cell.setColspan(2);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell);

        Vector chronicMedications = ChronicMedication.find(patient.personid, "", "", "", "OC_CHRONICMED_BEGIN",
                "ASC"), activePrescriptions = Prescription.getActivePrescriptions(patient.personid);

        //*** CHRONIC MEDICATION ******************************************
        if (chronicMedications.size() > 0) {
            PdfPTable medicationTable = new PdfPTable(2);

            // sub title
            cell = new PdfPCell(new Paragraph(getTran("curative", "medication.chronic"), FontFactory.getFont(
                    FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC)));
            cell.setColspan(2);
            cell.setBorder(PdfPCell.BOX);
            cell.setBorderColor(BaseColor.LIGHT_GRAY);
            cell.setVerticalAlignment(PdfPCell.ALIGN_LEFT);
            cell.setBackgroundColor(BGCOLOR_LIGHT);
            medicationTable.addCell(cell);

            // run thru medications
            String sPrescrRule, sProductUnit, timeUnitTran;
            ChronicMedication medication;

            for (int n = 0; n < chronicMedications.size(); n++) {
                medication = (ChronicMedication) chronicMedications.elementAt(n);

                sPrescrRule = getTran("web.prescriptions", "prescriptionrule");
                sPrescrRule = sPrescrRule.replaceAll("#unitspertimeunit#",
                        medication.getUnitsPerTimeUnit() + "");

                // productunits
                if (medication.getUnitsPerTimeUnit() == 1) {
                    sProductUnit = getTran("product.unit", medication.getProduct().getUnit());
                } else {
                    sProductUnit = getTran("product.units", medication.getProduct().getUnit());
                }
                sPrescrRule = sPrescrRule.replaceAll("#productunit#", sProductUnit.toLowerCase());

                // timeunits
                if (medication.getTimeUnitCount() == 1) {
                    sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", "");
                    timeUnitTran = getTran("prescription.timeunit", medication.getTimeUnit());
                } else {
                    sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", medication.getTimeUnitCount() + "");
                    timeUnitTran = getTran("prescription.timeunits", medication.getTimeUnit());
                }
                sPrescrRule = sPrescrRule.replaceAll("#timeunit#",
                        timeUnitTran.replaceAll("  ", " ").toLowerCase());

                // product name
                cell = new PdfPCell(new Paragraph(medication.getProduct().getName(),
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
                cell.setColspan(1);
                cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP + PdfPCell.BOTTOM); // no right border
                cell.setBorderColor(BaseColor.LIGHT_GRAY);
                medicationTable.addCell(cell);

                // prescription rule
                cell = new PdfPCell(new Paragraph(sPrescrRule, FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)));
                cell.setColspan(1);
                cell.setBorder(PdfPCell.RIGHT + PdfPCell.TOP + PdfPCell.BOTTOM); // no left border
                cell.setBorderColor(BaseColor.LIGHT_GRAY);
                medicationTable.addCell(cell);
            }

            // add cells to make up with the chronic medications
            if (chronicMedications.size() < activePrescriptions.size()) {
                int missingCellCount = activePrescriptions.size() - chronicMedications.size();
                for (int i = 0; i < missingCellCount; i++) {
                    cell = new PdfPCell();
                    cell.setColspan(2);
                    cell.setBorder(PdfPCell.NO_BORDER);
                    medicationTable.addCell(cell);
                }
            }

            // add chronicmedicationtables to medicationtable
            cell = new PdfPCell(medicationTable);
            cell.setBorder(PdfPCell.BOX);
            cell.setBorderColor(BaseColor.LIGHT_GRAY);
            cell.setPadding(3);
            table.addCell(cell);
        }

        //*** PRESCRIPTIONS ***********************************************
        if (activePrescriptions.size() > 0) {
            PdfPTable medicationTable = new PdfPTable(2);

            // sub title
            cell = new PdfPCell(new Paragraph(getTran("curative", "medication.prescription"),
                    FontFactory.getFont(FontFactory.HELVETICA,
                            Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC)));
            cell.setColspan(2);
            cell.setBorder(PdfPCell.BOX);
            cell.setBorderColor(BaseColor.LIGHT_GRAY);
            cell.setVerticalAlignment(PdfPCell.ALIGN_LEFT);
            cell.setBackgroundColor(BGCOLOR_LIGHT);
            medicationTable.addCell(cell);

            // run thru medications
            String sPrescrRule, sProductUnit, timeUnitTran;
            Prescription prescription;
            int n;

            for (n = 0; n < activePrescriptions.size(); n++) {
                prescription = (Prescription) activePrescriptions.elementAt(n);

                sPrescrRule = getTran("web.prescriptions", "prescriptionrule");
                sPrescrRule = sPrescrRule.replaceAll("#unitspertimeunit#",
                        prescription.getUnitsPerTimeUnit() + "");

                // productunits
                if (prescription.getUnitsPerTimeUnit() == 1) {
                    sProductUnit = getTran("product.unit", prescription.getProduct().getUnit());
                } else {
                    sProductUnit = getTran("product.units", prescription.getProduct().getUnit());
                }
                sPrescrRule = sPrescrRule.replaceAll("#productunit#", sProductUnit.toLowerCase());

                // timeunits
                if (prescription.getTimeUnitCount() == 1) {
                    sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", "");
                    timeUnitTran = getTran("prescription.timeunit", prescription.getTimeUnit());
                } else {
                    sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#",
                            prescription.getTimeUnitCount() + "");
                    timeUnitTran = getTran("prescription.timeunits", prescription.getTimeUnit());
                }
                sPrescrRule = sPrescrRule.replaceAll("#timeunit#", timeUnitTran.toLowerCase());

                // product name
                cell = new PdfPCell(new Paragraph(prescription.getProduct().getName(),
                        FontFactory.getFont(FontFactory.HELVETICA,
                                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
                cell.setColspan(1);
                cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP + PdfPCell.BOTTOM); // no right border
                cell.setBorderColor(BaseColor.LIGHT_GRAY);
                medicationTable.addCell(cell);

                // prescription rule
                cell = new PdfPCell(new Paragraph(sPrescrRule, FontFactory.getFont(FontFactory.HELVETICA,
                        Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)));
                cell.setColspan(1);
                cell.setBorder(PdfPCell.RIGHT + PdfPCell.TOP + PdfPCell.BOTTOM); // no left border
                cell.setBorderColor(BaseColor.LIGHT_GRAY);
                medicationTable.addCell(cell);
            }

            // add cells to make up with the active prescriptions
            if (activePrescriptions.size() < chronicMedications.size()) {
                int missingCellCount = chronicMedications.size() - activePrescriptions.size();
                for (int i = 0; i < missingCellCount; i++) {
                    cell = new PdfPCell();
                    cell.setColspan(2);
                    cell.setBorder(PdfPCell.NO_BORDER);
                    medicationTable.addCell(cell);
                }
            }

            // add presciptionssstable to medicationtable
            cell = new PdfPCell(medicationTable);
            cell.setBorder(PdfPCell.BOX);
            cell.setBorderColor(BaseColor.LIGHT_GRAY);
            cell.setPadding(3);
            table.addCell(cell);

            doc.add(table);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}