Example usage for com.itextpdf.text Paragraph setSpacingAfter

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

Introduction

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

Prototype

public void setSpacingAfter(float spacing) 

Source Link

Usage

From source file:com.bougsid.printers.PrintMission.java

public void printMission(Mission mission) {
    Document document = new Document(PageSize.A4);
    try {//from   www .j  a  v a2s  .com
        File downloadDir = new File(msg.getMessage("application.mission.downloaddir"));
        if (!downloadDir.exists()) {
            downloadDir.mkdir();
        }
        System.out.println("Dir =" + downloadDir.getPath());
        PdfWriter.getInstance(document,
                new FileOutputStream(downloadDir.getPath() + "/" + mission.getUuid() + ".pdf"));
        document.open();
        Paragraph p = new Paragraph();
        p.setSpacingAfter(60);
        document.add(p);
        //header
        Paragraph paragraph = new Paragraph(
                msg.getMessage("mission.pdf.school") + "       " + mission.getIdMission() + "           ",
                DEFAULT_FONT);
        Phrase phrase = new Phrase(msg.getMessage("mission.pdf.city") + " "
                + LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
        paragraph.add(phrase);
        paragraph.setSpacingAfter(50);
        document.add(paragraph);
        //title
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(40);
        PdfPCell cell = new PdfPCell(new Phrase(msg.getMessage("mission.pdf.title"),
                FontFactory.getFont(FontFactory.HELVETICA, 18)));
        cell.setBorderWidth(1);
        cell.setPadding(10);

        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        table.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.setSpacingAfter(40);
        document.add(table);

        //content
        table = new PdfPTable(2);
        table.setWidthPercentage(100);

        //line 1
        cell = new PdfPCell(new Paragraph(mission.getEmploye().getCivilite().getLabel(), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFullName(), DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 2
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.matricule"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getMatricule(), DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 3
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.grade"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFonction(), DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        if (mission.getEntreprise() != null) {
            //line 4
            cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1"), DEFAULT_FONT_BOLD));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1_2"), DEFAULT_FONT_BOLD));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);

            //line 5
            cell = new PdfPCell(new Paragraph(" ", DEFAULT_FONT_BOLD));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(" - " + mission.getEntreprise().getNom(), DEFAULT_FONT));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);
        }

        //line 6
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.lieu"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        p = new Paragraph();
        p.setFont(DEFAULT_FONT);
        for (Ville ville : mission.getVilles()) {
            p.add(ville.getNom() + "\n");
        }
        cell = new PdfPCell(p);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 7
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.startdate"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(
                ": " + mission.getStartDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "    Heure : "
                        + mission.getStartDate().format(DateTimeFormatter.ofPattern("HH:mm")),
                DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 8
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.enddate"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(
                ": " + mission.getEndDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "    Heure : "
                        + mission.getEndDate().format(DateTimeFormatter.ofPattern("HH:mm")),
                DEFAULT_FONT));

        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 9
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.transport"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        switch (mission.getTransportType()) {
        case PERSONNEL:
            cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.perso") + " "
                    + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat")
                    + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT));
            break;
        case Accompagnement:
            cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.accomp") + " "
                    + mission.getAccompEmploye().getCivilite() + " " + mission.getAccompEmploye().getFullName()
                    + " " + msg.getMessage("mission.pdf.accomp.voitue") + " "
                    + mission.getAccompEmploye().getVehicule().getMarque() + " "
                    + msg.getMessage("mission.pdf.mat") + " "
                    + mission.getAccompEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT));
            break;
        case Service:
            cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.service") + " "
                    + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat")
                    + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT));
            break;
        default: {
            cell = new PdfPCell(new Paragraph(
                    ": " + mission.getTransportType().getLabel() + " " + msg.getMessage("mission.pdf.taxi"),
                    DEFAULT_FONT));
        }
        }
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        table.setSpacingAfter(40);
        document.add(table);

        //note
        document.add(new Paragraph(msg.getMessage("mission.pdf.TEXT_2"), DEFAULT_FONT));

        //signature
        if (mission.getEmploye().getGrade().getType() == GradeType.DG) {

        } else {
            Employe dir = employeService.getDG();
            if (dir != null)
                paragraph = new Paragraph(dir.getFullName(), DEFAULT_FONT);
            paragraph.setAlignment(Element.ALIGN_RIGHT);
            paragraph.setSpacingBefore(40);
            document.add(paragraph);
            paragraph = new Paragraph(msg.getMessage("mission.pdf.DG"), DEFAULT_FONT);
            paragraph.setAlignment(Element.ALIGN_RIGHT);
            document.add(paragraph);
        }

    } catch (DocumentException ex) {
        ex.printStackTrace();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    }
    document.close();
    //        try {
    //            Desktop.getDesktop().open(new File("./order.pdf"));
    //        } catch (IOException ex) {
    //            JOptionPane.showMessageDialog(null, "Fichier gner mais ne peut pas etre ouvert vrifier le dossier");
    //        }
}

