Example usage for com.itextpdf.text Font Font

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

Introduction

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

Prototype


public Font(final BaseFont bf, final float size, final int style, final BaseColor color) 

Source Link

Document

Constructs a Font.

Usage

From source file:net.sf.texprinter.generators.PDFGenerator.java

License:Open Source License

/**
 * Generates a PDF file from a Question object.
 * //w ww.java2  s  .  c o  m
 * @param question The question.
 * @param filename The filename.
 */
public static void generate(Question question, String filename) {

    // wait window
    ProgressMessage pm = new ProgressMessage("TeXPrinter is printing your PDF file.");

    // start wait window
    //pm.start();

    // log message
    log.log(Level.INFO, "Starting PDF generation of {0}.", filename);

    // define a new PDF document
    Document document = null;

    // define a new PDF writer
    PdfWriter writer = null;

    // lets try
    try {

        // create a new PDF document
        document = new Document();

        // define a new PDF Writer
        writer = PdfWriter.getInstance(document, new FileOutputStream(filename));

        // set the PDF version
        writer.setPdfVersion(PdfWriter.VERSION_1_6);

        // open the document
        document.open();

        // set the title font
        Font titleFont = new Font(FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK);

        // set the chunk for the question title
        Chunk questionTitle = new Chunk(question.getQuestion().getTitle(), titleFont);

        // create a paragraph from that chunk
        Paragraph paragraphQuestionTitle = new Paragraph(questionTitle);

        // log message
        log.log(Level.INFO, "Adding the question title.");

        // add the question title to the document
        document.add(paragraphQuestionTitle);

        // set the asker font
        Font askerFont = new Font(FontFamily.HELVETICA, 10, Font.ITALIC, BaseColor.DARK_GRAY);

        // set the chunk for the asker
        Chunk questionAsker = new Chunk("Asked by " + question.getQuestion().getUser().getName() + " ("
                + question.getQuestion().getUser().getReputation() + ") on " + question.getQuestion().getDate()
                + " (" + String.valueOf(question.getQuestion().getVotes())
                + (question.getQuestion().getVotes() == 1 ? " vote" : " votes") + ")", askerFont);

        // create a paragraph from that chunk
        Paragraph paragraphQuestionAsker = new Paragraph(questionAsker);

        // log message
        log.log(Level.INFO, "Adding both asker and reputation.");

        // add the asker to the document
        document.add(paragraphQuestionAsker);

        // create a line separator
        LineSeparator line = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -5);

        // add the line to the document
        document.add(line);

        // add a new line
        document.add(Chunk.NEWLINE);

        // create a list of elements from the question objects
        List<Element> questionTextObjects = getPostText(question.getQuestion().getText());

        // log message
        log.log(Level.INFO, "Adding the question text.");

        // for each element
        for (Element questionTextObject : questionTextObjects) {

            // add it to the document
            document.add(questionTextObject);
        }

        // add a new line
        document.add(Chunk.NEWLINE);

        // create a new font for the comments title
        Font commentsTitleFont = new Font(FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.BLACK);

        // create a new chunk based on that font
        Chunk commentsTitle = new Chunk(
                "This question has " + question.getQuestion().getComments().size()
                        + ((question.getQuestion().getComments().size() == 1) ? " comment:" : " comments:"),
                commentsTitleFont);

        // create a paragraph from that chunk
        Paragraph paragraphCommentsTitle = new Paragraph(commentsTitle);

        // if there are comments to this question
        if (!question.getQuestion().getComments().isEmpty()) {

            // log message
            log.log(Level.INFO, "Adding the question comments.");

            // add that paragraph to the document
            document.add(paragraphCommentsTitle);

            // add a new line
            document.add(Chunk.NEWLINE);

            // get all the comments
            List<Comment> questionComments = question.getQuestion().getComments();

            // for each comment
            for (Comment questionComment : questionComments) {

                // get the elements of the comment text
                List<Element> questionCommentObjects = getPostText(questionComment.getText());

                // for each element
                for (Element questionCommentObject : questionCommentObjects) {

                    // add it to the document
                    document.add(questionCommentObject);
                }

                // create a new paragraph about the comment author
                Paragraph paragraphCommentAuthor = new Paragraph(questionComment.getAuthor() + " on "
                        + questionComment.getDate() + " (" + String.valueOf(questionComment.getVotes())
                        + (questionComment.getVotes() == 1 ? " vote" : " votes") + ")", askerFont);

                // set the alignment to the right
                paragraphCommentAuthor.setAlignment(Element.ALIGN_RIGHT);

                // add the paragraph to the document
                document.add(paragraphCommentAuthor);

                // add a new line
                document.add(Chunk.NEWLINE);
            }
        }

        // add a line separator
        document.add(line);

        // add two new lines
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        // get the list of answers
        List<Post> answersList = question.getAnswers();

        // if there are no answers
        if (answersList.isEmpty()) {

            // log message
            log.log(Level.INFO, "This question has no answers.");

            // create a new chunk
            Chunk noAnswersTitle = new Chunk("Sorry, this question has no answers yet.", titleFont);

            // create a paragraph from that chunk
            Paragraph paragraphNoAnswersTitle = new Paragraph(noAnswersTitle);

            // add the paragraph to the document
            document.add(paragraphNoAnswersTitle);

        } else {

            // log message
            log.log(Level.INFO, "Adding answers.");

            // there are answers, so create a counter for answers
            int answerCount = 1;

            // for each answer
            for (Post answer : answersList) {

                // log message
                log.log(Level.INFO, "Adding answer {0}.", answerCount);

                // set the message text as empty
                String answerAccepted = "";

                // if the answer is accepted
                if (answer.isAccepted()) {

                    // add that to the message
                    answerAccepted = " - Marked as accepted.";
                }

                // create a new chunk
                Chunk answerTitle = new Chunk("Answer #" + answerCount, titleFont);

                // create a paragraph from that chunk
                Paragraph paragraphAnswerTitle = new Paragraph(answerTitle);

                // add the paragraph to the document
                document.add(paragraphAnswerTitle);

                // increase the counter
                answerCount++;

                // create a new chunk
                Chunk questionAnswerer = new Chunk("Answered by " + answer.getUser().getName() + " ("
                        + answer.getUser().getReputation() + ") on " + answer.getDate() + answerAccepted + " ("
                        + String.valueOf(answer.getVotes()) + (answer.getVotes() == 1 ? " vote" : " votes")
                        + ")", askerFont);

                // create a paragraph from that chunk
                Paragraph paragraphQuestionAnswerer = new Paragraph(questionAnswerer);

                // add that paragraph to the document
                document.add(paragraphQuestionAnswerer);

                // add a line separator
                document.add(line);

                // add a new line
                document.add(Chunk.NEWLINE);

                // create a list of elements from the answer text
                List<Element> answerTextObjects = getPostText(answer.getText());

                // for each element
                for (Element answerTextObject : answerTextObjects) {

                    // add it to the document
                    document.add(answerTextObject);
                }

                // add a new line
                document.add(Chunk.NEWLINE);

                // create a new font style
                Font answerCommentsTitleFont = new Font(FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.BLACK);

                // create a new chunk
                Chunk answerCommentsTitle = new Chunk(
                        "This answer has " + answer.getComments().size()
                                + ((answer.getComments().size() == 1) ? " comment:" : " comments:"),
                        answerCommentsTitleFont);

                // create a paragraph from that chunk
                Paragraph paragraphAnswerCommentsTitle = new Paragraph(answerCommentsTitle);

                // if there are comments for that answer
                if (!answer.getComments().isEmpty()) {

                    // log message
                    log.log(Level.INFO, "Adding comments for answer {0}.", (answerCount - 1));

                    // add that paragraph to the document
                    document.add(paragraphAnswerCommentsTitle);

                    // add a new line
                    document.add(Chunk.NEWLINE);

                    // get all the comments
                    List<Comment> answerComments = answer.getComments();

                    // for each comment
                    for (Comment answerComment : answerComments) {

                        // create a list of elements from the comment text
                        List<Element> answerCommentObjects = getPostText(answerComment.getText());

                        // for each element
                        for (Element answerCommentObject : answerCommentObjects) {

                            // add it to the document
                            document.add(answerCommentObject);
                        }

                        // create a new paragraph for the comment author
                        Paragraph paragraphAnswerCommentAuthor = new Paragraph(
                                answerComment.getAuthor() + " on " + answerComment.getDate() + " ("
                                        + String.valueOf(answerComment.getVotes())
                                        + (answerComment.getVotes() == 1 ? " vote" : " votes") + ")",
                                askerFont);

                        // set the aligment to the right
                        paragraphAnswerCommentAuthor.setAlignment(Element.ALIGN_RIGHT);

                        // add the paragraph to the document
                        document.add(paragraphAnswerCommentAuthor);

                        // add a new line
                        document.add(Chunk.NEWLINE);
                    }
                }

                // add a line separator
                document.add(line);

                // add two new lines
                document.add(Chunk.NEWLINE);
                document.add(Chunk.NEWLINE);
            }
        }

        // log message
        log.log(Level.INFO, "PDF generation complete, closing {0}.", filename);

        // close the document
        document.close();

        // stop wait window
        pm.interrupt();

    } catch (IOException ioexception) {

        // stop wait window
        pm.interrupt();

        // log message
        log.log(Level.SEVERE, "An IO error occurred while trying to create the PDF file. MESSAGE: {0}",
                StringUtils.printStackTrace(ioexception));

        // critical error, exit
        Dialogs.showExceptionWindow();

    } catch (Exception exception) {

        // log message
        log.log(Level.SEVERE, "A generic error occurred while trying to create the PDF file. MESSAGE: {0}",
                StringUtils.printStackTrace(exception));

        // log message
        log.log(Level.INFO, "I will try to remove the remaining PDF file.");

        try {

            // log message
            log.log(Level.INFO, "Closing both document and writer.");

            // close the document
            document.close();

            // close the writer
            writer.close();

        } catch (Exception ex) {

            // log message
            log.log(Level.WARNING, "I could not close either document or writer. MESSAGE: {0}",
                    StringUtils.printStackTrace(ex));
        }

        try {

            // reference problematic file
            File target = new File(filename);

            // log message
            log.log(Level.INFO, "Opening problematic file {0}.", filename);

            // check if file exists
            if (target.exists()) {

                // log message
                log.log(Level.INFO, "File exists, trying to delete it.");

                // trying to remove it
                if (target.delete()) {

                    // log message
                    log.log(Level.INFO, "File {0} was successfully removed.", filename);

                } else {

                    // log message
                    log.log(Level.SEVERE, "File {0} could not be removed.", filename);

                }
            }
        } catch (SecurityException se) {

            // log message
            log.log(Level.SEVERE, "A security exception was raised. MESSAGE: {0}",
                    StringUtils.printStackTrace(se));

        }

        // stop wait window
        pm.interrupt();

        // critical error, exit
        Dialogs.showExceptionWindow();

    }
}

