Example usage for com.itextpdf.text Chapter Chapter

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

Introduction

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

Prototype

public Chapter(String title, int number) 

Source Link

Document

Constructs a new Chapter.

Usage

From source file:has.GenerateReceipt.java

private static void addContent(Document document)
        throws DocumentException, IOException, SQLException, ClassNotFoundException {
    Anchor anchor = new Anchor("BILL DETAILS(Generated by HAS) on " + new Date(), catFont);
    // anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    addEmptyLine(preface, 2);//w w  w .j av  a 2 s. c o  m

    Statement stmt = null, stmt1 = null, stmt2 = null, stmt3 = null, stmt4 = null, stmt5 = null;
    Connection conn = null;
    String w = null;
    int found = 0;
    // System.out.println("At the start");
    try {
        conn = DriverManager.getConnection(url, user, password);
        stmt = conn.createStatement();
        stmt1 = conn.createStatement();
        stmt2 = conn.createStatement();
        stmt3 = conn.createStatement();
        stmt4 = conn.createStatement();
        stmt5 = conn.createStatement();
        // stmt1 = conn.createStatement();
    } catch (Exception rx) {
        System.out.println("in catch");
    }
    int present = 0;
    double minfre = 0;

    String sql2 = "SELECT id,Value FROM central";
    Vector tariff = null, discount = null, rates = null, totalbookings = null;
    ResultSet rsz = stmt.executeQuery(sql2);
    int iad;
    while (rsz.next()) {
        iad = rsz.getInt("id");

        if (iad == 9) {
            minfre = rsz.getDouble("Value");
        }
        if (iad == 10) {
            ObjectInputStream o = null;
            byte[] arr = rsz.getBytes("Value");
            tariff = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                tariff = (Vector) o.readObject();
            }
        }
        if (iad == 11) {
            ObjectInputStream o = null;
            byte[] arr = rsz.getBytes("Value");
            rates = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                rates = (Vector) o.readObject();
            }
        }

        if (iad == 12) {
            ObjectInputStream o = null;
            byte[] arr = rsz.getBytes("Value");
            totalbookings = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                totalbookings = (Vector) o.readObject();
            }
        }

        if (iad == 13) {
            ObjectInputStream o = null;
            byte[] arr = rsz.getBytes("Value");
            discount = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                discount = (Vector) o.readObject();
            }
        }

        if (iad == 14) {
            present = rsz.getInt("Value");
        }

    }

    String sql = "SELECT * FROM Customer ";
    ResultSet rs = null, rs1 = null;
    try {
        rs = stmt.executeQuery(sql);
    } catch (SQLException ex) {
        Logger.getLogger(CheckOut.class.getName()).log(Level.SEVERE, null, ex);
    }
    while (rs.next()) {
        int x = rs.getInt("ISAC");
        if (x == 2) {
            int y = rs.getInt("SCOD");
            if (present == y) {
                double Totalbill = 0, amount = 0;
                ObjectInputStream o = null;
                byte[] arr = rs.getBytes("Catering");
                Vector Catering = new Vector();
                if (arr != null) {
                    o = new ObjectInputStream(new ByteArrayInputStream(arr));
                    Catering = (Vector) o.readObject();
                }

                Paragraph subPara2 = new Paragraph(rs.getString("Name") + "  " + rs.getString("I"), subFont);
                Section subCatPart = catPart.addSection(subPara2);
                // Section subCatPart2 = catPart.addSection(subPara2);
                if (Catering.size() != 0) {

                    createTable(subCatPart, Catering);
                    System.out.println("Enterte in catering");
                    CateringObject obj = (CateringObject) Catering.elementAt(0);
                    Totalbill = obj.bill;
                    //    tb.addRow(new Object[]{new String(rs.getString("Name")),new String(rs.getString("I")),new String(obj.date),new String(obj.item),new Double(obj.bill) });
                    for (int f = 1; f < Catering.size(); f++) {
                        obj = (CateringObject) Catering.elementAt(f);
                        //    tb.addRow(new Object[]{new String(""),new String(""),new String(obj.date),new String(obj.item),new Double(obj.bill) });
                        Totalbill = Totalbill + obj.bill;
                    }
                    String updatestr = "UPDATE customer SET Catering = ?  WHERE id = " + rs.getInt("id");
                    PreparedStatement p = conn.prepareStatement(updatestr);
                    p.setObject(1, null);
                    p.executeUpdate();
                }
                int ap1 = rs.getInt("SCOD") - rs.getInt("SCID") + 1;
                int ap = rs.getInt("History") + ap1;
                System.out.println("ap1=" + ap1);
                System.out.println("ap=" + ap);
                sql = "UPDATE customer SET history= " + ap + " WHERE id= " + rs.getInt("id");
                System.out.println(sql);
                stmt1.executeUpdate(sql);
                sql = "UPDATE customer SET ISAC= 0 WHERE id= " + rs.getInt("id");
                System.out.println(sql);
                stmt5.executeUpdate(sql);
                int to = 0;
                String room = rs.getString("Room");
                String roompart = room.substring(0, 2);
                double roomrent = 0, tariffa = 0, discounta = 0, advance = 0;
                advance = rs.getDouble("RTP");
                System.out.println(roompart);
                if (roompart.equalsIgnoreCase("SA")) {
                    amount = ap1 * (int) rates.elementAt(0);
                    roomrent = amount;
                    System.out.println("roomrent=" + roomrent);
                    amount = amount + Totalbill;
                    tariffa = (amount * (double) tariff.elementAt(0)) / 100;
                    amount = amount + tariffa;
                    to = (int) totalbookings.elementAt(0);
                    to = to + ap1;
                    totalbookings.setElementAt(to, 0);
                }

                if (roompart.equalsIgnoreCase("SNA")) {
                    amount = ap1 * (int) rates.elementAt(1);
                    roomrent = amount;
                    amount = amount + Totalbill;
                    tariffa = (amount * (double) tariff.elementAt(1)) / 100;
                    amount = amount + (amount * (double) tariff.elementAt(1)) / 100;
                    to = (int) totalbookings.elementAt(1);
                    to = to + ap1;
                    totalbookings.setElementAt(to, 1);
                }
                if (roompart.equalsIgnoreCase("DA")) {
                    amount = ap1 * (int) rates.elementAt(2);
                    roomrent = amount;
                    amount = amount + Totalbill;
                    tariffa = (amount * (double) tariff.elementAt(2)) / 100;
                    amount = amount + (amount * (double) tariff.elementAt(2)) / 100;
                    to = (int) totalbookings.elementAt(2);
                    to = to + ap1;
                    totalbookings.setElementAt(to, 2);
                }
                if (roompart.equalsIgnoreCase("DNA")) {
                    amount = ap1 * (int) rates.elementAt(3);
                    roomrent = amount;
                    amount = amount + Totalbill;
                    tariffa = (amount * (double) tariff.elementAt(3)) / 100;
                    amount = amount + (amount * (double) tariff.elementAt(3)) / 100;
                    to = (int) totalbookings.elementAt(3);
                    to = to + ap1;
                    totalbookings.setElementAt(to, 3);
                }
                String updatestr = "UPDATE central SET Value = ?  WHERE id =12 ";
                PreparedStatement p = conn.prepareStatement(updatestr);
                p.setObject(1, totalbookings);
                p.executeUpdate();
                int history = rs.getInt("history");
                double cusfre = history / present;
                double minfree = (double) discount.elementAt(0);
                double minbill = (double) discount.elementAt(1);
                double d1 = (double) discount.elementAt(2);
                double d2 = (double) discount.elementAt(3);
                double d3 = (double) discount.elementAt(4);
                double d4 = (double) discount.elementAt(5);

                if (cusfre < minfree && amount < minbill) {
                    discounta = (amount * d1) / 100;
                    amount = amount - discounta;
                }
                if (cusfre < minfree && amount > minbill) {
                    discounta = (amount * d2) / 100;
                    amount = amount - discounta;
                }
                if (cusfre > minfree && amount < minbill) {
                    discounta = (amount * d3) / 100;
                    amount = amount - discounta;
                }
                if (cusfre > minfree && amount > minbill) {
                    discounta = (amount * d4) / 100;
                    amount = amount - discounta;
                }
                amount = amount - advance;
                //  tb2.addRow(new Object[]{new String(rs.getString("Name")),new String(rs.getString("I")),new Double(Totalbill),new Double(advance),new Double(roomrent),new Double(tariffa),new Double(discounta),new Double(amount)});
            }
        }
        if (x == 1) {
            Vector advancev = null, ecid = null, ecod = null, advanceroom = null;
            ObjectInputStream o = null;
            byte[] arr = rs.getBytes("Advance");
            advancev = new Vector();
            if (arr != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr));
                advancev = (Vector) o.readObject();
            }
            byte[] arr2 = rs.getBytes("Advance_room");
            advanceroom = new Vector();
            if (arr2 != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr2));
                advanceroom = (Vector) o.readObject();
            }
            byte[] arr3 = rs.getBytes("ECID");
            ecid = new Vector();
            if (arr3 != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr3));
                ecid = (Vector) o.readObject();
            }
            byte[] arr4 = rs.getBytes("ECOD");
            ecod = new Vector();
            if (arr4 != null) {
                o = new ObjectInputStream(new ByteArrayInputStream(arr4));
                ecod = (Vector) o.readObject();
            }

            for (int l = 0; l < ecod.size(); l++) {
                long y = (long) ecod.elementAt(l);
                if (present == y) {
                    double Totalbill = 0, amount = 0;
                    //  ObjectInputStream o = null;
                    byte[] arr1 = rs.getBytes("Catering");
                    Vector Catering = new Vector();
                    if (arr1 != null) {
                        o = new ObjectInputStream(new ByteArrayInputStream(arr1));
                        Catering = (Vector) o.readObject();
                    }
                    Paragraph subPara2 = new Paragraph(rs.getString("Name") + "  " + rs.getString("I"),
                            subFont);
                    Section subCatPart = catPart.addSection(subPara2);
                    if (Catering.size() != 0) {
                        createTable(subCatPart, Catering);
                        CateringObject obj = (CateringObject) Catering.elementAt(0);
                        Totalbill = obj.bill;
                        //tb.addRow(new Object[]{new String(rs.getString("Name")),new String(rs.getString("I")),new String(obj.date),new String(obj.item),new Double(obj.bill) });
                        for (int f = 1; f < Catering.size(); f++) {
                            obj = (CateringObject) Catering.elementAt(f);
                            //  tb.addRow(new Object[]{new String(""),new String(""),new String(obj.date),new String(obj.item),new Double(obj.bill) });
                            Totalbill = Totalbill + obj.bill;
                        }
                        String updatestr = "UPDATE customer SET Catering = ?  WHERE id = " + rs.getInt("id");
                        PreparedStatement p = conn.prepareStatement(updatestr);
                        p.setObject(1, null);
                        p.executeUpdate();
                    }

                    System.out.println("l == " + l);
                    System.out.println("size = " + ecod.size());
                    System.out.println(ecod);
                    System.out.println(ecid);
                    long ppp = (long) ecod.get(l);
                    long qqq = (long) ecid.get(l);
                    System.out.println("ecod = " + ppp);
                    System.out.println("ecid = " + qqq);
                    long ap1 = ppp - qqq + 1;
                    // sql="UPDATE customer SET ISAC=0 WHERE id= "+rs.getInt("id");
                    // stmt3.executeUpdate(sql);

                    int ap = rs.getInt("History") + (int) ap1;
                    sql = "UPDATE customer SET history=" + ap + " WHERE id= " + rs.getInt("id");
                    stmt4.executeUpdate(sql);

                    int to = 0;
                    String room = (String) advanceroom.elementAt(l);
                    String roompart = room.substring(0, 1);
                    double roomrent = 0, tariffa = 0, discounta = 0, advance = 0;
                    advance = Double.parseDouble((String) advancev.elementAt(l));
                    if (roompart.equalsIgnoreCase("SA")) {
                        amount = ap1 * (int) rates.elementAt(0);
                        roomrent = amount;
                        amount = amount + Totalbill;
                        tariffa = (amount * (double) tariff.elementAt(0)) / 100;
                        amount = amount + tariffa;
                        to = (int) totalbookings.elementAt(0);
                        to = to + (int) ap1;
                        totalbookings.setElementAt(to, 0);
                    }

                    if (roompart.equalsIgnoreCase("SNA"))
                        amount = (double) rates.elementAt(1);
                    {
                        amount = ap1 * (int) rates.elementAt(1);
                        roomrent = amount;
                        amount = amount + Totalbill;
                        tariffa = (amount * (double) tariff.elementAt(1)) / 100;
                        amount = amount + (amount * (double) tariff.elementAt(1)) / 100;
                        to = (int) totalbookings.elementAt(1);
                        to = to + (int) ap1;
                        totalbookings.setElementAt(to, 1);
                    }
                    if (roompart.equalsIgnoreCase("DA")) {
                        amount = ap1 * (int) rates.elementAt(2);
                        roomrent = amount;
                        amount = amount + Totalbill;
                        tariffa = (amount * (double) tariff.elementAt(2)) / 100;
                        amount = amount + (amount * (double) tariff.elementAt(2)) / 100;
                        to = (int) totalbookings.elementAt(2);
                        to = to + (int) ap1;
                        totalbookings.setElementAt(to, 2);
                    }
                    if (roompart.equalsIgnoreCase("DNA")) {
                        amount = ap1 * (int) rates.elementAt(3);
                        roomrent = amount;
                        amount = amount + Totalbill;
                        tariffa = (amount * (double) tariff.elementAt(3)) / 100;
                        amount = amount + (amount * (double) tariff.elementAt(3)) / 100;
                        to = (int) totalbookings.elementAt(3);
                        to = to + (int) ap1;
                        totalbookings.setElementAt(to, 3);
                    }
                    String updatestr = "UPDATE central SET Value = ?  WHERE id =12 ";
                    PreparedStatement p = conn.prepareStatement(updatestr);
                    p.setObject(1, totalbookings);
                    p.executeUpdate();
                    int history = rs.getInt("history");
                    double cusfre = history / present;
                    double minfree = (double) discount.elementAt(0);
                    double minbill = (double) discount.elementAt(1);
                    double d1 = (double) discount.elementAt(2);
                    double d2 = (double) discount.elementAt(3);
                    double d3 = (double) discount.elementAt(4);
                    double d4 = (double) discount.elementAt(5);

                    if (cusfre < minfree && amount < minbill) {
                        discounta = (amount * d1) / 100;
                        amount = amount - discounta;
                    }
                    if (cusfre < minfree && amount > minbill) {
                        discounta = (amount * d2) / 100;
                        amount = amount - discounta;
                    }
                    if (cusfre > minfree && amount < minbill) {
                        discounta = (amount * d3) / 100;
                        amount = amount - discounta;
                    }
                    if (cusfre > minfree && amount > minbill) {
                        discounta = (amount * d4) / 100;
                        amount = amount - discounta;
                    }
                    amount = amount - advance;
                    //   tb2.addRow(new Object[]{new String(rs.getString("Name")),new String(rs.getString("I")),new Double(Totalbill),new Double(advance),new Double(roomrent),new Double(tariffa),new Double(discounta),new Double(amount)});
                }
            }
        }
        // add a table
        //createTable(subCatPart);
    }
    Paragraph subPara2 = new Paragraph("Thanks for choosing us .. please visit again", subFont);
    Section subCatPart2 = catPart.addSection(subPara2);
    /* Anchor anchor2 = new Anchor("Thanks for choosing us .. please visit again", catFont);
     Chapter catPart2 = new Chapter(new Paragraph(anchor), 1);*/

    // now add all this to the document
    document.add(catPart);
    //document.add(catPart2);

}