From source file:com.deadormi.servlet.CreaPdfServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//w w w . j  ava 2 s.  c om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String url = request.getQueryString();
    Integer gruppo_id = Integer.parseInt(url.substring(url.indexOf("=") + 1, url.length()));

    List<Utente> iscritti = null;
    List<Post> posts = null;
    Gruppo gruppo = null;
    Utente utente = null;
    String imageUrl = null;
    String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();

    try {
        iscritti = UtenteController.getUserByGroupId(request, gruppo_id);
        gruppo = GruppoController.getGruppoById(request, gruppo_id);
    } catch (SQLException ex) {
        log.error(ex);
    }

    // step 1: creation of a document-object
    Document document = new Document();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();

        String incipit = "Report del " + CurrentDate.getCurrentDate() + "\n";
        Paragraph pIncipit = new Paragraph(incipit,
                FontFactory.getFont(FontFactory.HELVETICA, 14, BaseColor.BLACK));
        pIncipit.setAlignment(Element.ALIGN_CENTER);
        pIncipit.setSpacingAfter(10);
        document.add(pIncipit);

        String title = "Gruppo " + gruppo.getNome();
        Paragraph pTitle = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 18, BaseColor.BLUE));
        pTitle.setAlignment(Element.ALIGN_CENTER);
        pTitle.setSpacingAfter(40);
        document.add(pTitle);

        PdfPCell labelNome = new PdfPCell(new Paragraph("Nome utente"));
        PdfPCell labelNumPost = new PdfPCell(new Paragraph("Num. post"));
        PdfPCell labelData = new PdfPCell(new Paragraph("Data ultimo post"));
        labelNome.setBorder(Rectangle.NO_BORDER);
        labelNumPost.setBorder(Rectangle.NO_BORDER);
        labelData.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < iscritti.size(); i++) {
            utente = iscritti.get(i);
            try {
                posts = PostController.getPostByGruppoIdAndUserId(request, gruppo_id, utente.getId_utente());
            } catch (SQLException ex) {
                Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (utente.getNome_avatar() != null) {
                imageUrl = baseUrl + request.getContextPath() + AVATAR_RESOURCE_PATH + "/"
                        + utente.getId_utente() + "_" + utente.getNome_avatar();
                ;
            } else {
                imageUrl = baseUrl + request.getContextPath() + "/res/images/user_avatar.png";
            }
            Image image = Image.getInstance(new URL(imageUrl));
            image.scaleToFit(50, 50);

            PdfPTable table = new PdfPTable(3);

            PdfPCell cellAvatar = new PdfPCell(image);
            cellAvatar.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellAvatar.setBorder(Rectangle.NO_BORDER);
            cellAvatar.setRowspan(3);

            PdfPCell cellNome = new PdfPCell(new Paragraph(utente.getUsername() + ""));
            cellNome.setBorder(Rectangle.NO_BORDER);

            PdfPCell cellNumPost = new PdfPCell(new Paragraph(posts.size() + ""));
            cellNumPost.setBorder(Rectangle.NO_BORDER);

            //L'ultimo  sempre il piu recente siccome la query  ORDER BY data_creazione
            PdfPCell cellData;
            if (posts.size() != 0) {
                cellData = new PdfPCell(new Paragraph(posts.get(posts.size() - 1).getData_creazione()));
            } else {
                cellData = new PdfPCell(new Paragraph("N/A"));

            }
            cellData.setBorder(Rectangle.NO_BORDER);

            PdfPCell cellVoidBottom = new PdfPCell(new Paragraph(" "));
            cellVoidBottom.setBorder(Rectangle.BOTTOM);
            cellVoidBottom.setPaddingBottom(10);
            cellVoidBottom.setColspan(3);

            PdfPCell cellVoidTop = new PdfPCell(new Paragraph(" "));
            cellVoidTop.setBorder(Rectangle.NO_BORDER);
            cellVoidTop.setPaddingTop(10);
            cellVoidTop.setColspan(3);

            table.addCell(cellVoidTop);
            table.addCell(cellAvatar);
            table.addCell(labelNome);
            table.addCell(cellNome);
            table.addCell(labelNumPost);
            table.addCell(cellNumPost);
            table.addCell(labelData);
            table.addCell(cellData);
            table.addCell(cellVoidBottom);

            document.add(table);

        }

        document.close();
        response.setContentType("application/pdf");
        response.addHeader("Content-Disposition", "inline; filename=ahahah.pdf");
        OutputStream os = response.getOutputStream();
        baos.writeTo(os);
        os.flush();
        os.close();
    } catch (DocumentException ex) {
        Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.dexter.fms.mbean.ReportsMBean.java

@SuppressWarnings("unchecked")
public void createPDF(int type, String filename, int pageType) {
    try {//from  ww w.  j  a v a 2  s  .  c  o m
        FacesContext context = FacesContext.getCurrentInstance();
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FMS");
        document.addCreationDate();
        document.addCreator("FMS");
        document.addSubject("Report");
        document.addTitle(getReport_title());

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        Hashtable<String, Object> params = new Hashtable<String, Object>();
        params.put("partner", dashBean.getUser().getPartner());
        GeneralDAO gDAO = new GeneralDAO();
        Object pSettingsObj = gDAO.search("PartnerSetting", params);
        PartnerSetting setting = null;
        if (pSettingsObj != null) {
            Vector<PartnerSetting> pSettingsList = (Vector<PartnerSetting>) pSettingsObj;
            for (PartnerSetting e : pSettingsList) {
                setting = e;
            }
        }
        gDAO.destroy();

        PdfPCell c = null;
        if (setting != null && setting.getLogo() != null) {
            Image logoImg = Image.getInstance(setting.getLogo());
            logoImg.scaleToFit(212, 51);
            c = new PdfPCell(logoImg);
        } else
            c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(getReport_title(), font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (getReport_start_dt() != null && getReport_end_dt() != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("From " + getReport_start_dt() + " to " + getReport_end_dt(), font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = exportPDFTable(type);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();
        String fileName = filename + ".pdf";

        writeFileToResponse(context.getExternalContext(), baos, fileName, "application/pdf");

        context.responseComplete();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dexter.fuelcard.mbean.UtilMBean.java

public byte[] createInvoicePDF(int pageType, String title, String dateperiod, String amount, String chargeType,
        String chargeAmount, String total) {
    try {/*from www.j  ava  2s . co  m*/
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FUELCARD");
        document.addCreationDate();
        document.addCreator("FUELCARD");
        document.addSubject("Invoice");
        document.addTitle(title);

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        PdfPCell c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(title, font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (dateperiod != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("For " + dateperiod, font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = new PdfPTable(4);
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Charge Type", font)); // % per transaction or flat per license
        pdfTable.addCell(new Paragraph("Charge Amount", font)); // the amount of the charge setting

        if (chargeType.equalsIgnoreCase("Percent-Per-Tran")) {
            pdfTable.addCell(new Paragraph("Total Amount", font)); // the amount of the charge setting
        } else {
            pdfTable.addCell(new Paragraph("Total License", font)); // the amount of the charge setting
        }
        //pdfTable.addCell(new Paragraph("Description", font)); // the 
        pdfTable.addCell(new Paragraph("Amount Due", font));

        font = new Font(helvetica, 8, Font.NORMAL);
        pdfTable.addCell(new Paragraph(chargeType, font));
        pdfTable.addCell(new Paragraph(chargeAmount, font));
        pdfTable.addCell(new Paragraph(total, font));
        pdfTable.addCell(new Paragraph(amount, font));

        pdfTable.setWidthPercentage(100);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();

        return baos.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.etest.pdfgenerator.InventoryCasesReportPDF.java

public InventoryCasesReportPDF() {
    Document document = null;/* w w  w  .  jav  a 2 s.  c  om*/
    Date date = new Date();

    try {
        document = new Document(PageSize.LETTER, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);
        Font dateFont = FontFactory.getFont("Times-Roman", 8);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(500, 700);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph reportTitle = new Paragraph();
        reportTitle.setAlignment(Element.ALIGN_CENTER);
        reportTitle.add(new Phrase("Inventory of Cases Report", header));
        document.add(reportTitle);

        Paragraph datePrinted = new Paragraph();
        datePrinted.setSpacingAfter(20f);
        datePrinted.setAlignment(Element.ALIGN_CENTER);
        datePrinted.add(
                new Phrase("Date printed: " + new SimpleDateFormat("dd MMMM yyyy").format(date), dateFont));
        document.add(datePrinted);

        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 100, 300, 100, 100 });
        table.setSpacingAfter(5f);

        PdfPCell cellOne = new PdfPCell(new Phrase("Subject"));
        cellOne.setBorder(Rectangle.NO_BORDER);
        cellOne.setPaddingLeft(10);
        cellOne.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellOne.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwo = new PdfPCell(new Phrase("Descriptive Title"));
        cellTwo.setBorder(Rectangle.NO_BORDER);
        cellTwo.setPaddingLeft(10);
        cellTwo.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellTwo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellThree = new PdfPCell(new Phrase("No. of Cases"));
        cellThree.setBorder(Rectangle.NO_BORDER);
        cellThree.setPaddingLeft(10);
        cellThree.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellThree.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFour = new PdfPCell(new Phrase("No. of Items"));
        cellFour.setBorder(Rectangle.NO_BORDER);
        cellFour.setPaddingLeft(10);
        cellFour.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFour.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellOne);
        table.addCell(cellTwo);
        table.addCell(cellThree);
        table.addCell(cellFour);

        table.getDefaultCell().setBorderWidth(0f);
        document.add(table);

        for (InventoryOfCasesReport report : service.getInventoryOfCases()) {
            PdfPTable table2 = new PdfPTable(4);
            table2.setWidthPercentage(100);
            table2.setWidths(new int[] { 100, 300, 100, 100 });
            table2.setSpacingBefore(3f);
            table2.setSpacingAfter(3f);

            if (!service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()).isEmpty()) {
                if (!service
                        .getListOfCellCaseIdBySyllabusId(
                                service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()))
                        .isEmpty()) {
                    PdfPCell cell1 = new PdfPCell(new Paragraph(report.getSubject(), content));
                    cell1.setBorder(0);
                    cell1.setPaddingLeft(10);
                    cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                    cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell2 = new PdfPCell(new Paragraph(report.getDescriptiveTitle(), content));
                    cell2.setBorder(0);
                    cell2.setPaddingLeft(10);
                    cell2.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                    cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell3 = new PdfPCell(new Paragraph(
                            String.valueOf(service.getTotalCellCasesBySyllabus(
                                    service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()))),
                            content));
                    cell3.setBorder(0);
                    cell3.setPaddingLeft(10);
                    cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell4 = new PdfPCell(new Paragraph(
                            String.valueOf(service.getTotalCellItemsByCellCaseId(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())))),
                            content));
                    cell4.setBorder(0);
                    cell4.setPaddingLeft(10);
                    cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    table2.addCell(cell1);
                    table2.addCell(cell2);
                    table2.addCell(cell3);
                    table2.addCell(cell4);
                    document.add(table2);
                }
            }
        }
    } catch (DocumentException ex) {
        Logger.getLogger(InventoryItemsReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}

From source file:com.etest.pdfgenerator.InventoryItemsReportPDF.java

public InventoryItemsReportPDF() {
    Document document = null;//w  w  w.ja va 2s  .  co m
    Date date = new Date();

    try {
        document = new Document(PageSize.LETTER.rotate(), 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);
        Font dateFont = FontFactory.getFont("Times-Roman", 8);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(650, 500);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph title1 = new Paragraph();
        title1.setAlignment(Element.ALIGN_CENTER);
        title1.add(new Phrase("Inventory of Items Report"));
        document.add(title1);

        Paragraph title2 = new Paragraph();
        title2.setAlignment(Element.ALIGN_CENTER);
        title2.add(new Phrase("Grouped According to the Revised Bloom's Taxonomy"));
        document.add(title2);

        Paragraph datePrinted = new Paragraph();
        datePrinted.setSpacingAfter(20f);
        datePrinted.setAlignment(Element.ALIGN_CENTER);
        datePrinted
                .add(new Phrase("Date printed: " + new SimpleDateFormat("dd MMMM yyyy").format(date), content));
        document.add(datePrinted);

        PdfPTable table = new PdfPTable(8);
        table.setWidthPercentage(100);
        table.setSpacingAfter(5f);

        for (int i = 0; i < tableHeader.length; i++) {
            PdfPCell cell = new PdfPCell(new Phrase(tableHeader[i], header));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingLeft(10);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            if (tableHeader[i].equals("Subject")) {
                cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
            } else {
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            }
            table.addCell(cell);
        }

        document.add(table);

        for (InventoryOfCasesReport report : service.getInventoryOfCases()) {
            PdfPTable table2 = new PdfPTable(8);
            table2.setWidthPercentage(100);
            table2.setSpacingBefore(3f);
            table2.setSpacingAfter(3f);

            if (!service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()).isEmpty()) {
                if (!service
                        .getListOfCellCaseIdBySyllabusId(
                                service.getListOfSyllabusIdByCurriculumId(report.getCurriculumId()))
                        .isEmpty()) {
                    PdfPCell cell1 = new PdfPCell(new Paragraph(report.getSubject(), content));
                    cell1.setBorder(0);
                    cell1.setPaddingLeft(10);
                    cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                    cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell2 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Remember.toString()))), content));
                    cell2.setBorder(0);
                    cell2.setPaddingLeft(10);
                    cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell3 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Understand.toString()))), content));
                    cell3.setBorder(0);
                    cell3.setPaddingLeft(10);
                    cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell4 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Apply.toString()))), content));
                    cell4.setBorder(0);
                    cell4.setPaddingLeft(10);
                    cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell5 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Analyze.toString()))), content));
                    cell5.setBorder(0);
                    cell5.setPaddingLeft(10);
                    cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell6 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Evaluate.toString()))), content));
                    cell6.setBorder(0);
                    cell6.setPaddingLeft(10);
                    cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell7 = new PdfPCell(
                            new Paragraph(String.valueOf(service.getTotalItemsByBloomsTaxonomy(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())),
                                    tq.getBloomsClassId(BloomsClass.Create.toString()))), content));
                    cell7.setBorder(0);
                    cell7.setPaddingLeft(10);
                    cell7.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell7.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    PdfPCell cell8 = new PdfPCell(new Paragraph(
                            String.valueOf(service.getTotalCellItemsByCellCaseId(
                                    service.getListOfCellCaseIdBySyllabusId(service
                                            .getListOfSyllabusIdByCurriculumId(report.getCurriculumId())))),
                            content));
                    cell8.setBorder(0);
                    cell8.setPaddingLeft(10);
                    cell8.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell8.setVerticalAlignment(Element.ALIGN_MIDDLE);

                    table2.addCell(cell1);
                    table2.addCell(cell2);
                    table2.addCell(cell3);
                    table2.addCell(cell4);
                    table2.addCell(cell5);
                    table2.addCell(cell6);
                    table2.addCell(cell7);
                    table2.addCell(cell8);
                    document.add(table2);
                }
            }
        }
    } catch (DocumentException ex) {
        Logger.getLogger(InventoryItemsReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}

From source file:com.etest.pdfgenerator.ItemAnalysisOfSubjectReportPDF.java

public ItemAnalysisOfSubjectReportPDF(int curriculumId) {
    this.curriculumId = curriculumId;

    Document document = null;/*from  w  w  w  . j  ava2  s. c om*/

    try {
        document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header1 = FontFactory.getFont("Times-Roman", 14, Font.BOLD);
        Font header2 = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);

        Paragraph title1 = new Paragraph();
        title1.setSpacingAfter(10f);
        title1.setAlignment(Element.ALIGN_CENTER);
        title1.add(new Phrase("Interactive Querying", header1));
        document.add(title1);

        Paragraph title2 = new Paragraph();
        title2.setSpacingAfter(10f);
        title2.setAlignment(Element.ALIGN_CENTER);
        title2.add(new Phrase("View Item Analysis of a Subject", content));
        document.add(title2);

        Paragraph subject = new Paragraph();
        subject.setAlignment(Element.ALIGN_LEFT);
        subject.add(new Phrase("Subject: " + cs.getCurriculumById(getCurriculumId()).getSubject().toUpperCase(),
                content));
        document.add(subject);

        Paragraph descriptiveTitle = new Paragraph();
        descriptiveTitle.setAlignment(Element.ALIGN_LEFT);
        descriptiveTitle.add(new Phrase(
                "Descriptive Title: " + cs.getCurriculumById(getCurriculumId()).getDescriptiveTitle(),
                content));
        document.add(descriptiveTitle);

        Paragraph term = new Paragraph();
        term.setSpacingAfter(20f);
        term.setAlignment(Element.ALIGN_LEFT);
        term.add(new Phrase("Normal Course Offering: 2nd Semester", content));
        document.add(term);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(75);

        PdfPCell cellOne = new PdfPCell(new Phrase("Difficulty"));
        cellOne.setBorder(0);
        cellOne.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellOne.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwo = new PdfPCell(new Phrase("Discrimination"));
        cellTwo.setBorder(0);
        cellTwo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTwo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellThree = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.00, 0.19))
                + " Very difficult item(s)", content));
        cellThree.setBorder(0);
        cellThree.setPaddingLeft(50);
        cellThree.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellThree.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFour = new PdfPCell(new Phrase(String.valueOf(
                rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DiscriminationIndex", 0.00, 0.19))
                + " Poor items(s)", content));
        cellFour.setBorder(0);
        cellFour.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFour.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFive = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.20, 0.39))
                + " difficult item(s)", content));
        cellFive.setBorder(0);
        cellFive.setPaddingLeft(50);
        cellFive.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellFive.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellSix = new PdfPCell(new Phrase(String.valueOf(
                rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DiscriminationIndex", 0.20, 0.29))
                + " Marginal items(s)", content));
        cellSix.setBorder(0);
        cellSix.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellSix.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellSeven = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.40, 0.60))
                + " Average item(s)", content));
        cellSeven.setBorder(0);
        cellSeven.setPaddingLeft(50);
        cellSeven.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellSeven.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellEight = new PdfPCell(new Phrase(String.valueOf(
                rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DiscriminationIndex", 0.30, 0.39))
                + " Reasonably Good items(s)", content));
        cellEight.setBorder(0);
        cellEight.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellEight.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellNine = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.61, 0.80))
                + " Easy item(s)", content));
        cellNine.setBorder(0);
        cellNine.setPaddingLeft(50);
        cellNine.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellNine.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTen = new PdfPCell(new Phrase(String
                .valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DiscriminationIndex", 0.41, 1))
                + " Very good items(s)", content));
        cellTen.setBorder(0);
        cellTen.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTen.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellEleven = new PdfPCell(new Phrase(
                String.valueOf(rs.getIndexesOfAllTestForASubject(getCurriculumId(), "DifficultIndex", 0.81, 1))
                        + " Very Easy item(s)",
                content));
        cellEleven.setBorder(0);
        cellEleven.setPaddingLeft(50);
        cellEleven.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellEleven.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwelve = new PdfPCell(new Phrase(""));
        cellTwelve.setBorder(0);
        cellTwelve.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTwelve.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellOne);
        table.addCell(cellTwo);
        table.addCell(cellThree);
        table.addCell(cellFour);
        table.addCell(cellFive);
        table.addCell(cellSix);
        table.addCell(cellSeven);
        table.addCell(cellEight);
        table.addCell(cellNine);
        table.addCell(cellTen);
        table.addCell(cellEleven);
        table.addCell(cellTwelve);

        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(ItemAnalysisOfSubjectReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (document != null) {
            document.close();
        }
    }
}