From source file:nl.avans.C3.BusinessLogic.InvoiceService.java

public void generateInvoice(String invoiceBSN, int[] behandelCode)
        throws DocumentException, FileNotFoundException, ClientNotFoundException, ParseException {
    Date date = new Date();
    String dt = new SimpleDateFormat("yyyy-MM-dd").format(date);
    String fileId = "invoice-" + dt + "-" + invoiceBSN;

    String companyName = companyService.getInsuranceCompany().getName();
    String companyAddress = companyService.getInsuranceCompany().getAddress();
    String companyPostalCode = companyService.getInsuranceCompany().getPostalCode();
    String companyCity = companyService.getInsuranceCompany().getCity();

    String companyKVK = Integer.toString(companyService.getInsuranceCompany().getKVK());
    String companyIBAN = "NL91ABNA0417164300";

    Client client = clientService.findClientByBSN(Integer.parseInt(invoiceBSN));
    String clientFirstName = client.getFirstName();
    String clientLastName = client.getLastName();
    String clientAddress = client.getAddress();
    String clientPostalCode = client.getPostalCode();
    String clientCity = client.getCity();
    boolean incasso = client.isIncasso();

    Date date2 = new Date();
    String dt2 = new SimpleDateFormat("dd-MM-yyyy").format(date2);
    String currentDate = dt2;// w  w w  .j  a  v a 2  s  .c o  m
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    Calendar c = Calendar.getInstance();
    c.setTime(sdf.parse(dt2));
    c.add(Calendar.MONTH, 1);
    dt2 = sdf.format(c.getTime());
    String expirationDate = dt2;

    String invoiceNumber = dt + "-" + invoiceBSN;

    Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
    Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12);

    // Creating new file
    Document doc = new Document();

    // Trying to parse the data to a new PDF
    PdfWriter.getInstance(doc, new FileOutputStream("generatedfiles/invoice/" + fileId + ".pdf"));

    // Opening the file
    doc.open();

    // Parsing the order details to the PDF
    doc.add(new Paragraph(companyName + "\n" + companyAddress + "\n" + companyPostalCode + " " + companyCity
            + "\n\n" + "KVK: " + companyKVK + "\nIBAN: " + companyIBAN + "\n\n\n" + clientFirstName + " "
            + clientLastName + "\n" + clientAddress + "\n" + clientPostalCode + " " + clientCity + "\n\n"
            + "Factuurdatum: " + currentDate + "\nVerloopdatum: " + expirationDate + "\n\n\n"
            + "Factuurnummer: " + invoiceNumber + "\n\n\n\n"));

    float[] columnWidths = { 2f, 2f, 2f, 2f, 2f };
    PdfPTable table = new PdfPTable(columnWidths);
    table.setWidthPercentage(100f);

    insertCell(table, "Behandelcode", Element.ALIGN_LEFT, 1, bfBold12);
    insertCell(table, "Behandelingnaam", Element.ALIGN_LEFT, 1, bfBold12);
    insertCell(table, "Aantal sessies", Element.ALIGN_LEFT, 1, bfBold12);
    insertCell(table, "Sessieduur", Element.ALIGN_LEFT, 1, bfBold12);
    insertCell(table, "Tarief", Element.ALIGN_LEFT, 1, bfBold12);
    table.setHeaderRows(1);

    List<Treatment> treatments = getTreatments(behandelCode);

    for (int i = 0; i < treatments.size(); i++) {
        insertCell(table, "" + treatments.get(i).getBehandelCode(), Element.ALIGN_LEFT, 1, bf12);
        insertCell(table, "" + treatments.get(i).getBehandelingNaam(), Element.ALIGN_LEFT, 1, bf12);
        insertCell(table, "" + treatments.get(i).getAantalSessies(), Element.ALIGN_LEFT, 1, bf12);
        insertCell(table, "" + treatments.get(i).getSessieDuur(), Element.ALIGN_LEFT, 1, bf12);
        insertCell(table, "" + treatments.get(i).getTariefBehandeling(), Element.ALIGN_RIGHT, 1, bf12);
    }

    //totaalbedrag zonder eigen risico
    double totaalBedrag = getTotaalBedrag(behandelCode);
    insertCell(table, "Totaalbedrag: ", Element.ALIGN_RIGHT, 4, bfBold12);
    insertCell(table, "" + totaalBedrag, Element.ALIGN_RIGHT, 1, bfBold12);

    //lege row
    insertCell(table, "", Element.ALIGN_RIGHT, 5, bf12);

    //huidig eigen risico
    double excess = insuranceContractService.getInsuranceContractByBSN(Integer.parseInt(invoiceBSN))
            .getExcess();
    insertCell(table, "Huidig eigen risico: ", Element.ALIGN_RIGHT, 4, bf12);
    insertCell(table, "" + excess, Element.ALIGN_RIGHT, 1, bf12);

    //totaal te betalen bedrag
    double teBetalenBedrag;
    double newExcess = excess - totaalBedrag;
    insertCell(table, "Te betalen bedrag: ", Element.ALIGN_RIGHT, 4, bfBold12);
    if (excess > 0) {
        if (excess > totaalBedrag) {
            insuranceContractService.updateInsuranceContractExcess(newExcess, insuranceContractService
                    .getInsuranceContractByBSN(Integer.parseInt(invoiceBSN)).getInsuranceContractID());
            insertCell(table, "" + totaalBedrag, Element.ALIGN_RIGHT, 1, bfBold12);
            teBetalenBedrag = totaalBedrag;
        } else {
            insuranceContractService.updateInsuranceContractExcess(0.00, insuranceContractService
                    .getInsuranceContractByBSN(Integer.parseInt(invoiceBSN)).getInsuranceContractID());
            insertCell(table, "" + excess, Element.ALIGN_RIGHT, 1, bfBold12);
            teBetalenBedrag = excess;
        }
    } else {
        insertCell(table, "0.0", Element.ALIGN_RIGHT, 1, bfBold12);
        teBetalenBedrag = 0.00;
    }

    Paragraph paragraph = new Paragraph("");
    paragraph.add(table);
    doc.add(paragraph);

    doc.add(new Paragraph("\n\n"));

    if (newExcess > 0) {
        doc.add(new Paragraph("U heeft nog " + newExcess + " eigen risico over."));
    } else {
        doc.add(new Paragraph("U heeft nog 0.0 eigen risico over."));
    }

    doc.add(new Paragraph("\n\n"));
    if (incasso == false) {
        if (teBetalenBedrag > 0) {
            doc.add(new Paragraph("We verzoeken u vriendelijk het bovenstaande bedrag van " + teBetalenBedrag
                    + " voor " + expirationDate
                    + " te voldoen op onze bankrekening onder vermelding van het factuurnummer " + invoiceNumber
                    + ". Voor vragen kunt u contact opnemen per e-mail."));
        } else {
            doc.add(new Paragraph(
                    "Omdat uw eigen risico op is worden er geen kosten in rekening gebracht voor de bovenstaande behandelingen."));
        }
    } else {
        doc.add(new Paragraph(
                "Het geld zal binnen 10 werkdagen van uw rekening afgeschreven worden door middel van een automatische incasso."));
    }

    // Closing the file
    doc.close();
}

