Example usage for com.itextpdf.text Paragraph add

List of usage examples for com.itextpdf.text Paragraph add

Introduction

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

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:Model.Emprestimo.java

private void resultado() {
    Document documento = new Document();
    Livro l;/*from   www  .  j a v a2  s  .co m*/
    try {
        PdfWriter.getInstance(documento, new FileOutputStream("Emprestimo" + id() + ".pdf"));
    } catch (DocumentException ex) {
        Logger.getLogger(Emprestimo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Emprestimo.class.getName()).log(Level.SEVERE, null, ex);
    }
    documento.open();

    try {
        Paragraph pa = new Paragraph();
        Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 28, Font.BOLD, new BaseColor(0, 0, 225));
        pa.setFont(fonte);
        pa.setAlignment(Element.ALIGN_CENTER);
        pa.setSpacingAfter(50);
        pa.add("Emprestimo");
        documento.add(pa);
        fonte = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
        pa = new Paragraph();
        pa.setFont(fonte);
        pa.setAlignment(Element.ALIGN_LEFT);
        pa.add("id: " + Integer.toString(id()));
        documento.add(pa);
        pa = new Paragraph();
        pa.setFont(fonte);
        pa.setAlignment(Element.ALIGN_LEFT);
        pa.add("ra: " + Integer.toString(this.getRa()));
        documento.add(pa);
        String lin = "";
        String[] h = this.Livros.split("/");
        for (int c = 0; c < h.length; c++) {
            l = new Livro();
            l.consultar(Integer.parseInt(h[c]));
            lin = lin + l.getNome() + "\n";
        }
        pa = new Paragraph();
        pa.setFont(fonte);
        pa.setAlignment(Element.ALIGN_LEFT);
        pa.add("Livros: " + lin);
        documento.add(pa);
        pa = new Paragraph();
        pa.setFont(fonte);
        pa.setAlignment(Element.ALIGN_LEFT);
        pa.add("Data de Realizao: " + this.dataR);
        documento.add(pa);
        pa = new Paragraph();
        pa.setFont(fonte);
        pa.setAlignment(Element.ALIGN_LEFT);
        pa.add("Data de Devoluo: " + this.dataD);
        documento.add(pa);
    } catch (DocumentException ex) {
        Logger.getLogger(Emprestimo.class.getName()).log(Level.SEVERE, null, ex);
    }
    documento.close();
}

From source file:Model.GerarRelatorio.java

public void preenche() throws ParseException {
    MainFrameSLM.getInstance().getStatusBar().setProcesso("Realizando a consulta");
    ArrayList<HashMap> registros = new RelatorioDB().getRegistros(relatorio.getSelect(), restricoes, orderBy);
    int contadorDePreenchimento = 0;
    MainFrameSLM.getInstance().getStatusBar().setProcesso("Montando o relatrio");
    for (int x = 0; x < registros.size(); x++) {
        registros.get(x).entrySet().toArray();
        while (contadorDePreenchimento < columnswidth.length) {
            for (Object registro : registros.get(x).entrySet().toArray()) {
                String temp = registro.toString();
                int separador = temp.indexOf("=");
                String temp2 = temp.substring(0, separador);
                String temp3 = temp.substring(separador + 1, temp.length());
                if (getNmAtributo(temp2).equalsIgnoreCase(columnName[contadorDePreenchimento])) {
                    if (temp.contains("DT")) {
                        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
                        insertCell(pdfPTable, sdf.format(new Date(Timestamp.valueOf(temp3).getTime())),
                                Element.ALIGN_LEFT, 1, tableContent);
                    } else {
                        insertCell(pdfPTable, temp3.equalsIgnoreCase("null") ? "" : temp3, Element.ALIGN_LEFT,
                                1, tableContent);
                    }/*from  w ww . j  a  v a  2  s  .c o m*/
                    contadorDePreenchimento++;
                }
                if (contadorDePreenchimento >= columnswidth.length) {
                    break;
                }
            }
        }
        contadorDePreenchimento = 0;
    }

    /*for (OrdemDeServico os : ordens) {
     String ordem = null;
     JFormattedTextField jft = new JFormattedTextField();
     MaskFormatter maskFormatter = new MaskFormatter(new Utilidades().mascaraOrdem(os.getNumeroOrdem()));
     maskFormatter.install(jft);
     jft.setText(String.valueOf(os.getNumeroOrdem()));
     ordem = jft.getText();
     SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
     insertCell(pdfPTable, ordem, Element.ALIGN_LEFT, 1, tableContent);
     insertCell(pdfPTable, sdf.format(os.getDataEmissao()), Element.ALIGN_LEFT, 1, tableContent);
     insertCell(pdfPTable, os.getServicosAExecutar(), Element.ALIGN_LEFT, 1, tableContent);
     double valor = 0;
     for (MaoDeObra mao : os.getMaoDeObra()) {
     valor += mao.getQtd();
     }
     String Metragem = String.valueOf(valor);
     Metragem = Metragem.replace(".", ",");
     insertCell(pdfPTable, Metragem, Element.ALIGN_LEFT, 1, tableContent);
     for (Equipe equipe : equipes) {
     if (equipe.getId() == os.getEquipe()) {
     insertCell(pdfPTable, equipe.getNomeEquipe(), Element.ALIGN_LEFT, 1, tableContent);
     break;
     }
     }
     insertCell(pdfPTable, os.getObs(), Element.ALIGN_LEFT, 1, tableContent);
            
     }*/
    Paragraph p = new Paragraph();
    pdfPTable.setWidthPercentage(100);
    p.add(pdfPTable);
    paragrafos.add(p);
}