From source file:com.etest.pdfgenerator.ItemAnalysisReportPDF.java

public ItemAnalysisReportPDF(int tqCoverageId) {
    this.tqCoverageId = tqCoverageId;

    Document document = null;/*  w ww  .  j a  v  a  2 s. c o m*/
    Date date = new Date();

    try {
        document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);
        Font dateFont = FontFactory.getFont("Times-Roman", 8);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(450, 730);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph reportTitle = new Paragraph();
        reportTitle.setAlignment(Element.ALIGN_CENTER);
        reportTitle.add(new Phrase("Item Analysis Report", header));
        document.add(reportTitle);

        Paragraph datePrinted = new Paragraph();
        datePrinted.setSpacingAfter(20f);
        datePrinted.setAlignment(Element.ALIGN_CENTER);
        datePrinted.add(
                new Phrase("Date printed: " + new SimpleDateFormat("dd MMMM yyyy").format(date), dateFont));
        document.add(datePrinted);

        Paragraph subject = new Paragraph();
        subject.setAlignment(Element.ALIGN_LEFT);
        subject.add(new Phrase(
                "Subject: " + cs.getCurriculumById(tq.getTQCoverageById(getTqCoverageId()).getCurriculumId())
                        .getSubject().toUpperCase(),
                content));
        document.add(subject);

        Paragraph term = new Paragraph();
        term.setAlignment(Element.ALIGN_LEFT);
        term.add(new Phrase("SY and Semester Administered: 2015-16 2nd Semester", content));
        document.add(term);

        Paragraph type = new Paragraph();
        type.setSpacingAfter(20f);
        type.setAlignment(Element.ALIGN_LEFT);
        type.add(
                new Phrase("Type of Test: " + tq.getTQCoverageById(getTqCoverageId()).getExamTitle(), content));
        document.add(type);

        PdfPTable table = new PdfPTable(5);
        table.setWidthPercentage(100);
        table.setWidths(new int[] { 130, 300, 300, 300, 300 });
        //            table.setSpacingAfter(5f);             

        PdfPCell cellOne = new PdfPCell(new Phrase("Item No."));
        cellOne.setBorderWidthTop(1);
        cellOne.setBorderWidthLeft(1);
        cellOne.setBorderWidthRight(1);
        cellOne.setBorderWidthBottom(1);
        cellOne.setPaddingLeft(10);
        cellOne.setPaddingRight(10);
        cellOne.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellOne.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwo = new PdfPCell(new Phrase("Difficulty"));
        cellTwo.setBorderWidthTop(1);
        cellTwo.setBorderWidthLeft(1);
        cellTwo.setBorderWidthRight(1);
        cellTwo.setBorderWidthBottom(1);
        cellTwo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTwo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellThree = new PdfPCell(new Phrase("Interpretation"));
        cellThree.setBorderWidthTop(1);
        cellThree.setBorderWidthLeft(1);
        cellThree.setBorderWidthRight(1);
        cellThree.setBorderWidthBottom(1);
        cellThree.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellThree.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFour = new PdfPCell(new Phrase("Discrimination"));
        cellFour.setBorderWidthTop(1);
        cellFour.setBorderWidthLeft(1);
        cellFour.setBorderWidthRight(1);
        cellFour.setBorderWidthBottom(1);
        cellFour.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFour.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFive = new PdfPCell(new Phrase("Interpretation"));
        cellFive.setBorderWidthTop(1);
        cellFive.setBorderWidthLeft(1);
        cellFive.setBorderWidthRight(1);
        cellFive.setBorderWidthBottom(1);
        cellFive.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFive.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellOne);
        table.addCell(cellTwo);
        table.addCell(cellThree);
        table.addCell(cellFour);
        table.addCell(cellFive);

        table.getDefaultCell().setBorderWidth(0f);
        document.add(table);

        PdfPTable table2 = new PdfPTable(5);
        table2.setWidthPercentage(100);
        table2.setWidths(new int[] { 130, 300, 300, 300, 300 });

        int itemNo = 1;
        for (CellItem ci : cis.getItemAnalysisResult(tqCoverageId)) {
            PdfPCell cell1 = new PdfPCell(new Paragraph(String.valueOf(itemNo), content));
            cell1.setBorderWidthTop(1);
            cell1.setBorderWidthLeft(1);
            cell1.setBorderWidthRight(1);
            cell1.setBorderWidthBottom(1);
            cell1.setPaddingLeft(10);
            cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
            cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

            PdfPCell cell2 = new PdfPCell(new Paragraph(String.valueOf(ci.getDifficultIndex()), content));
            cell2.setBorderWidthTop(1);
            cell2.setBorderWidthLeft(1);
            cell2.setBorderWidthRight(1);
            cell2.setBorderWidthBottom(1);
            cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

            PdfPCell cell3 = new PdfPCell(new Paragraph(
                    ItemAnalysisInterpretation.getDifficultyInterpretation(ci.getDifficultIndex()), content));
            cell3.setBorderWidthTop(1);
            cell3.setBorderWidthLeft(1);
            cell3.setBorderWidthRight(1);
            cell3.setBorderWidthBottom(1);
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

            PdfPCell cell4 = new PdfPCell(new Paragraph(String.valueOf(ci.getDiscriminationIndex()), content));
            cell4.setBorderWidthTop(1);
            cell4.setBorderWidthLeft(1);
            cell4.setBorderWidthRight(1);
            cell4.setBorderWidthBottom(1);
            cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

            PdfPCell cell5 = new PdfPCell(new Paragraph(
                    ItemAnalysisInterpretation.getDiscriminationInterpretation(ci.getDiscriminationIndex()),
                    content));
            cell5.setBorderWidthTop(1);
            cell5.setBorderWidthLeft(1);
            cell5.setBorderWidthRight(1);
            cell5.setBorderWidthBottom(1);
            cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);

            table2.addCell(cell1);
            table2.addCell(cell2);
            table2.addCell(cell3);
            table2.addCell(cell4);
            table2.addCell(cell5);

            itemNo++;
        }
        table.getDefaultCell().setBorderWidth(0f);
        document.add(table2);

    } catch (DocumentException ex) {
        Logger.getLogger(ItemAnalysisReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}

From source file:com.etest.pdfgenerator.TQCoveragePDF.java

public TQCoveragePDF(int tqCoverageId) {
    this.tqCoverageId = tqCoverageId;

    Document document = null;//from   w w w  .j  av a  2  s.  co m

    try {
        document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header1 = FontFactory.getFont("Times-Roman", 14, Font.BOLD);
        Font header2 = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);

        Image img = null;
        try {
            img = Image.getInstance("C:\\eTest-images\\SUCN_seal.png");
            img.scaleToFit(60, 60);
            img.setAbsolutePosition(100, 720);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.add(img);

        Paragraph title = new Paragraph();
        title.setAlignment(Element.ALIGN_CENTER);
        title.add(new Phrase("COLLEGE OF NURSING", header2));
        document.add(title);

        Paragraph school = new Paragraph();
        school.setAlignment(Element.ALIGN_CENTER);
        school.add(new Phrase("Siliman University", header2));
        document.add(school);

        Paragraph location = new Paragraph();
        location.setSpacingAfter(10f);
        location.setAlignment(Element.ALIGN_CENTER);
        location.add(new Phrase("Dumaguete City", header2));
        document.add(location);

        Paragraph examTitle = new Paragraph();
        examTitle.setSpacingAfter(20f);
        examTitle.setAlignment(Element.ALIGN_CENTER);
        examTitle
                .add(new Phrase(
                        cs.getCurriculumById(tq.getTQCoverageById(getTQCoverageId()).getCurriculumId())
                                .getSubject() + " " + tq.getTQCoverageById(getTQCoverageId()).getExamTitle(),
                        header2));
        document.add(examTitle);

        Paragraph instruction = new Paragraph();
        instruction.setSpacingAfter(5f);
        instruction.setAlignment(Element.ALIGN_LEFT);
        instruction.add(
                new Phrase("INSTRUCTIONS: Read the cases carefully. Choose the letter of the correct answer. "
                        + "Use an answer sheet and follow instruction for its use.", content));
        document.add(instruction);

        int itemNo = 1;
        Map<Integer, Map<Integer, Integer>> tqCoverage = tq.getTQCoverage(getTQCoverageId());
        for (Map.Entry<Integer, Map<Integer, Integer>> tqCases : tqCoverage.entrySet()) {
            Integer tqCaseId = tqCases.getKey();

            Label caseTopic = new Label();
            caseTopic.setValue(ccs.getCellCaseById(tqCaseId).getCaseTopic());
            caseTopic.setContentMode(ContentMode.HTML);
            document.add(new Paragraph(caseTopic.getValue().replaceAll("(?i)<p.*?>.*?</p>", ""), content));

            Map<Integer, Integer> value = tqCases.getValue();
            for (Map.Entry<Integer, Integer> itemIds : value.entrySet()) {
                Integer itemId = itemIds.getKey();
                Integer itemKeyId = itemIds.getValue();

                List<String> keyList = k.getAllItemKey(itemId);
                if (keyList.isEmpty()) {
                    ShowErrorNotification.error(
                            "No Item Key was found for STEM: \n" + cis.getCellItemById(itemId).getItem());
                    return;
                }

                Label stem = new Label();
                //                    stem.setValue(itemNo+". "+cis.getCellItemById(itemId).getItem().replace("{key}", keyList.get(0)));
                stem.setValue(itemNo + ". "
                        + cis.getCellItemById(itemId).getItem().replace("{key}", k.getItemKeyById(itemKeyId)));
                stem.setContentMode(ContentMode.HTML);
                document.add(new Paragraph(stem.getValue(), content));

                PdfPTable table = new PdfPTable(2);
                table.setWidthPercentage(100);
                table.setSpacingBefore(10f);
                table.setSpacingAfter(10f);

                //Set Column widths
                float[] columnWidths = { 1f, 1f };
                table.setWidths(columnWidths);

                PdfPCell cell1 = new PdfPCell(
                        new Paragraph("A) " + cis.getCellItemById(itemId).getOptionA(), content));
                //                cell1.setBorderColor(BaseColor.BLUE);
                cell1.setBorder(0);
                cell1.setPaddingLeft(10);
                cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

                PdfPCell cell2 = new PdfPCell(
                        new Paragraph("C) " + cis.getCellItemById(itemId).getOptionC(), content));
                //                cell2.setBorderColor(BaseColor.GREEN);
                cell2.setBorder(0);
                cell2.setPaddingLeft(10);
                cell2.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

                PdfPCell cell3 = new PdfPCell(
                        new Paragraph("B) " + cis.getCellItemById(itemId).getOptionB(), content));
                //                cell3.setBorderColor(BaseColor.RED);
                cell3.setBorder(0);
                cell3.setPaddingLeft(10);
                cell3.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);

                PdfPCell cell4 = new PdfPCell(
                        new Paragraph("D) " + cis.getCellItemById(itemId).getOptionD(), content));
                //                cell4.setBorderColor(BaseColor.RED);
                cell4.setBorder(0);
                cell4.setPaddingLeft(10);
                cell4.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
                cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

                table.addCell(cell1);
                table.addCell(cell2);
                table.addCell(cell3);
                table.addCell(cell4);

                document.add(table);

                itemNo++;
            }
        }

        document.newPage();

        Paragraph ticketNo = new Paragraph();
        ticketNo.setSpacingAfter(30f);
        ticketNo.setAlignment(Element.ALIGN_LEFT);
        ticketNo.add(new Phrase("TQ Ticket #: " + tq.getTqCoverageTicketNo(getTQCoverageId()), content));
        document.add(ticketNo);

        document.add(new Paragraph("Answer Key: "));

        itemNo = 1;
        List<TQAnswerKey> answerKey = tq.getTQCoverageAnswerKey(getTQCoverageId());
        for (TQAnswerKey t : answerKey) {
            document.add(new Paragraph(
                    t.getItemNo() + ": " + cis.getOptionAnswer(t.getCellItemId()).get(t.getAnswer())));
        }

    } catch (DocumentException ex) {
        Logger.getLogger(TQCoveragePDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (document != null) {
            document.close();
        }
    }
}

From source file:com.etest.pdfgenerator.TQCriticalIndexValuesReportPDF.java

public TQCriticalIndexValuesReportPDF(int tqCoverageId) {
    this.tqCoverageId = tqCoverageId;

    Document document = null;//from ww  w  .  j  a  v a 2s . c om

    try {
        document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, outputStream);
        document.open();

        Font header = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
        Font content = FontFactory.getFont("Times-Roman", 10);

        Paragraph reportTitle = new Paragraph();
        reportTitle.setSpacingAfter(10f);
        reportTitle.setAlignment(Element.ALIGN_CENTER);
        reportTitle.add(new Phrase("Interactive Querying", header));
        document.add(reportTitle);

        Paragraph title2 = new Paragraph();
        title2.setSpacingAfter(10f);
        title2.setAlignment(Element.ALIGN_CENTER);
        title2.add(new Phrase("View Item Analysis Critical Values of a Test", content));
        document.add(title2);

        Paragraph subject = new Paragraph();
        subject.setAlignment(Element.ALIGN_LEFT);
        subject.add(new Phrase("Subject: "
                + cs.getCurriculumById(tq.getTQCoverageById(getTqCoverageId()).getCurriculumId()).getSubject()
                        .toUpperCase()
                + "(" + cs.getCurriculumById(tq.getTQCoverageById(getTqCoverageId()).getCurriculumId())
                        .getDescriptiveTitle()
                + ")", content));
        document.add(subject);

        Paragraph term = new Paragraph();
        term.setAlignment(Element.ALIGN_LEFT);
        term.add(new Phrase("SY and Semester Administered: 2015-16 2nd Semester", content));
        document.add(term);

        Paragraph descriptiveTitle = new Paragraph();
        descriptiveTitle.setSpacingAfter(10f);
        descriptiveTitle.setAlignment(Element.ALIGN_LEFT);
        descriptiveTitle.add(
                new Phrase("Type of Test: " + tq.getTQCoverageById(getTqCoverageId()).getExamTitle(), content));
        document.add(descriptiveTitle);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(75);

        PdfPCell cellOne = new PdfPCell(new Phrase("Difficulty"));
        cellOne.setBorder(0);
        cellOne.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellOne.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellTwo = new PdfPCell(new Phrase("Discrimination"));
        cellTwo.setBorder(0);
        cellTwo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTwo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellThree = new PdfPCell(new Phrase(
                String.valueOf(rs.getTQCriticalIndexValue(getTqCoverageId(), "DifficultIndex", 0.00, 0.19))
                        + " Very difficult item(s)",
                content));
        cellThree.setBorder(0);
        cellThree.setPaddingLeft(50);
        cellThree.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellThree.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFour = new PdfPCell(new Phrase(
                String.valueOf(rs.getTQCriticalIndexValue(getTqCoverageId(), "DiscriminationIndex", 0.00, 0.19))
                        + " Poor items(s)",
                content));
        cellFour.setBorder(0);
        cellFour.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFour.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellFive = new PdfPCell(new Phrase(
                String.valueOf(rs.getTQCriticalIndexValue(getTqCoverageId(), "DifficultIndex", 0.81, 1))
                        + " Very easy item(s)",
                content));
        cellFive.setBorder(0);
        cellFive.setPaddingLeft(50);
        cellFive.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        cellFive.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellSix = new PdfPCell(new Phrase(""));
        cellSix.setBorder(0);
        cellSix.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellSix.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellOne);
        table.addCell(cellTwo);
        table.addCell(cellThree);
        table.addCell(cellFour);
        table.addCell(cellFive);
        table.addCell(cellSix);

        table.getDefaultCell().setBorderWidth(0f);
        document.add(table);

    } catch (DocumentException ex) {
        Logger.getLogger(TQCriticalIndexValuesReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (document != null) {
            document.close();
        }
    }

}