From source file:numerical.CramersRule.java

private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_saveActionPerformed
    JFileChooser jfc = new JFileChooser();
    jfc.setCurrentDirectory(new File("/My Documents"));
    int return_val = jfc.showSaveDialog(rootPane);
    if (return_val == JFileChooser.APPROVE_OPTION) {
        Document doc = new Document();
        try {/*from w  w  w. j av a  2  s .  c  o  m*/
            jfc.getSelectedFile();
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(jfc.getSelectedFile() + ".pdf"));
            doc.open();

            Font f = new Font(Font.FontFamily.TIMES_ROMAN, 12.0f, Font.NORMAL, BaseColor.BLACK);
            Font f1 = new Font(Font.FontFamily.TIMES_ROMAN, 18.0f, Font.BOLD, BaseColor.BLACK);

            Paragraph paragraph = new Paragraph(null, f);
            Paragraph title = new Paragraph(null, f1);
            title.add("Cramers Rule\n");

            paragraph.add(txt_result.getText());
            doc.add(title);
            doc.add(paragraph);
            doc.close();
            writer.close();

            JOptionPane.showMessageDialog(rootPane, "Successfully saved!");
        } catch (FileNotFoundException | DocumentException | HeadlessException e) {
            System.err.println(e);
        }
    }
}