From source file:Model.GerarRelatorio.java

public void toParagraphs(String linha, int alinhamento) {
    Paragraph p = new Paragraph();
    p.add(linha);
    p.setAlignment(alinhamento);/*ww  w . ja  va2 s.c  om*/
    paragrafos.add(p);
}

From source file:Model.MyPdfDocument.java

License:Open Source License

/**
 * Write the pdf file//from   ww  w  . j  a  v a  2  s  .c o m
 * Escreve o arquivo pdf
 */
private void write(ArrayList<ArrayList<String>> stList, String filename)
        throws DocumentException, FileNotFoundException, UnsupportedEncodingException {
    Document document = null;

    try {
        document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();

        MyFontSelector myFontSelector = MyFontSelector.getInstance();
        FontSelector fontSelector;
        Phrase phrase;

        for (ArrayList<String> stL : stList) {

            fontSelector = myFontSelector.getFontSelector("TITLE");
            phrase = fontSelector.process(stL.remove(0));
            document.add(new Paragraph(phrase));

            Paragraph paragraph = new Paragraph();
            addEmptyLine(paragraph, 1);

            for (String st : stL) {
                fontSelector = myFontSelector.getFontSelector(getFontString(st));

                /**
                 * In Windows we have some problems with Latin characters
                 * and we need to forces the encoding to UFT8
                 * 
                 * No Windows tivemos alguns problemas com caracteres latinos
                 * e foi necessrio forar a codificao para UTF8
                 */
                if (isWindows()) {
                    st = new String(st.getBytes(), "UTF8");
                }

                st = replace(st);

                phrase = fontSelector.process(st);
                paragraph.add(phrase);
            }

            document.add(paragraph);
            document.newPage();
        }

    } catch (DocumentException ex) {
        throw new DocumentException("Read error");
    } catch (FileNotFoundException ex) {
        throw new FileNotFoundException("File [" + filename + "] not found");
    } finally {
        if (document != null) {
            document.close();
        }
    }
}

From source file:Model.MyPdfDocument.java

License:Open Source License

/**
 * Add a empty line/*from w w w  .  j a va 2  s.  c o  m*/
 * Adiciona uma linha em branco
 * Method addEmptyLine as seen in: http://www.vogella.com/tutorials/JavaPDF/article.html
 */
private void addEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }
}

From source file:mvjce.PDF.java

