private void addMetaData(Document document) {
   document.addTitle("My first PDF");
   document.addSubject("Using iText");
   document.addKeywords("Java, PDF, iText");
   document.addAuthor("Lars Vogel");
   document.addCreator("Lars Vogel");
 }
 private void addHeader(Document document, Examination examination) throws DocumentException {
   Paragraph p;
   p = new Paragraph("SZÁMLA", headerFont);
   document.add(p);
   p = new Paragraph("Számlaszám: " + examination.getInvoice().getInvoiceId(), boldDataFont);
   p.setAlignment(Element.ALIGN_RIGHT);
   addEmptyLine(p, 2);
   document.add(p);
 }
  private void addSaleData(Document document, Examination examination) throws DocumentException {
    PdfPTable table = new PdfPTable(4);
    table.setWidthPercentage(100);
    table.setSpacingBefore(10);
    table.setSpacingAfter(10);
    table.setWidths(new int[] {7, 5, 2, 2});
    table.addCell(getCell("Csoport", Element.ALIGN_CENTER, boldtableHeaderFont));
    table.addCell(getCell("Megjegyzés", Element.ALIGN_CENTER, boldtableHeaderFont));
    table.addCell(getCell("Ár", Element.ALIGN_CENTER, boldtableHeaderFont));
    table.addCell(getCell("Összesen", Element.ALIGN_CENTER, boldtableHeaderFont));

    for (InvoiceGroups invoiceGroup : examination.getInvoice().getInvoiceGroup()) {
      PdfPCell invoiceGroupCell = getCell(invoiceGroup.getName(), Element.ALIGN_LEFT, boldDataFont);
      invoiceGroupCell.setColspan(3);
      table.addCell(invoiceGroupCell);
      table.addCell(
          getCell(invoiceGroup.getNetPrice().toString(), Element.ALIGN_LEFT, boldDataFont));

      if (invoiceGroup.getItems() != null && invoiceGroup.getItems().size() != 0) {
        for (Item item : invoiceGroup.getItems()) {
          table.addCell(getCell("", Element.ALIGN_LEFT, dataFont));
          table.addCell(getCell(item.getDescription(), Element.ALIGN_LEFT, dataFont));
          table.addCell(getCell(item.getPrice().toString(), Element.ALIGN_LEFT, dataFont));
          table.addCell(getCell("", Element.ALIGN_LEFT, dataFont));
        }
      }
    }
    document.add(table);
  }
  private void generateInvoicePDFByExamination(
      Examination examination, HttpServletResponse response) throws FileNotFoundException {
    Document document = new Document();

    response.setHeader("Accept-ranges", "bytes");
    response.setContentType("application/pdf");
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Content-Description", "File Transfer");
    response.setHeader("Content-Transfer-Encoding:", "binary");

    try {
      PdfWriter.getInstance(document, response.getOutputStream());
      document.open();
      addMetaData(document);
      addTitlePage(document, examination);
      document.close();
    } catch (DocumentException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 private void addBuyerAndSeller(Document document, Examination examination)
     throws DocumentException {
   PdfPTable table = new PdfPTable(2);
   table.setWidthPercentage(100);
   PdfPCell seller = getPartyAddress("Kibocsátó:", "Ceg neve", "Ceg Varosa", "Ceg cime");
   table.addCell(seller);
   PdfPCell buyer =
       getPartyAddress(
           "Vevő:",
           examination.getPatient().getName(),
           examination.getPatient().getCity(),
           examination.getPatient().getAddress());
   table.addCell(buyer);
   document.add(table);
 }
 private void addNewLine(Document document) throws DocumentException {
   Paragraph p = new Paragraph("", headerFont);
   addEmptyLine(p, 2);
   document.add(p);
 }
  private void addSummaryData(Document document, Examination examination) throws DocumentException {
    BigDecimal tax = examination.getNetPrice().multiply(new BigDecimal("0.25"));

    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);
    table.setWidths(new int[] {3, 3, 3, 2, 4});
    PdfPCell dateInformationLabelCell = new PdfPCell();
    dateInformationLabelCell.addElement(new Paragraph("Számla dátuma:", boldDataFont));
    dateInformationLabelCell.addElement(new Paragraph("Fizetési határidő:", boldDataFont));
    dateInformationLabelCell.addElement(new Paragraph("Fizetés dátuma:", boldDataFont));
    dateInformationLabelCell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(dateInformationLabelCell);

    PdfPCell dateInformation = new PdfPCell();
    dateInformation.addElement(
        new Paragraph(
            convertDate(examination.getInvoice().getInvoiceDate(), "yyyy.MM.dd"), dataFont));
    dateInformation.addElement(
        new Paragraph(
            convertDate(examination.getInvoice().getDayOfPayment(), "yyyy.MM.dd"), dataFont));
    dateInformation.addElement(
        new Paragraph(
            convertDate(examination.getInvoice().getDayOfPayment(), "yyyy.MM.dd"), dataFont));
    dateInformation.setBorder(PdfPCell.NO_BORDER);
    table.addCell(dateInformation);

    PdfPCell cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    PdfPCell payInformation = new PdfPCell();
    payInformation.addElement(new Paragraph("Összesen: ", boldDataFont));
    payInformation.setBorder(PdfPCell.NO_BORDER);
    table.addCell(payInformation);

    PdfPCell payDatas = new PdfPCell();
    payDatas.setHorizontalAlignment(Element.ALIGN_RIGHT);
    payDatas.disableBorderSide(Rectangle.BOX);
    payDatas.addElement(new Paragraph(examination.getNetPrice().toString(), dataFont));
    payDatas.addElement(new Paragraph(tax.toString(), dataFont));
    payDatas.addElement(new Paragraph("_______", dataFont));
    payDatas.addElement(new Paragraph(examination.getBrutPrice().toString(), dataFont));
    payDatas.setBorder(PdfPCell.NO_BORDER);
    table.addCell(payDatas);

    /*      PdfPTable tbl = new PdfPTable(2);
    PdfPCell cell = new PdfPCell(new Phrase("some random text"));
    cell.disableBorderSide(Rectangle.BOX);
    tbl.addCell(cell);
    cell = new PdfPCell(new Phrase("1."));
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.disableBorderSide(Rectangle.BOX);
    tbl.addCell(cell);
    cell = new PdfPCell(new Phrase("34."));
    cell.disableBorderSide(Rectangle.BOX);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tbl.addCell(cell);
    cell = new PdfPCell(new Phrase("some more random text"));
    cell.disableBorderSide(Rectangle.BOX);
    tbl.addCell(cell);*/

    document.add(table);
  }