From source file:numerical.Determinants.java

private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_saveActionPerformed
    JFileChooser jfc = new JFileChooser();
    jfc.setCurrentDirectory(new File("/My Documents"));
    int return_val = jfc.showSaveDialog(rootPane);
    if (return_val == JFileChooser.APPROVE_OPTION) {
        Document doc = new Document();
        try {/*w  w  w .  j  a v  a2s  .  c o m*/
            jfc.getSelectedFile();
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(jfc.getSelectedFile() + ".pdf"));
            doc.open();

            Font f = new Font(Font.FontFamily.TIMES_ROMAN, 12.0f, Font.NORMAL, BaseColor.BLACK);
            Font f1 = new Font(Font.FontFamily.TIMES_ROMAN, 18.0f, Font.BOLD, BaseColor.BLACK);

            Paragraph paragraph = new Paragraph(null, f);
            Paragraph title = new Paragraph(null, f1);
            title.add("Determinants \n");

            paragraph.add(txt_result.getText());
            doc.add(title);
            doc.add(paragraph);
            doc.close();
            writer.close();

            JOptionPane.showMessageDialog(rootPane, "Successfully saved!");
        } catch (FileNotFoundException | DocumentException | HeadlessException e) {
            System.err.println(e);
        }
    }
}

From source file:numerical.Fibonnaci.java