public static void create(int sino) {// sino = SI.No
    // TODO code application logic here
    try {/*from  w ww . jav  a2s.  com*/
        //Create Document instance.
        Document document = new Document();

        //Create OutputStream instance.
        OutputStream outputStream = new FileOutputStream(
                new File("/home/narein/NetBeansProjects/" + sem + cl + "/" + usn + ".pdf"));

        //Create PDFWriter instance.
        PdfWriter.getInstance(document, outputStream);

        //Open the document.
        document.open();
        //image position
        Image imageCenter = Image.getInstance("/home/narein/Downloads/mvj.png");
        //imageCenter.setAlignment(Image.MIDDLE);
        imageCenter.setAbsolutePosition(235, 780);
        imageCenter.scaleAbsolute(146f, 53f);
        //Permanently affiliated para
        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.addCell(getCell(
                "\n\n\nPermanently affiliated to VTU, Govt. of Karnataka\nApproved by AICTE, New Delhi\nNear ITPB, Bengaluru- 560067\n\n"
                        + hod_name + ", HOD - " + dep,
                PdfPCell.ALIGN_LEFT));
        table.addCell(getCell("\n\n\n\nPh: 080-42991000\nFax: 080-28452443\nWebsite: www.mvjce.edu.in\nEmail: "
                + hod_email + "\n\n", PdfPCell.ALIGN_RIGHT));
        //line across pdf
        final LineSeparator lineSeparator = new LineSeparator();
        Chunk linebreak = new Chunk(lineSeparator);
        Phrase p = new Phrase("\nPROGRESS REPORT\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Paragraph para = new Paragraph(p);
        para.setAlignment(Element.ALIGN_CENTER);
        Chunk glue = new Chunk(new VerticalPositionMark());
        Paragraph p1 = new Paragraph("\nRef:", new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        p1.add(new Chunk(glue));
        //get current date
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
        LocalDate localDate = LocalDate.now();
        //add date to pdf
        p1.add(new Phrase("Date: " + dtf.format(localDate) + "\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
        Phrase dear_prnts = new Phrase("Dear Parents,\n", new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        Phrase The_acad = new Phrase(
                "                  The academic performance of your ward Mr/Ms " + name + " of Semester " + sem
                        + " bearing the USN " + usn + " is as follows,\n\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Phrase Rem = new Phrase("Remarks\n", new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Phrase your_ward = new Phrase(
                "\nYour ward's overall performance is Good / Satisfactory / Poor / Very Poor\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Phrase you_are = new Phrase("\nYou are requested to:\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        Phrase req = new Phrase("");
        Paragraph para2 = new Paragraph(
                "1) Advice your ward to attend classes regularly\n2) Note that he/she may likely be detainedfrom appearing for examinations\n"
                        + "3) Advice your ward to improve in Test/Exam performance particularly in subject\n4) Meet the Head of the Department\n5) Meet the principal\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Chunk glue1 = new Chunk(new VerticalPositionMark());
        Paragraph p3 = new Paragraph("\nSIGNATURE:\n\nNAME OF PROCTOR:\n\nCONTACT NUMBER:",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        p3.add(new Chunk(glue1));
        p3.add(new Phrase(
                "SIGNATURE OF HOD\n\n            Kindly attend the Parent Teacher Meeting to be held on the date informed to your ward.\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
        Phrase Note = new Phrase("\nNOTE:", new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Paragraph p4 = new Paragraph();
        p4.add(Note);
        p4.add(new Phrase(
                "  Parents are requested to contact the proctor (By Email/Letter/Phone) and confirm receipt of this feedback. Parents are also"
                        + "welcome to interact with proctors/subject faculty/ HOD for any discussion/clarification.\n",
                new Font(FontFamily.TIMES_ROMAN, 9)));
        //Add content to the document.
        document.add(imageCenter);
        document.add(table);
        document.add(linebreak);
        document.add(para);
        document.add(p1);
        document.add(dear_prnts);
        document.add(The_acad);
        document.add(createinternalsTable());
        if (internal.equals("1")) {
            document.add(new Phrase("\nPREVIOUS SEMESTER VTU RESULT\n\n",
                    new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD)));
            document.add(createexternalTable());
        }
        document.add(Rem);
        document.add(your_ward);
        document.add(you_are);
        document.add(para2);
        document.add(p3);
        document.add(p4);
        //document.add(paragraph);document.add(paragraph1);

        //Close document and outputStream.
        document.close();
        outputStream.close();

        System.out.println("Pdf created successfully.");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:negotiation.Contract.FormContractPdf.java

public static void addTitlePage(Document document, String service) throws DocumentException {
    glo_service = service;//from  w w  w.  j a  v  a  2 s  .  co m
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);
    // Lets write a big header
    preface.add(new Paragraph("SLA on " + service, catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    /*preface.add(new Paragraph("Report generated by: Sophia" + ", " + new Date(), smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes SLA",
        smallBold));
            
    addEmptyLine(preface, 8);
            
    preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
        redFont));
            
    document.add(preface);
    // Start a new page
    document.newPage();*/
}

From source file:negotiation.Contract.FormContractPdf.java

public static void addContents(Document document) throws DocumentException {
    Anchor anchor = new Anchor("Contract", catFont);
    anchor.setName("Contract");

    Paragraph para = new Paragraph();
    para.add(new Paragraph("1. General", subFont));
    String para1 = ContractContents.addGeneral("userA", "ManagerD", "aws", "2014", "2015");
    para.add(para1);/*from   w w  w . j av  a2s  . c o m*/
    addEmptyLine(para, 1);

    para.add(new Paragraph("2. Scope & description of the service", subFont));
    String para2 = ContractContents.addDescription("aws-ec2", "www.aws.com", "computing service");
    para.add(para2);

    para.add(new Paragraph("3. Service hours & exceptions", subFont));
    String para3 = ContractContents.addTime("2014", "2015");
    para.add(para3);

    para.add(new Paragraph("4. Service components & dependencies", subFont));
    String para4 = ContractContents.addComponents("aws-ec2", "computing service");
    para.add(para4);

    para.add(new Paragraph("5. Support", subFont));
    String para5 = ContractContents.addSupport("University of Manchester", "Mon-Fri: 9:00am - 5:00pm");
    para.add(para5);

    para.add(new Paragraph("5.1 Incident handling", smallBold));
    String para6 = ContractContents.addHandling("Incident handling ...");
    para.add(para6);

    para.add(new Paragraph("5.2 Fulfillment of service requests", smallBold));
    String para7 = ContractContents.addFulfillment("Fulfillment ...");
    para.add(para7);

    para.add(new Paragraph("6. Service level targets", subFont));
    String para8 = AwsEc2ContractContents.addTargets();
    //String para8 = ContractContents.addTargets("Availability", "24 hours");
    para.add(para8);

    para.add(new Paragraph("7. Limitations & constaints", subFont));
    String para9 = AwsEc2ContractContents.addConstaints();
    //String para9 = ContractContents.addConstaints("Wordload limits...");
    para.add(para9);

    para.add(new Paragraph("8. Communication, reporting & escalation", subFont));
    para.add(new Paragraph("8.1 General communication", smallBold));
    String para10 = ContractContents.addContacts("123", "456", "789");
    para.add(para10);

    para.add(new Paragraph("8.2 Regular reporting", smallBold));
    String para11 = ContractContents.addReport("20150520", "regular check", "once a week",
            "University of Manchester.");
    para.add(para11);

    para.add(new Paragraph("8.3 SLA violations", smallBold));
    String para12 = AwsEc2ContractContents.addViolations();
    //String para12 = ContractContents.addViolations("Penalty required when performance cannot rearch agreed SLAs.");
    para.add(para12);

    para.add(new Paragraph("8.4 Escalation & complaints", smallBold));
    String para13 = ContractContents
            .addEscalation("Please contact University of Manchester via provided email.");
    para.add(para13);

    para.add(new Paragraph("9. Information security & data protection", subFont));
    String para14 = ContractContents
            .addProtection("All the data should be kept within University of Manchester network domain.");
    para.add(para14);

    para.add(new Paragraph("10. Additional responsibilities of the service provider", subFont));
    String para15 = ContractContents.addProviderResp("Provider should ...");
    para.add(para15);

    para.add(new Paragraph("11. Customer responsibilities", subFont));
    String para16 = ContractContents.addCustomerResp("Customer should ...");
    para.add(para16);

    para.add(new Paragraph("12. Review", subFont));
    String para17 = ContractContents.addReview("Review should be taken...");
    para.add(para17);

    para.add(new Paragraph("13. Glossary of terms", subFont));
    String para18 = AwsEc2ContractContents.addTerms();
    //String para18 = ContractContents.addTerms("aws-ec2", "computing services");
    para.add(para18);

    para.add(new Paragraph("14. Document control", subFont));
    String para19 = ContractContents.addControl(55555, "SLA on" + glo_service, "University of Manchester",
            "University of Manchester", "1.0", "2015", "2016", "No change so far");
    para.add(para19);

    document.add(para);
}

From source file:net.vzurczak.timesheetgenerator.PdfGenerator.java

License:Apache License

/**
 * Adds a page for a given week./*from   w ww .  ja  v a 2 s .c  o  m*/
 * @param i the week number
 * @param doc the document to update
 * @param bean a generation bean (not null)
 * @throws DocumentException
 */
private void addPageForWeek(int weekNumber, Document doc, GenerationDataBean bean) throws DocumentException {

    doc.newPage();
    final Font boldFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD);
    final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA);
    Calendar calendar = Utils.findCalendar(weekNumber);

    // Title
    Paragraph paragraph = new Paragraph("Bordereau de Dclaration des Temps", boldFont);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    doc.add(paragraph);

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

    // Meta: week
    final PdfPTable metaTable = new PdfPTable(1);

    paragraph = new Paragraph();
    paragraph.add(new Chunk("Semaine : ", boldFont));
    paragraph.add(new Chunk(String.valueOf(weekNumber), normalFont));

    PdfPCell c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    metaTable.addCell(c);

    // Meta: date
    Calendar endOfWeekCalendar = ((Calendar) calendar.clone());
    endOfWeekCalendar.add(Calendar.DATE, 4);
    String formattedDate = new SimpleDateFormat("dd/MM/yyyy").format(endOfWeekCalendar.getTime());

    paragraph = new Paragraph();
    paragraph.add(new Chunk("Date : ", boldFont));
    paragraph.add(new Chunk(formattedDate, normalFont));

    c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    metaTable.addCell(c);

    doc.add(metaTable);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    // Signatures
    final PdfPTable signaturesTable = new PdfPTable(2);
    paragraph = new Paragraph();
    paragraph.add(new Chunk("Nom : ", boldFont));
    paragraph.add(new Chunk(bean.getName(), normalFont));

    c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    paragraph = new Paragraph();
    paragraph.add(new Chunk("Responsable : ", boldFont));
    paragraph.add(new Chunk(bean.getManagerName(), normalFont));

    c = new PdfPCell(paragraph);
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    c = new PdfPCell(new Paragraph("Signature : ", boldFont));
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    c = new PdfPCell(new Paragraph("Signature : ", boldFont));
    c.setBorder(Rectangle.NO_BORDER);
    signaturesTable.addCell(c);

    doc.add(signaturesTable);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    // Calendar
    final PdfPTable timeTable = new PdfPTable(7);
    timeTable.addCell(new PdfPCell());

    for (int i = 0; i < 5; i++) {
        final String date = this.sdf.format(calendar.getTime());
        timeTable.addCell(newCell(date, 10));
        calendar.add(Calendar.DATE, 1);
    }

    timeTable.addCell(newCell("Total", 10));
    timeTable.addCell(newCell("Heures Effectues", 20));

    for (int i = 0; i < 5; i++)
        timeTable.addCell(newCell("", 20));

    if (bean.getTotalHours() > 0)
        timeTable.addCell(newCell(bean.getTotalHours() + " h", 20));

    timeTable.completeRow();
    doc.add(timeTable);
}

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;/*from w  w  w.j  a  v  a  2s  . 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();
}