From source file:klasy.PdfFiles.java

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

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // add a list
    createList(subCatPart);//w w  w  .j  a  va  2  s  .  co m
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // add a table
    //createTable(subCatPart);

    // now add all this to the document
    document.add(catPart);

    // Next section
    anchor = new Anchor("Second Chapter", catFont);
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // now add all this to the document
    document.add(catPart);

}

From source file:lk.score.androphsy.report.ReportPdf.java

License:Open Source License

private void addDevicePage(Document document) {
    Anchor anchor = new Anchor("Device Information");
    anchor.setName("Device Information");
    Chapter chap = new Chapter(new Paragraph(anchor), 1);

    Paragraph subpara = new Paragraph("Device Information", HeadingFont);
    subpara.setAlignment(Paragraph.ALIGN_CENTER);
    addEmptyLine(subpara, 1);//from   w w  w.  j av  a2  s  .  c o m
    createTableRowFormat(subpara, "DeviceBasicInfo");

    try {
        document.add(subpara);
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java

License:Apache License

/**
 * Export a report to a pdf file./* w  w  w  . jav  a 2s.c om*/
 *
 * @param allMetricsMap         map of all QC metrics - keys and description.
 * @param selectedReports       the report units to be exported in PDF format.
 * @param preferredPDFDirectory the directory the pdf document should be exported to.
 * @return Path of the created PDF document if it is successfully created - otherwise return empty string.
 */
public static String exportReportUnitInPDFFormat(final Map<String, String> allMetricsMap,
        final ArrayList<ReportUnit> selectedReports, final String preferredPDFDirectory) {
    //Obtain current timestamp. 
    final java.util.Date date = new java.util.Date();
    final String timestampString = CREATION_DATE_TIME_FORMAT.format(date);
    //Replace all occurrences of special character ':' from time stamp since ':' is not allowed in filename. 
    final String filenameTimestamp = timestampString.replace(':', '-');
    //Instantiation of document object - landscape format using the rotate() method
    final Document document = new Document(PageSize.A4.rotate(), PDF_PAGE_MARGIN, PDF_PAGE_MARGIN,
            PDF_PAGE_MARGIN, PDF_PAGE_MARGIN);
    final String pdfFileName = preferredPDFDirectory + "\\QCReports-" + filenameTimestamp + FILE_TYPE_EXTENSION;
    try {
        //Creation of PdfWriter object
        //            PdfWriter writer;
        //            writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFileName));
        document.open();
        for (ReportUnit reportUnit : selectedReports) {
            //New page for each report. 
            document.newPage();
            //Creation of chapter object
            final Paragraph pageTitle = new Paragraph(
                    String.format(PDF_PAGE_TITLE, reportUnit.getMsrunName(), timestampString),
                    Constants.PDF_TITLE_FONT);
            pageTitle.setAlignment(Element.ALIGN_CENTER);
            final Chapter chapter1 = new Chapter(pageTitle, 1);
            chapter1.setNumberDepth(0);
            //Creation of TIC graph section object
            final String graphTitle = String.format(TIC_GRAPH_SECTION_TITLE, reportUnit.getMsrunName());
            final Paragraph ticGraphSection = new Paragraph(graphTitle, Constants.PDF_SECTION_FONT);
            ticGraphSection.setSpacingBefore(PDF_PARAGRAPH_SPACING);
            ticGraphSection.add(Chunk.NEWLINE);
            //Insert TIC Graph in ticGraphSection.
            ticGraphSection.add(createTICChartImage(reportUnit));
            chapter1.addSection(ticGraphSection);
            final String metricsTitle = String.format(METRICS_VALUES_SECTION_TITLE, reportUnit.getMsrunName());
            final Paragraph metricsValuesSection = new Paragraph(metricsTitle, Constants.PDF_SECTION_FONT);
            metricsValuesSection.setSpacingBefore(PDF_PARAGRAPH_SPACING);
            //Reference: http://www.java-connect.com/itext/add-table-in-PDF-document-using-java-iText-library.html
            //TODO: Insert metrics values table in metricsValuesSection
            metricsValuesSection.add(createMetricsValuesTable(allMetricsMap, reportUnit));
            chapter1.addSection(metricsValuesSection);
            //Addition of a chapter to the main document
            document.add(chapter1);
        }
        document.close();
        return pdfFileName;
    } catch (final DocumentException e) {
        // TODO Explain when these exception can occur.
        /* FileNotFoundException will be thrown by the FileInputStream, FileOutputStream, and 
         * RandomAccessFile constructors when a file with the specified path name does not exist.
         * It will also be thrown by these constructors if the file does exist but for some reason 
         * is inaccessible, for example when an attempt is made to open a read-only file for writing.
         * DocumentException Signals that an error has occurred in a Document.
         */
        logger.log(Level.SEVERE, PDF_EXPORT_EXCEPTION_MESSAGE, e);
        return "";
    }
}

From source file:org.flowable.app.rest.runtime.RelatedContentResource.java

License:Apache License

void createPdf(String dest, ArrayList<String> info) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();// w  w w.ja va 2 s  .  c om
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Chunk chunk = new Chunk("Relatrio", chapterFont);
    Chapter chapter = new Chapter(new Paragraph(chunk), 1);
    chapter.setNumberDepth(0);

    int i = 0;
    for (; i < info.size(); i++) {
        chapter.add(new Paragraph(info.get(i), paragraphFont));
    }
    document.add(chapter);
    document.close();
}

From source file:org.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

private void addContent(PdfWriter writer) throws DocumentException, PdfFormatierungsException {
    Anchor anchor = new Anchor("Lernentwicklungsbericht", lernentwicklungsberichtUeberschriftFont);
    Chapter chapterLEB = new Chapter(new Paragraph(anchor), 1);
    chapterLEB.setNumberDepth(0);//from  w w w  . java 2  s .c o  m
    Paragraph paragraphHeader = new Paragraph();
    paragraphHeader.setLeading(FIXED_LEADING_TEXT, 1);
    sectionCount += 1;
    Section headerSection = chapterLEB.addSection(paragraphHeader);
    headerSection.setNumberDepth(0);

    paragraphHeader.add(Chunk.NEWLINE);
    paragraphHeader.add(PdfFormatHelper.buildHeaderNameLine(lebData.getSchuelername(), headerFont));
    paragraphHeader.add(Chunk.NEWLINE);
    paragraphHeader.add(PdfFormatHelper.buildHeaderKlassendatenLine(lebData, headerFont));
    headerSection.add(Chunk.NEWLINE);
    headerSection.add(Chunk.NEWLINE);
    document.add(chapterLEB);
    insertDummyLineIfNecessary(writer);

    addKlassenbrief(chapterLEB, writer);
    addIndividuelleEinschaetzung(chapterLEB, writer);
    addFacheinschaetzungen(chapterLEB, writer);
}

From source file:org.jaqpot.core.service.data.ReportService.java

public void report2PDF(Report report, OutputStream os) {

    Document document = new Document();
    document.setPageSize(PageSize.A4);// www  . j ava  2 s .  c  o m
    document.setMargins(50, 45, 80, 40);
    document.setMarginMirroring(false);

    try {
        PdfWriter writer = PdfWriter.getInstance(document, os);
        TableHeader event = new TableHeader();
        writer.setPageEvent(event);

    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    document.open();

    /** setup fonts for pdf */
    Font ffont = new Font(Font.FontFamily.UNDEFINED, 9, Font.ITALIC);
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Font tableFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);

    /** print link to jaqpot*/
    Chunk chunk = new Chunk(
            "This report has been automatically created by the JaqpotQuatro report service. Click here to navigate to our official webpage",
            ffont);
    chunk.setAnchor("http://www.jaqpot.org");

    Paragraph paragraph = new Paragraph(chunk);
    paragraph.add(Chunk.NEWLINE);

    Chapter chapter = new Chapter(paragraph, 1);
    chapter.setNumberDepth(0);

    /** get title */
    String title = null;
    if (report.getMeta() != null && report.getMeta().getTitles() != null
            && !report.getMeta().getTitles().isEmpty())
        title = report.getMeta().getTitles().iterator().next();

    /** print title aligned centered in page */
    if (title == null)
        title = "Report";
    chunk = new Chunk(title, chapterFont);
    paragraph = new Paragraph(chunk);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.add(Chunk.NEWLINE);
    paragraph.add(Chunk.NEWLINE);

    chapter.add(paragraph);

    /** report Description */
    if (report.getMeta() != null && report.getMeta().getDescriptions() != null
            && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        paragraph = new Paragraph();
        paragraph.add(new Chunk("Description: ", paragraphFontBold));
        paragraph.add(new Chunk(report.getMeta().getDescriptions().toString().replaceAll(":http", ": http"),
                paragraphFont));
        chapter.add(paragraph);
        chapter.add(Chunk.NEWLINE);
    }

    /** report model, algorithm and/or dataset id */
    if (report.getMeta() != null && report.getMeta().getHasSources() != null
            && !report.getMeta().getHasSources().isEmpty() && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        Iterator<String> sources = report.getMeta().getHasSources().iterator();
        sources.forEachRemaining(o -> {
            if (o != null) {
                String[] source = o.split("/");
                if (source[source.length - 2].trim().equals("model")
                        || source[source.length - 2].trim().equals("algorithm")
                        || source[source.length - 2].trim().equals("dataset")) {
                    Paragraph paragraph1 = new Paragraph();
                    paragraph1.add(new Chunk(source[source.length - 2].substring(0, 1).toUpperCase()
                            + source[source.length - 2].substring(1) + ": ", paragraphFontBold));
                    paragraph1.add(new Chunk(source[source.length - 1], paragraphFont));
                    chapter.add(paragraph1);
                    chapter.add(Chunk.NEWLINE);
                }
            }
        });
    }

    /** report single calculations */
    report.getSingleCalculations().forEach((key, value) -> {
        Paragraph paragraph1 = new Paragraph();
        paragraph1 = new Paragraph();
        paragraph1.add(new Chunk(key + ": ", paragraphFontBold));
        paragraph1.add(new Chunk(value.toString().trim().replaceAll(" +", " "), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    });

    /** report date of completion */
    if (report.getMeta() != null && report.getMeta().getDate() != null) {
        Paragraph paragraph1 = new Paragraph();
        paragraph1.add(new Chunk("Procedure completed on: ", paragraphFontBold));
        paragraph1.add(new Chunk(report.getMeta().getDate().toString(), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    }

    try {
        document.add(chapter);
    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    Integer chapterNumber = 0;

    /** report all_data */
    for (Entry<String, ArrayCalculation> entry : report.getArrayCalculations().entrySet()) {
        String label = entry.getKey();
        ArrayCalculation ac = entry.getValue();
        PdfPTable table = new PdfPTable(ac.getColNames().size() + 1);
        for (Entry<String, List<Object>> row : ac.getValues().entrySet()) {

            try {
                XMLWorkerHelper.getInstance().parseXHtml(w -> {
                    if (w instanceof WritableElement) {
                        List<Element> elements = ((WritableElement) w).elements();
                        for (Element element : elements) {
                            PdfPCell pdfCell = new PdfPCell();
                            pdfCell.addElement(element);
                            table.addCell(pdfCell);
                        }
                    }
                }, new StringReader(row.getKey()));
            } catch (IOException e) {
                e.printStackTrace();
            }

            for (Object o : row.getValue()) {
                table.addCell(o.toString());
            }
            table.completeRow();
        }
        try {
            Chunk tableChunk = new Chunk(label, tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(Chunk.NEWLINE);
            tableChapter.add(table);
            document.newPage();
            document.add(tableChapter);
        } catch (DocumentException ex) {
            throw new InternalServerErrorException(ex);
        }
    }

    /** report plots */
    for (Entry<String, String> entry : report.getFigures().entrySet()) {
        try {
            byte[] valueDecoded = Base64.decodeBase64(entry.getValue());
            Image l = Image.getInstance(valueDecoded);
            document.newPage();
            //image starts at the half's half of pdf page
            l.setAbsolutePosition(0, (document.getPageSize().getHeight() / 2 / 2));
            l.scaleToFit(document.getPageSize());

            Chunk tableChunk = new Chunk(entry.getKey(), tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(l);
            document.add(tableChapter);
        } catch (IOException | DocumentException e) {
            e.printStackTrace();
        }
    }
    document.close();
}

From source file:org.sharegov.cirm.utils.PDFExportUtil.java

License:Apache License

private static void addContent(Document doc, Json data) throws DocumentException {
    Anchor anchor = new Anchor(); //new Anchor("First Chapter", catFont);
    //anchor.setName("First Chapter Anchor");

    Chapter catPart = new Chapter(new Paragraph(anchor), 1);
    catPart.setNumberDepth(0);/*from   ww  w .java  2 s  .  co  m*/
    Paragraph subPara = new Paragraph(); //new Paragraph("SubCategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.setNumberDepth(0);

    createTable(subCatPart, data);

    //Add everything to the document
    doc.add(catPart);
}

From source file:org.sharegov.cirm.utils.PDFViewReport.java

License:Apache License

private void addContent(Document d, Json data) {
    Anchor anchor = new Anchor();
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);
    catPart.setNumberDepth(0);//from   w  ww .  j  a  v a 2 s.  com
    Paragraph subPara = new Paragraph(); //new Paragraph("SubCategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.setNumberDepth(0);

    try {
        addTopTable(subCatPart, data);
        addDescription(subCatPart, data);
        addQuestions(subCatPart, data);
        addActors(subCatPart, data);
        addActivities(subCatPart, data);
        d.add(catPart);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Problem during addContend for BO: " + data.toString(), e);
    }
}

From source file:org.sharegov.cirm.utils.PDFViewReport.java

License:Apache License

private void addWASDContent(Document d, Json applicant, String hasCaseNumber, boolean isEnglish) {
    //Anchor anchor = new Anchor();
    try {//from   w w w .  ja v  a  2 s  . c om
        Chapter chapter = new Chapter(new Paragraph(), 1);
        chapter.setNumberDepth(0);
        //addWASDHeader(chapter);
        addWASDBody(chapter, applicant, hasCaseNumber, isEnglish);
        d.add(chapter);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}