private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_saveActionPerformed
    JFileChooser jfc = new JFileChooser();
    jfc.setCurrentDirectory(new File("/My Documents"));
    int return_val = jfc.showSaveDialog(rootPane);
    if (return_val == JFileChooser.APPROVE_OPTION) {
        Document doc = new Document();
        try {//  w  w  w  .  ja v a 2  s . co m
            jfc.getSelectedFile();
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(jfc.getSelectedFile() + ".pdf"));
            doc.open();

            Font f = new Font(Font.FontFamily.TIMES_ROMAN, 12.0f, Font.NORMAL, BaseColor.BLACK);
            Font f1 = new Font(Font.FontFamily.TIMES_ROMAN, 18.0f, Font.BOLD, BaseColor.BLACK);

            Paragraph paragraph = new Paragraph(null, f);
            Paragraph title = new Paragraph(null, f1);
            title.add("Fibonnaci\n");
            paragraph.add("Sequence number: " + count + "\n");
            paragraph.add("Result: ");
            paragraph.add(txt_result.getText());
            doc.add(title);
            doc.add(paragraph);
            doc.close();
            writer.close();

            JOptionPane.showMessageDialog(rootPane, "Successfully saved!");
        } catch (FileNotFoundException | DocumentException | HeadlessException e) {
            System.err.println(e);
        }
    }
}

From source file:org.apache.jmeter.visualizers.CreateReport.java

License:Apache License

public void createPdf(String filename, Document document2) throws IOException, DocumentException {
    // step 1//from   w w w .j  av  a  2  s  .c om
    Document document = new Document();
    // step 2
    //  OutputStream outputStream = new OutputStream(new FileOutputStream(filename));
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3
    document.open();
    // step 4

    Font titleFont = new Font(Font.FontFamily.HELVETICA, 30, Font.BOLD, clr);//BaseColor.Color.getHSBColor(258, 100, 13));
    Paragraph emptyLine = new Paragraph();
    addEmptyLine(emptyLine, 2);
    Paragraph title = new Paragraph("Test Report", titleFont);
    title.setAlignment(Element.ALIGN_CENTER);

    BaseColor BC = new BaseColor(164, 188, 196);

    document.add(title);
    document.add(emptyLine);
    emptyLine = new Paragraph(" ");
    Date dNow = new Date();
    SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
    //    addEmptyLine(emptyLine, 0);
    document.add(new Paragraph("Report created on : " + ft.format(dNow), small));
    document.add(emptyLine);
    document.add(emptyLine);
    document.add(emptyLine);
    document.add(new Paragraph("Test Summary Report", subFont));
    // document.add(emptyLine);
    PdfPTable table = createTable1();

    PdfPTable table2 = createTable2();
    document.add(new Paragraph(" "));
    document.add(emptyLine);
    document.add(table);
    document.add(emptyLine);
    document.add(emptyLine);
    document.add(emptyLine);
    document.add(new Paragraph("Test Error Report", subFont));
    document.add(emptyLine);
    document.add(emptyLine);
    document.add(table2);
    table.setSpacingBefore(5);
    table.setSpacingAfter(5);
    table2.setSpacingBefore(5);
    table2.setSpacingAfter(5);
    // step 5
    //adding  graphs

    //PdfWriter writer ;
    //  writer = PdfWriter.getInstance(document, outputStream);
    Image[] img = new Image[5];

    img[0] = createGraphs("Average Response Time of samples for each Request", "Average(ms)", 2); // df *add 90%line and no of samples to csv summary model table
    img[1] = createGraphs("Number of samples processed for each Request", "Number of Samples", 2);
    img[2] = createGraphs("Error % of samples for each Request", "Error %", 6);
    img[3] = createGraphs("Throughput of samples for each Request", "Throughput(ms)", 7);
    img[4] = createGraphs("90 % Line of samples for each Request", "90% line(ms)", 2);

    // document.add(image1);

    document.add(img[0]);
    // document.

    //release resources 
    document.close();
    document = null;

}

From source file:org.cidte.sii.negocio.PDFWriter.java

public void writePDF(ArrayList<Writable> list, String directorio, String nombre, java.awt.Image image)
        throws DocumentException, FileNotFoundException, BadElementException, IOException {

    Document doc = new Document();
    PdfWriter docWriter;/*from ww w .  j a v a  2  s  . c o m*/

    // special font sizes
    Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
    Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12);

    // file path
    String path = directorio + nombre + ".pdf";
    docWriter = PdfWriter.getInstance(doc, new FileOutputStream(new File(path)));

    // document header attributes
    doc.addAuthor("sii");
    doc.addCreationDate();
    doc.addProducer();
    doc.addCreator("sii");
    doc.addTitle(nombre);
    doc.setPageSize(PageSize.LETTER);

    // open document
    doc.open();

    Image img = Image.getInstance(image, null);
    img.setAlignment(Element.ALIGN_LEFT);
    doc.add(img);

    // create a paragraph
    Paragraph paragraph = new Paragraph("iText  is a library that allows you to create and "
            + "manipulate PDF documents. It enables developers looking to enhance web and other "
            + "applications with dynamic PDF document generation and/or manipulation.");

    // create PDF table with the given widths
    PdfPTable table = new PdfPTable(list.get(0).getNames().length);
    // set table width a percentage of the page width
    table.setWidthPercentage(100);
    table.setSpacingBefore(10f); // Space before table
    table.setSpacingAfter(10f); // Space after table

    // insert column headings
    String[] headings = list.get(0).getNames();
    for (String heading : headings) {
        insertCell(table, heading, Element.ALIGN_CENTER, 1, bfBold12);
    }
    table.setHeaderRows(1);

    // insert the data
    for (int i = 0; i < list.size(); i++) {
        Writable w = list.get(i);
        Object[] arr = w.getAsArray();
        for (int j = 0; j < arr.length; j++) {
            // arr[j]
            insertCell(table, arr[j].toString(), Element.ALIGN_LEFT, 1, bf12);
        }
    }

    // insert an empty row
    // insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);
    // add the PDF table to the paragraph
    paragraph.add(table);
    // add the paragraph to the document
    doc.add(paragraph);

    // close the document
    doc.close();

    // close the writer
    docWriter.close();

}

From source file:org.inspira.condominio.pdf.DocumentoEgresos.java

public void exportarPdf(String destino) throws IOException, DocumentException {
    File file = new File(destino);
    file.getParentFile().mkdirs();/*from w  w  w.  ja v  a2 s  . c  o  m*/
    PdfWriter.getInstance(documento, new FileOutputStream(file));
    documento.open();
    documento.add(new Paragraph(
            "Periodo: ".concat(
                    DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(new Date())),
            F_NORMAL));
    documento.add(new Paragraph(admin, F_NORMAL));
    Paragraph heading = new Paragraph("Gastos ".concat(tipoDeGasto),
            new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000)));
    heading.setSpacingBefore(16f);
    heading.setSpacingAfter(16f);
    Paragraph heading2 = new Paragraph("Autoriz",
            new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL, new BaseColor(0x000000)));
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    Paragraph heading3 = new Paragraph("Vo. Bo.",
            new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL, new BaseColor(0x000000)));
    PdfPCell cell1 = new PdfPCell(heading2);
    cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell1.setColspan(1);
    cell1.setFixedHeight(20f);
    cell1.setBorder(Rectangle.NO_BORDER);
    PdfPCell cell2 = new PdfPCell(heading3);
    cell2.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell2.setColspan(1);
    cell2.setFixedHeight(20f);
    cell2.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell1);
    table.addCell(cell2);
    table.setSpacingBefore(16f);
    table.setSpacingAfter(32f);

    documento.add(heading);
    agregarTablaEgresos(egresos);
    documento.add(table);
    agregarZonaVistoBueno();
    documento.close();
}

From source file:org.inspira.condominio.pdf.DocumentoEstadoDeCuenta.java

private void bakeContent(String path, String imgResString) throws IOException, DocumentException {
    File outFile = new File(path);
    outFile.getParentFile().mkdirs();//from  www. j a v  a 2 s.  com
    PdfWriter.getInstance(documento, new FileOutputStream(outFile));
    documento.open();
    documento.add(new Paragraph(
            "Ciudad de Mxico, "
                    + DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(new Date()),
            new Font(FontFamily.HELVETICA, 18, Font.NORMAL, new BaseColor(0x000000))));
    Paragraph intro = new Paragraph(new Phrase("Comprobante de estado de cuenta", F_NORMAL));
    intro.setAlignment(Paragraph.ALIGN_RIGHT);
    intro.setSpacingBefore(10f);
    documento.add(intro);
    Image image = Image.getInstance(imgResString);
    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(image.getScaledWidth());
    table.setLockedWidth(true);
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);
    //cell.setCellEvent(new ImageBackgroundEvent(image));
    cell.setFixedHeight(image.getScaledHeight());
    table.addCell(cell);
    documento.add(table);
    Paragraph p1 = new Paragraph("Estado de cuenta: ".concat(idEdoCta), F_NORMAL);
    p1.setSpacingBefore(5f);
    p1.setSpacingAfter(25f);
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    documento.add(p1);
    documento.add(new Paragraph("Pagos", F_NORMAL));
    agregaTablaDePagos();
    Paragraph pNotas = new Paragraph("Notas: ".concat(notas), F_NORMAL);
    pNotas.setSpacingAfter(12f);
    pNotas.setSpacingAfter(2f);
    documento.add(pNotas);
    Paragraph pAdeudos = new Paragraph("Adeudos", F_NORMAL);
    pAdeudos.setSpacingBefore(25f);
    documento.add(pAdeudos);
    agregaTablaDeAdeudos();
    documento.add(new Paragraph(
            "Recuerde que puede consultar su estado de pagos y adeudos desde la aplicacin mvil o directamente con su administrador.",
            F_NORMAL));
    Paragraph hechoPor = new Paragraph("Elabor:", F_NORMAL);
    hechoPor.setSpacingBefore(30f);
    hechoPor.setSpacingAfter(15f);
    documento.add(hechoPor);
    Paragraph nombreDelAdmin = new Paragraph(admin, F_NORMAL);
    nombreDelAdmin.setAlignment(Paragraph.ALIGN_CENTER);
    documento.add(nombreDelAdmin);
    Paragraph nombreDeCondominio = new Paragraph(condominio, F_NORMAL);
    nombreDeCondominio.setAlignment(Paragraph.ALIGN_CENTER);
    documento.add(nombreDeCondominio);
}

From source file:org.inspira.condominio.pdf.DocumentoIngreso.java

public void exportarPdf(String destino, String nombreInmueble, String dir)
        throws IOException, DocumentException {
    File file = new File(destino);
    PdfWriter.getInstance(documento, new FileOutputStream(file));
    documento.open();// ww w.ja va2  s.c  o m
    Paragraph inmueble = new Paragraph(nombreInmueble,
            new Font(Font.FontFamily.HELVETICA, 26, Font.BOLD, new BaseColor(0x000000)));
    inmueble.setSpacingAfter(8f);
    documento.add(inmueble);
    documento.add(new Paragraph(dir, F_NORMAL));
    documento.add(new Paragraph(
            "Periodo: ".concat(
                    DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(new Date())),
            F_NORMAL));
    Paragraph heading = new Paragraph("Formato de ingresos ordinario",
            new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000)));
    heading.setSpacingBefore(16f);
    heading.setSpacingAfter(16f);
    Paragraph heading2 = new Paragraph("Cobranza ordinaria",
            new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000)));
    heading2.setSpacingBefore(16f);
    heading2.setSpacingAfter(16f);
    Paragraph heading3 = new Paragraph("Formato de ingresos extraordinario",
            new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000)));
    heading3.setSpacingBefore(16f);
    heading3.setSpacingAfter(16f);
    Paragraph heading4 = new Paragraph("Cobranza extraordinaria",
            new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000)));
    heading4.setSpacingBefore(16f);
    heading4.setSpacingAfter(16f);
    documento.add(heading);
    totalRegular = addTablaFormatoIngresos(infoIngresos);
    documento.add(heading2);
    addTablaCobranza(infoIngresos);
    documento.add(heading3);
    totalExtra = addTablaFormatoIngresos(infoIngresosExtra);
    documento.add(heading4);
    addTablaCobranza(infoIngresosExtra);
    Paragraph heading5 = new Paragraph(
            String.format("TOTAL DE INGRESOS: %.2f pesos", totalRegular + totalExtra),
            new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, new BaseColor(0x000000)));
    heading5.setSpacingBefore(16f);
    heading5.setSpacingAfter(16f);
    documento.add(heading5);
    documento.close();
}