Example usage for com.itextpdf.text Document Document

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

Introduction

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

Prototype


public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom) 

Source Link

Document

Constructs a new Document -object.

Usage

From source file:com.archsystemsinc.ipms.sec.webapp.controller.IssueController.java

License:Apache License

@RequestMapping(value = "/issues/pdf", method = RequestMethod.GET)
public void getPDF1(final HttpServletResponse response, final Model model,
        final java.security.Principal principal) throws DocumentException, IOException, ClassNotFoundException {
    logger.debug("Received request to download issues report as an PDF");

    try {/*from   www . ja  v  a  2 s  . c o  m*/
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:\\Test.pdf"));
        document.open();
        final String sheetName = GenericConstants.ISSUES;
        final String[] coloumnNames = { "1", "2", "3", "4", "5", "6" };
        final Principal currentUser = principalService.findByName(principal.getName());
        final List issues = service.findCurrentUserIssues(currentUser);

        document.add(new Paragraph(GenericConstants.ISSUES));
        PdfPTable t = new PdfPTable(3);

        t.setSpacingBefore(25);

        t.setSpacingAfter(25);
        for (int i = 0; i < issues.size(); i++) {
            Object isu = issues.get(i);

        }

        t.addCell("1.1");

        t.addCell("1.2");

        t.addCell("1.3");

        document.add(t);
        document.close();

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

}

From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java

License:Apache License

/**
 * /*  w  ww  . j  a va  2  s .c o  m*/
 * PDF File? ?
 * 
 * @param filePath PDF ?? ?? File Path
 *  
 */
public static void createPDF(String filePath, Upload upload, PDFMetadataDefinition data) throws Exception {

    if (data == null)
        return;

    //PDF ? ?
    Document pdf = new Document(PageSize.A4, 50, 50, 70, 65);
    PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(filePath));
    writer.setLinearPageMode();

    //Page Event ?( ? ?, ? ??  event)
    PDFCommonEventHelper event = new PDFCommonEventHelper();
    writer.setPageEvent(event);

    pdf.open();
    int cNum = 1;

    SAXBuilder builder = new SAXBuilder();

    //chapter ? xml 
    File listXml = new File(PDFDocGenerator.class.getResource("/xml/chapter.xml").getFile());
    org.jdom2.Document listDoc = builder.build(listXml);

    for (Element chapterE : listDoc.getRootElement().getChildren()) {

        if (chapterE.getAttributeValue("option") != null) {

            String option = chapterE.getAttributeValue("option");

            //source ?? ?  
            if (option.equals("zip") && data.getZipDefinition() != null) {

                addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data.getZipDefinition(), upload);
                cNum++;

                //deploy ?? ?  
            } else if (option.equals("deploy")
                    && (upload.getDeploySrc() != null && upload.getDeploySrc().getFileItem().getSize() > 0)) {

                addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data.getZipDefinition(), upload);
                cNum++;

                //.ear ?? ?  
            } else if (option.equals("ear") && data.getEarDefinition() != null) {

                addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data, upload);
                cNum++;

                //.war ?? ?  
            } else if (option.equals("war") && data.getEarDefinition() == null
                    && data.getWarDefinitionMap() != null) {
                Iterator iterator = data.getWarDefinitionMap().entrySet().iterator();

                if (iterator.hasNext()) {
                    Entry entry = (Entry) iterator.next();
                    addChapterForDynamic(writer, chapterE, cNum, pdf, builder,
                            (AnalyzeDefinition) entry.getValue(), upload);
                    cNum++;
                }

                //.jar ?? ?  
            } else if (option.equals("jar") && data.getEarDefinition() == null
                    && data.getJarDefinitionMap() != null) {
                Iterator iterator = data.getJarDefinitionMap().entrySet().iterator();

                if (iterator.hasNext()) {
                    Entry entry = (Entry) iterator.next();
                    addChapterForDynamic(writer, chapterE, cNum, pdf, builder,
                            (AnalyzeDefinition) entry.getValue(), upload);
                    cNum++;
                }

                //PDFMetadataDefinition?  data  
            } else if (option.equals("root")) {

                addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data, upload);
                cNum++;

                // was ? ? ? chapter 
            } else if (option.equals(upload.getAfterWas())) {

                addChapter(writer, chapterE, cNum, pdf, builder);
                cNum++;
                //Exception  ? ? chapter 
            } else if (option.equals("exception")) {

                if (data.getExceptionInfoList().size() > 0) {
                    addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data, upload);
                    cNum++;
                }
            }

        } else {
            addChapter(writer, chapterE, cNum, pdf, builder);
            cNum++;
        }
    }

    setLastPageInfo(pdf, writer, cNum);
    setChapterSectionTOC(pdf, writer, event);
    setTitleMainPage(pdf, writer, event, upload);
    pdf.close();
}

From source file:com.automaster.autoview.server.servlet.TextStateOperators.java

/**
 * Creates a PDF document.//from ww w.  ja va 2  s .  c om
 * @param filename the path to the new PDF document
 * @throws DocumentException 
 * @throws IOException
 */
public void createPdf(String filename) throws IOException, DocumentException {
    // step 1
    Rectangle rect = new Rectangle(595, 842);
    Document document = new Document(rect, 30, 30, 30, 30);
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3
    document.open();
    // step 4
    //PdfAcroForm canva = writer.getAcroForm();

    BaseFont bf = BaseFont.createFont();

    //canva.addMultiLineTextField("txtTeste", "texto de teste vamos ver se le quebra a linha", bf, 15, 300, 800, 100, 100);

    PdfContentByte canvas = writer.getDirectContent();
    String text = "AWAY again";
    String text1 = "TESTE Rua alameda luis de sousa santos, N 52, castanhal, CEP: 68742-783, ao lado do posto adriano";
    canvas.beginText();
    // line 1
    canvas.setFontAndSize(bf, 16);
    canvas.moveText(36, 800);
    canvas.moveTextWithLeading(0, -24);
    canvas.setTextRise(10);
    canvas.showText(text);
    // line 2
    canvas.setWordSpacing(20);
    canvas.newlineShowText(text);
    // line 3
    canvas.setCharacterSpacing(10);
    canvas.newlineShowText(text);
    canvas.setWordSpacing(0);
    canvas.setCharacterSpacing(0);
    // line 4
    canvas.setHorizontalScaling(50);
    canvas.newlineShowText(text);
    canvas.setHorizontalScaling(100);
    // line 5
    canvas.newlineShowText(text);
    canvas.setTextRise(15);
    canvas.setFontAndSize(bf, 12);
    canvas.setColorFill(BaseColor.RED);
    canvas.showText("2");
    canvas.setColorFill(GrayColor.GRAYBLACK);
    // line 6
    canvas.setLeading(56);
    canvas.setMiterLimit(5);
    canvas.newlineShowText(
            "Rua alameda luis de sousa santos, N 52, castanhal, CEP: 68742-783, ao lado do posto" + text);
    canvas.setLeading(24);
    canvas.newlineText();
    Paragraph paragraph = new Paragraph("teste");
    PdfWriter pdfWriter = canvas.getPdfWriter();
    PdfAcroForm pdfAcroForm = pdfWriter.getAcroForm();
    //pdfAcroForm.addMultiLineTextField("txtTeste", "Changing the adriano leading: Rua alameda luis de sousa santos, N 52, castanhal, CEP: 68742-783, ao lado do posto", bf, 12, 30, 650, 550, 750);
    //pdfAcroForm.addHiddenField("txtTeste", text); 
    PdfFormField pdfFormField = new PdfFormField(pdfWriter, 30, 650, 550, 750, null);
    pdfFormField.setFieldName("txtTeste");
    pdfFormField.setValueAsString(text1);
    //TextField textField = new TextField(canvas.getPdfWriter(), new Rectangle(30, 650, 550, 750), "txtTest");
    //textField.setText(text);
    pdfAcroForm.addFormField(pdfFormField);
    // line 7
    PdfTextArray array = new PdfTextArray("A");
    array.add(120);
    array.add("W");
    array.add(120);
    array.add("A");
    array.add(95);
    array.add("Y again");
    canvas.showText(array);
    canvas.endText();

    canvas.setColorFill(BaseColor.BLUE);
    canvas.beginText();
    canvas.setTextMatrix(360, 770);
    canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
    canvas.setFontAndSize(bf, 24);
    canvas.showText(text);
    canvas.endText();

    canvas.beginText();
    canvas.setTextMatrix(360, 730);
    canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE);
    canvas.setFontAndSize(bf, 24);
    canvas.showText(text);
    canvas.endText();

    canvas.beginText();
    canvas.setTextMatrix(360, 690);
    canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
    canvas.setFontAndSize(bf, 24);
    canvas.showText(text);
    canvas.endText();

    canvas.beginText();
    canvas.setTextMatrix(360, 650);
    canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE);
    canvas.setFontAndSize(bf, 24);
    canvas.showText(text);
    canvas.endText();

    PdfTemplate template = canvas.createTemplate(200, 36);
    template.setLineWidth(2);
    for (int i = 0; i < 6; i++) {
        template.moveTo(0, i * 6);
        template.lineTo(200, i * 6);
    }
    template.stroke();

    canvas.saveState();
    canvas.beginText();
    canvas.setTextMatrix(360, 610);
    canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_CLIP);
    canvas.setFontAndSize(bf, 24);
    canvas.showText(text);
    canvas.endText();
    canvas.addTemplate(template, 360, 610);
    canvas.restoreState();

    canvas.saveState();
    canvas.beginText();
    canvas.setTextMatrix(360, 570);
    canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE_CLIP);
    canvas.setFontAndSize(bf, 24);
    canvas.showText(text);
    canvas.endText();
    canvas.addTemplate(template, 360, 570);
    canvas.restoreState();

    canvas.saveState();
    canvas.beginText();
    canvas.setTextMatrix(360, 530);
    canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE_CLIP);
    canvas.setFontAndSize(bf, 24);
    canvas.showText(text);
    canvas.endText();
    canvas.addTemplate(template, 360, 530);
    canvas.restoreState();

    canvas.saveState();
    canvas.beginText();
    canvas.setTextMatrix(360, 490);
    canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_CLIP);
    canvas.setFontAndSize(bf, 24);
    canvas.showText(text);
    canvas.endText();
    canvas.addTemplate(template, 360, 490);
    canvas.restoreState();

    // step 5
    //document.add((Element) pdfAcroForm);
    document.close();
}

From source file:com.carfinance.module.common.controller.DocumentDownloadController.java

/**
 * ???PDF//from   w ww  .  ja va 2  s.c  om
 * @param model
 * @param request
 * @param response
 */
@RequestMapping(value = "/pdfcontrace", method = RequestMethod.GET)
public void pdfContrace(Model model, HttpServletRequest request, HttpServletResponse response) {
    String contrace_id_str = request.getParameter("contrace_id");
    long contrace_type = Long.valueOf(request.getParameter("contrace_type"));//??1-2-?
    long vehicle_contrace_id = Long.valueOf(request.getParameter("vehicle_contrace_id"));

    String org_id = "";
    String contrace_no = "";
    String customer_name = "";
    String license_plate = "";
    String vehicle_model = "";
    String engine_no = "";
    String carframe_no = "";
    double guide_price = 0;
    String color = "";
    String begin_time = "";
    String end_time = "";
    String driving_user_name = "";
    String driving_user_license_no = "";
    String daily_price = "";
    String daily_available_km = "";
    String over_km_price = "";
    String over_hour_price = "";
    String month_price = "";
    String month_available_km = "";
    String pre_payment = "";
    String deposit = "";
    String monthly_day = "";
    String vehicle_id = "";

    if (contrace_type == 1) {
        VehicleContraceInfo vehicleContraceInfo = this.vehicleServiceManageService
                .getVehicleContraceInfoById(Long.valueOf(contrace_id_str));
        if (vehicleContraceInfo != null) {
            org_id = String.valueOf(vehicleContraceInfo.getOrg_id());
            contrace_no = vehicleContraceInfo.getContrace_no();
            customer_name = vehicleContraceInfo.getCustomer_name();

            //                List<VehicleContraceVehsInfo> vehsList = this.vehicleServiceManageService.getVehicleContraceVehsListByContraceId(vehicleContraceInfo.getId());
            //                if(vehsList != null) {
            //                    VehicleContraceVehsInfo vehsInfo = vehsList.get(0);
            VehicleContraceVehsInfo vehsInfo = this.vehicleServiceManageService
                    .getContraceVehicleByid(vehicle_contrace_id);
            VehicleInfo vehicleInfo = this.vehicleManageService.getVehicleInfoByid(vehsInfo.getVehicle_id());

            license_plate = vehicleInfo.getLicense_plate();
            vehicle_model = vehicleInfo.getModel();
            engine_no = vehicleInfo.getEngine_no();
            carframe_no = vehicleInfo.getCarframe_no();
            guide_price = vehicleInfo.getGuide_price();
            color = vehicleInfo.getColor();

            driving_user_name = vehsInfo.getDriving_user_name();
            driving_user_license_no = vehsInfo.getDriving_user_license_no();

            daily_price = vehicleInfo.getDaily_price() + "";
            vehicle_id = vehicleInfo.getId() + "";
            //                }

            begin_time = vehicleContraceInfo.getUse_begin();
            end_time = vehicleContraceInfo.getUse_end();

            daily_available_km = vehicleContraceInfo.getDaily_available_km() + "";
            over_km_price = vehicleContraceInfo.getOver_km_price() + "";
            over_hour_price = vehicleContraceInfo.getOver_hour_price() + "";
            month_price = vehicleContraceInfo.getMonth_price() + "";
            month_available_km = vehicleContraceInfo.getMonth_available_km() + "";
            pre_payment = vehicleContraceInfo.getPre_payment() + "";
            deposit = vehicleContraceInfo.getDeposit() + "";
            monthly_day = vehicleContraceInfo.getMonthly_day() + "";
        }
    } else if (contrace_type == 2) {
        PropertyContraceInfo propertyContraceInfo = this.vehicleServiceManageService
                .getPropertyContraceInfoById(Long.valueOf(contrace_id_str));
        if (propertyContraceInfo != null) {
            org_id = String.valueOf(propertyContraceInfo.getOrg_id());
            contrace_no = propertyContraceInfo.getContrace_no();
            customer_name = propertyContraceInfo.getCustomer_name();
        }
    }
    //1.ContentType
    response.setContentType("multipart/form-data");
    //2.????(??a.pdf)
    response.setHeader("Content-Disposition", "attachment;fileName=" + contrace_no + "_" + vehicle_id + ".pdf");

    Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
    // ?? pdf ?
    try {
        BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);

        Font bold_fontChinese = new Font(bfChinese, 18, Font.BOLD, BaseColor.BLACK);
        Font normal_fontChinese = new Font(bfChinese, 12, Font.NORMAL, BaseColor.BLACK);
        Font normal_desc_fontChinese = new Font(bfChinese, 6, Font.NORMAL, BaseColor.BLACK);

        FileOutputStream pdfFile = new FileOutputStream(new File(
                appProps.get("normal.contrace.download.path") + contrace_no + "_" + vehicle_id + ".pdf"));
        // pdf ?
        Paragraph paragraph1 = new Paragraph("???", bold_fontChinese);
        paragraph1.setAlignment(Element.ALIGN_CENTER);

        Chunk customer_name_underline = new Chunk(customer_name);
        customer_name_underline.setUnderline(1f, 3f);

        Chunk license_plate_underline = new Chunk(license_plate);
        license_plate_underline.setUnderline(1f, 3f);

        Chunk vehicle_model_underline = new Chunk(vehicle_model);
        vehicle_model_underline.setUnderline(1f, 3f);

        Chunk engine_no_underline = new Chunk(engine_no);
        engine_no_underline.setUnderline(1f, 3f);

        Chunk carframe_no_underline = new Chunk(carframe_no);
        carframe_no_underline.setUnderline(1f, 3f);

        Chunk guide_price_underline = new Chunk(guide_price / 10000 + "");
        guide_price_underline.setUnderline(1f, 3f);

        Chunk color_underline = new Chunk(color);
        color_underline.setUnderline(1f, 3f);

        Chunk begin_time_underline = new Chunk(begin_time);
        begin_time_underline.setUnderline(1f, 3f);

        Chunk end_time_underline = new Chunk(end_time);
        end_time_underline.setUnderline(1f, 3f);

        Chunk driving_user_name_underline = new Chunk(
                driving_user_name == null ? "___/___" : driving_user_name);
        driving_user_name_underline.setUnderline(1f, 3f);

        Chunk driving_user_license_no_underline = new Chunk(
                driving_user_license_no == null ? "_____/_____" : driving_user_license_no);
        driving_user_license_no_underline.setUnderline(1f, 3f);

        Chunk daily_price_underline = new Chunk(daily_price);
        daily_price_underline.setUnderline(1f, 3f);

        Chunk daily_available_km_underline = new Chunk(daily_available_km);
        daily_available_km_underline.setUnderline(1f, 3f);

        Chunk over_km_price_underline = new Chunk(over_km_price);
        over_km_price_underline.setUnderline(1f, 3f);

        Chunk over_hour_price_underline = new Chunk(over_hour_price);
        over_hour_price_underline.setUnderline(1f, 3f);

        Chunk month_price_underline = new Chunk(month_price == null ? "_____/_____" : month_price);
        month_price_underline.setUnderline(1f, 3f);

        Chunk month_available_km_underline = new Chunk(
                month_available_km == null ? "_____/_____" : month_available_km);
        month_available_km_underline.setUnderline(1f, 3f);

        Chunk pre_payment_underline = new Chunk(pre_payment);
        pre_payment_underline.setUnderline(1f, 3f);

        Chunk deposit_underline = new Chunk(deposit);
        deposit_underline.setUnderline(1f, 3f);

        Chunk monthly_day_underline = new Chunk(monthly_day == null ? "___/___" : monthly_day);
        monthly_day_underline.setUnderline(1f, 3f);

        Paragraph paragraph2 = new Paragraph(
                "???    ???"
                        + contrace_no,
                normal_fontChinese);
        Paragraph paragraph3 = new Paragraph("" + customer_name_underline
                + " (    20____________", normal_fontChinese);
        Paragraph paragraph4 = new Paragraph(
                "??? ??????????",
                normal_fontChinese);
        Paragraph paragraph5 = new Paragraph("???____"
                + license_plate_underline + "____?____" + vehicle_model_underline
                + "________" + color_underline + "____??____" + engine_no_underline
                + "____?____" + carframe_no_underline + "____??____"
                + guide_price_underline + "____", normal_fontChinese);
        Paragraph paragraph6 = new Paragraph("?____" + begin_time_underline
                + "____?____" + end_time_underline + "____",
                normal_fontChinese);
        Paragraph paragraph7 = new Paragraph("??____"
                + driving_user_name_underline + "____??____" + driving_user_license_no_underline
                + "____?", normal_fontChinese);
        Paragraph paragraph8 = new Paragraph("????", normal_fontChinese);
        Paragraph paragraph9 = new Paragraph("1????____" + daily_price_underline
                + "____??____" + daily_available_km_underline
                + "____??____" + over_km_price_underline
                + "____??____" + over_hour_price_underline
                + "____??30????____"
                + month_price_underline + "____??____" + month_available_km_underline
                + "____30",
                normal_fontChinese);
        Paragraph paragraph10 = new Paragraph(
                "2??????8:00---20:00",
                normal_fontChinese);
        Paragraph paragraph11 = new Paragraph(
                "3??????",
                normal_fontChinese);
        Paragraph paragraph12 = new Paragraph(
                "4????____" + pre_payment_underline
                        + "____??____"
                        + monthly_day_underline + "____?",
                normal_fontChinese);
        Paragraph paragraph13 = new Paragraph("5???____"
                + deposit_underline
                + "____(???)???????",
                normal_fontChinese);
        Paragraph paragraph14 = new Paragraph(
                "6????1%????????",
                normal_fontChinese);
        Image image = Image.getInstance(appProps.get("normal.contrace.download.path") + "chekuang.jpg");

        Paragraph paragraph15 = new Paragraph("?", normal_desc_fontChinese);
        Paragraph paragraph16 = new Paragraph(
                "1?????????",
                normal_desc_fontChinese);
        Paragraph paragraph17 = new Paragraph(
                "2????5000?200",
                normal_desc_fontChinese);
        Paragraph paragraph18 = new Paragraph(
                "3????",
                normal_desc_fontChinese);
        Paragraph paragraph19 = new Paragraph(
                "4???????????????",
                normal_desc_fontChinese);
        Paragraph paragraph20 = new Paragraph(
                "5?????????",
                normal_desc_fontChinese);
        Paragraph paragraph21 = new Paragraph(
                "6????????????",
                normal_desc_fontChinese);
        Paragraph paragraph22 = new Paragraph("?", normal_desc_fontChinese);
        Paragraph paragraph23 = new Paragraph(
                "1???????",
                normal_desc_fontChinese);
        Paragraph paragraph24 = new Paragraph(
                "2?????????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph25 = new Paragraph(
                "3????????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph26 = new Paragraph(
                "4?????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph27 = new Paragraph(
                "5????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph28 = new Paragraph(
                "6?????????????????????620%?30%??????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph29 = new Paragraph(
                "7???????????",
                normal_desc_fontChinese);
        Paragraph paragraph30 = new Paragraph(
                "8????????",
                normal_desc_fontChinese);

        Paragraph paragraph31 = new Paragraph(
                "9??????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph32 = new Paragraph(
                "10????????????",
                normal_desc_fontChinese);
        Paragraph paragraph33 = new Paragraph(
                "11???????????500-1000",
                normal_desc_fontChinese);
        Paragraph paragraph34 = new Paragraph(
                "12??????????",
                normal_desc_fontChinese);
        Paragraph paragraph35 = new Paragraph(
                "13?????_________________________________7??????????\n",
                normal_desc_fontChinese);
        Paragraph paragraph36 = new Paragraph(
                "14?????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph37 = new Paragraph(
                "15?????????5000????????????????400?500100????",
                normal_desc_fontChinese);
        Paragraph paragraph38 = new Paragraph(
                "16???????????????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph39 = new Paragraph("?", normal_desc_fontChinese);
        Paragraph paragraph40 = new Paragraph(
                "1??????????????",
                normal_desc_fontChinese);
        Paragraph paragraph41 = new Paragraph(
                "2????????????",
                normal_desc_fontChinese);
        Paragraph paragraph42 = new Paragraph(
                "3????",
                normal_desc_fontChinese);
        Paragraph paragraph43 = new Paragraph(
                "4??????????50%?????????",
                normal_desc_fontChinese);
        Paragraph paragraph44 = new Paragraph(
                "5???????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph45 = new Paragraph(
                "6???????????????",
                normal_desc_fontChinese);
        Paragraph paragraph46 = new Paragraph(
                "7?????????50%",
                normal_desc_fontChinese);
        Paragraph paragraph47 = new Paragraph(
                "8???7????????????",
                normal_desc_fontChinese);
        Paragraph paragraph48 = new Paragraph(
                "9???_____/?40??8????_____??",
                normal_desc_fontChinese);
        Paragraph paragraph49 = new Paragraph(
                "10?????___?????",
                normal_desc_fontChinese);
        Paragraph paragraph50 = new Paragraph(
                "11????",
                normal_desc_fontChinese);
        Paragraph paragraph51 = new Paragraph("??", normal_desc_fontChinese);
        Paragraph paragraph52 = new Paragraph(
                "1?????????20%????",
                normal_desc_fontChinese);
        Paragraph paragraph53 = new Paragraph(
                "2???????????????????",
                normal_desc_fontChinese);
        Paragraph paragraph54 = new Paragraph(
                "?????___________________\n",
                normal_desc_fontChinese);
        Paragraph paragraph55 = new Paragraph(
                "???????????????",
                normal_desc_fontChinese);
        Paragraph paragraph56 = new Paragraph(
                "???????",
                normal_desc_fontChinese);
        Paragraph paragraph57 = new Paragraph("?????????",
                normal_desc_fontChinese);
        Paragraph paragraph58 = new Paragraph(
                "???                     ?",
                normal_desc_fontChinese);
        Paragraph paragraph59 = new Paragraph(
                "                                           ???                            ??",
                normal_desc_fontChinese);

        //  Document ?File  PdfWriter ?
        PdfWriter.getInstance(pdfDoc, pdfFile);
        pdfDoc.open(); //  Document 

        // ??
        pdfDoc.add(paragraph1);
        pdfDoc.add(new Chunk("\n\n"));
        pdfDoc.add(paragraph2);
        pdfDoc.add(paragraph3);
        pdfDoc.add(paragraph4);
        pdfDoc.add(paragraph5);
        pdfDoc.add(paragraph6);
        pdfDoc.add(paragraph7);
        pdfDoc.add(paragraph8);
        pdfDoc.add(paragraph9);
        pdfDoc.add(paragraph10);
        pdfDoc.add(paragraph11);
        pdfDoc.add(paragraph12);
        pdfDoc.add(paragraph13);
        pdfDoc.add(paragraph14);
        pdfDoc.add(image);

        pdfDoc.newPage();
        pdfDoc.add(paragraph15);
        pdfDoc.add(paragraph16);
        pdfDoc.add(paragraph17);
        pdfDoc.add(paragraph18);
        pdfDoc.add(paragraph19);
        pdfDoc.add(paragraph20);
        pdfDoc.add(paragraph21);
        pdfDoc.add(paragraph22);
        pdfDoc.add(paragraph23);
        pdfDoc.add(paragraph24);
        pdfDoc.add(paragraph25);
        pdfDoc.add(paragraph26);
        pdfDoc.add(paragraph27);
        pdfDoc.add(paragraph28);
        pdfDoc.add(paragraph29);
        pdfDoc.add(paragraph30);
        pdfDoc.add(paragraph31);
        pdfDoc.add(paragraph32);
        pdfDoc.add(paragraph33);
        pdfDoc.add(paragraph34);
        pdfDoc.add(paragraph35);
        pdfDoc.add(paragraph36);
        pdfDoc.add(paragraph37);
        pdfDoc.add(paragraph38);
        pdfDoc.add(paragraph39);
        pdfDoc.add(paragraph40);
        pdfDoc.add(paragraph41);
        pdfDoc.add(paragraph42);
        pdfDoc.add(paragraph43);
        pdfDoc.add(paragraph44);
        pdfDoc.add(paragraph45);
        pdfDoc.add(paragraph46);
        pdfDoc.add(paragraph47);
        pdfDoc.add(paragraph48);
        pdfDoc.add(paragraph49);
        pdfDoc.add(paragraph50);
        pdfDoc.add(paragraph51);
        pdfDoc.add(paragraph52);
        pdfDoc.add(paragraph53);
        pdfDoc.add(paragraph54);
        pdfDoc.add(paragraph55);
        pdfDoc.add(paragraph56);
        pdfDoc.add(paragraph57);
        pdfDoc.add(paragraph58);
        pdfDoc.add(paragraph59);

        pdfDoc.close();

        ServletOutputStream out;
        //File(?download.pdf)
        File file = new File(
                appProps.get("normal.contrace.download.path") + contrace_no + "_" + vehicle_id + ".pdf");

        try {
            FileInputStream inputStream = new FileInputStream(file);
            //3.response?ServletOutputStream(out)
            out = response.getOutputStream();
            int b = 0;
            byte[] buffer = new byte[512];
            while (b != -1) {
                b = inputStream.read(buffer);
                //4.?(out)
                out.write(buffer, 0, b);
            }
            inputStream.close();
            out.close();
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.carfinance.module.common.controller.DocumentDownloadController.java

/**
 * ??//ww w.  j ava 2  s  .  co m
 * @param model
 * @param request
 * @param response
 */
@RequestMapping(value = "/pdfhunchecontrace", method = RequestMethod.GET)
public void pdfHuncheContrace(Model model, HttpServletRequest request, HttpServletResponse response) {
    String contrace_id_str = request.getParameter("contrace_id");

    String org_id = "";
    String contrace_no = "";
    String customer_name = "";
    String vehicle_id = "";
    String daily_available_km = "";

    VehicleContraceInfo vehicleContraceInfo = this.vehicleServiceManageService
            .getVehicleContraceInfoById(Long.valueOf(contrace_id_str));
    if (vehicleContraceInfo != null) {
        org_id = String.valueOf(vehicleContraceInfo.getOrg_id());
        contrace_no = vehicleContraceInfo.getContrace_no();
        customer_name = vehicleContraceInfo.getCustomer_name();
        daily_available_km = vehicleContraceInfo.getDaily_available_km() + "";
    } else {
        PropertyContraceInfo propertyContraceInfo = this.vehicleServiceManageService
                .getPropertyContraceInfoById(Long.valueOf(contrace_id_str));
        if (propertyContraceInfo != null) {
            org_id = String.valueOf(propertyContraceInfo.getOrg_id());
            contrace_no = propertyContraceInfo.getContrace_no();
            customer_name = propertyContraceInfo.getCustomer_name();
        }
    }

    List<VehicleContraceVehsInfo> vehicleContraceVehsInfoList = this.vehicleServiceManageService
            .getVehicleContraceVehsListByContraceId(Long.valueOf(contrace_id_str));

    //1.ContentType
    response.setContentType("multipart/form-data");
    //2.????(??a.pdf)
    response.setHeader("Content-Disposition", "attachment;fileName=" + contrace_no + ".pdf");

    Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
    // ?? pdf ?
    try {
        BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);

        Font bold_fontChinese = new Font(bfChinese, 18, Font.BOLD, BaseColor.BLACK);
        Font normal_fontChinese = new Font(bfChinese, 12, Font.NORMAL, BaseColor.BLACK);
        Font normal_desc_fontChinese = new Font(bfChinese, 6, Font.NORMAL, BaseColor.BLACK);

        FileOutputStream pdfFile = new FileOutputStream(
                new File(appProps.get("hunche.contrace.download.path") + contrace_no + ".pdf"));
        // pdf ?
        Paragraph paragraph1 = new Paragraph("???", bold_fontChinese);
        paragraph1.setAlignment(Element.ALIGN_CENTER);

        Paragraph paragraph2 = new Paragraph(
                "???", normal_fontChinese);
        Paragraph paragraph3 = new Paragraph("" + customer_name + " (",
                normal_fontChinese);
        Paragraph paragraph4 = new Paragraph(
                "?????________________???",
                normal_fontChinese);
        Paragraph paragraph5 = new Paragraph("??????",
                normal_fontChinese);
        // table
        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100);
        table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        PdfPCell cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        // 
        cell.setPhrase(new Paragraph("?", normal_fontChinese));
        table.addCell(cell);
        cell.setPhrase(new Paragraph("", normal_fontChinese));
        table.addCell(cell);
        cell.setPhrase(new Paragraph("?/", normal_fontChinese));
        table.addCell(cell);
        cell.setPhrase(new Paragraph("?", normal_fontChinese));
        table.addCell(cell);
        // ?
        for (VehicleContraceVehsInfo v : vehicleContraceVehsInfoList) {

            PdfPCell newcell = new PdfPCell();
            newcell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            newcell.setPhrase(new Paragraph("1", normal_fontChinese));
            table.addCell(newcell);
            newcell.setPhrase(new Paragraph(v.getModel(), normal_fontChinese));
            table.addCell(newcell);
            newcell.setPhrase(new Paragraph(v.getDaily_price() + "", normal_fontChinese));
            table.addCell(newcell);
            newcell.setPhrase(new Paragraph(daily_available_km, normal_fontChinese));
            table.addCell(newcell);
        }

        Paragraph paragraph6 = new Paragraph(
                "??_________________________________________________________________",
                normal_fontChinese);
        Paragraph paragraph7 = new Paragraph(
                "____________________________?______",
                normal_fontChinese);
        Paragraph paragraph8 = new Paragraph("????", normal_fontChinese);
        Paragraph paragraph9 = new Paragraph(
                "???________________________???________________________",
                normal_fontChinese);
        Paragraph paragraph10 = new Paragraph("?", normal_fontChinese);
        Paragraph paragraph11 = new Paragraph(
                "???????????????",
                normal_fontChinese);
        Paragraph paragraph12 = new Paragraph("?", normal_fontChinese);
        Paragraph paragraph13 = new Paragraph(
                "??????????????",
                normal_fontChinese);
        Paragraph paragraph14 = new Paragraph(
                "?????????",
                normal_fontChinese);
        Paragraph paragraph15 = new Paragraph("?????",
                normal_fontChinese);
        Paragraph paragraph16 = new Paragraph(
                "(/)                                       (/)",
                normal_fontChinese);
        Paragraph paragraph17 = new Paragraph(
                "                                                      ??", normal_fontChinese);
        Paragraph paragraph18 = new Paragraph(
                "??                                               ??  ",
                normal_fontChinese);
        Paragraph paragraph19 = new Paragraph(
                "                                                      201          ",
                normal_fontChinese);

        //  Document ?File  PdfWriter ?
        PdfWriter.getInstance(pdfDoc, pdfFile);
        pdfDoc.open(); //  Document 

        // ??
        pdfDoc.add(paragraph1);
        pdfDoc.add(new Chunk("\n\n"));
        pdfDoc.add(paragraph2);
        pdfDoc.add(paragraph3);
        pdfDoc.add(paragraph4);
        pdfDoc.add(paragraph5);
        pdfDoc.add(table);
        pdfDoc.add(paragraph6);
        pdfDoc.add(paragraph7);
        pdfDoc.add(paragraph8);
        pdfDoc.add(paragraph9);
        pdfDoc.add(paragraph10);
        pdfDoc.add(paragraph11);
        pdfDoc.add(paragraph12);
        pdfDoc.add(paragraph13);
        pdfDoc.add(paragraph14);
        pdfDoc.add(paragraph15);
        pdfDoc.add(paragraph16);
        pdfDoc.add(paragraph17);
        pdfDoc.add(paragraph18);
        pdfDoc.add(paragraph19);

        pdfDoc.close();

        ServletOutputStream out;
        //File(?download.pdf)
        File file = new File(appProps.get("hunche.contrace.download.path") + contrace_no + ".pdf");

        try {
            FileInputStream inputStream = new FileInputStream(file);
            //3.response?ServletOutputStream(out)
            out = response.getOutputStream();
            int b = 0;
            byte[] buffer = new byte[512];
            while (b != -1) {
                b = inputStream.read(buffer);
                //4.?(out)
                out.write(buffer, 0, b);
            }
            inputStream.close();
            out.close();
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.devox.GUI.PDF.CrearReporteDestruccion.java

@Override
public void crear(File file) {
    try {/*from  ww w .  j a  v  a 2  s  . com*/
        document = new Document(PageSize.A4, 50f, 50f, 100f, 220f);
        file.createNewFile();
        writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina event = new CabeceraPieDePagina();
        writer.setPageEvent(event);
        document.newPage();
        Paragraph p = new Paragraph("RELACIN DE PRODUCTOS PARA DESTRUCCIN", FUENTE_TITULO_APTO);
        p.setAlignment(Element.ALIGN_CENTER);
        document.add(p);
        document.add(configurarInformacion());
        PdfPTable table = crearTabla();
        agregarProductos(table);
        document.add(table);
        document.close();
    } catch (IOException | DocumentException ex) {
        Log.print(ex);
    }

    Object[] options = { "Abrir PDF", "No" };
    int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
            new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options,
            options[0]);
    if (open == JOptionPane.YES_OPTION) {
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException ex) {
            Log.print("No se encontr la ruta");
            JOptionPane.showMessageDialog(null, "Error en el archivo");
        }
    }
}

From source file:com.devox.GUI.PDF.CrearReportePorEstado.java

@Override
public void crear(File file) {
    try {/*from   w w  w  . ja  va 2 s.co  m*/
        Document document = new Document(PageSize.A4, 50f, 50f, 65f, 100f);
        file.createNewFile();
        PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina event = new CabeceraPieDePagina();
        w.setPageEvent(event);
        document.newPage();
        document.add(configurarInformacion());
        document.add(new Paragraph("\n"));
        PdfPTable table = crearTabla();
        agregarProductos(table);
        document.add(table);
        document.add(new Paragraph("\n"));
        document.add(new Paragraph("TOTAL: " + data.length + "FOLIOS.", FUENTE_FOLIO_CHICA));
        document.close();
    } catch (Exception ex) {
        Log.print(ex);
    }

    Object[] options = { "Abrir PDF", "No" };
    int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
            new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options,
            options[0]);
    if (open == JOptionPane.YES_OPTION) {
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException ex) {
            Log.print("No se encontr la ruta");
            JOptionPane.showMessageDialog(null, "Error en el archivo");
        }
    }
}

From source file:com.ephesoft.dcma.imagemagick.MultiPageExecutor.java

License:Open Source License

/**
 * This method creates multi page pdf using IText.
 * /*from   ww w  .j av a 2 s  .  c  o  m*/
 * @param batchInstanceThread {@link BatchInstanceThread}
 * @param pages11 {@link String}
 * @param widthOfPdfPage int
 * @param heightOfPdfPage int
 */
public MultiPageExecutor(BatchInstanceThread batchInstanceThread, final String[] pages11,
        final int widthOfPdfPage, final int heightOfPdfPage) {
    if (pages11 != null && pages11.length > 0) {
        this.pages = new String[pages11.length];
        this.pages = pages11.clone();
        batchInstanceThread.add(new AbstractRunnable() {

            @Override
            public void run() {
                String pdf = pages[pages.length - 1];
                Document document = null;
                PdfWriter writer = null;
                RandomAccessFileOrArray randomAccessArray = null;
                try {
                    document = new Document(PageSize.LETTER, 0, 0, 0, 0);
                    writer = PdfWriter.getInstance(document, new FileOutputStream(pdf));
                    document.open();
                    int comps = 1;
                    int totalTiffImages = pages.length - 1;
                    int index = 0;
                    while (index < totalTiffImages) {
                        randomAccessArray = new RandomAccessFileOrArray(pages[index]);
                        comps = TiffImage.getNumberOfPages(randomAccessArray);
                        // Conversion statement
                        for (int tiffPageNumber = 0; tiffPageNumber < comps; ++tiffPageNumber) {
                            Image img = TiffImage.getTiffImage(randomAccessArray, tiffPageNumber + 1);
                            img.scaleToFit(widthOfPdfPage, heightOfPdfPage);
                            document.add(img);
                            document.newPage();
                        }
                        index++;
                    }
                } catch (Exception e) {
                    LOGGER.error("Error while creating pdf using iText" + e.getMessage(), e);
                    //pdf = null;
                } finally {
                    try {
                        if (document != null) {
                            document.close();
                        }
                        if (writer != null) {
                            writer.close();
                        }
                        if (randomAccessArray != null) {
                            randomAccessArray.close();
                        }
                    } catch (Exception e) {
                        LOGGER.error("Error while closing I/O streams for write PDF. " + e.getMessage());
                    }
                }
            }
        });
    }
}

From source file:com.ephesoft.dcma.imagemagick.MultiPageExecutor.java

License:Open Source License

/**
 * The <code>MultiPageExecutor</code> method creates multi page searchable pdf using IText.
 * //from w  ww  .  ja  va 2 s.co m
 * @param batchInstanceThread {@link BatchInstanceThread} thread instance of batch
 * @param imageHtmlMap {@link Map} map containing image url with corresponding hocr
 * @param isColoredPDF true for colored image pdf else otherwise
 * @param isSearchablePDF true for searchable pdf else otherwise
 * @param pdfFilePath {@link String} path where new pdf has to be created
 * @param widthOfLine Integer for line width to be used
 */
public MultiPageExecutor(BatchInstanceThread batchInstanceThread, final Map<String, HocrPage> imageHtmlMap,
        final boolean isColoredPDF, final boolean isSearchablePDF, final String pdfFilePath,
        final int widthOfLine, final String[] pages) {
    if (imageHtmlMap != null && !imageHtmlMap.isEmpty()) {
        this.pages = new String[pages.length];
        this.pages = pages.clone();
        batchInstanceThread.add(new AbstractRunnable() {

            @Override
            public void run() {
                String pdf = pdfFilePath;
                Document document = null;
                PdfWriter writer = null;
                FileOutputStream fileOutputStream = null;
                boolean isPdfSearchable = isSearchablePDF;
                boolean isColoredImage = isColoredPDF;
                LOGGER.info("is searchable pdf: " + isPdfSearchable + ", is Colored Image: " + isColoredImage);
                try {
                    document = new Document(PageSize.LETTER, 0, 0, 0, 0);
                    fileOutputStream = new FileOutputStream(pdf);
                    writer = PdfWriter.getInstance(document, fileOutputStream);
                    document.open();
                    Set<String> imageSet = imageHtmlMap.keySet();
                    for (String imageUrl : imageSet) {
                        HocrPage hocrPage = imageHtmlMap.get(imageUrl);
                        String newImageUrl = getCompressedImage(isColoredImage, imageUrl);
                        LOGGER.info("New Image URL: " + newImageUrl);
                        addImageToPdf(writer, hocrPage, newImageUrl, isPdfSearchable, widthOfLine);
                        document.newPage();
                        (new File(newImageUrl)).delete();
                    }
                } catch (FileNotFoundException fileNotFoundException) {
                    LOGGER.error("Error occurred while creating pdf " + pdf + " : "
                            + fileNotFoundException.toString());
                } catch (DocumentException documentException) {
                    LOGGER.error(
                            "Error occurred while creating pdf " + pdf + " : " + documentException.toString());
                } finally {
                    if (document != null && document.isOpen()) {
                        document.close();
                    }
                    // Closing pdf writer
                    if (null != writer) {
                        writer.close();
                    }

                    // Closing file output stream of pdf
                    if (null != fileOutputStream) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException ioException) {
                            LOGGER.error("Error occurred while closing stream for pdf " + pdf + " : "
                                    + ioException.toString());
                        }
                    }
                }
            }
        });
    }
}

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

public InventoryCasesReportPDF() {
    Document document = null;//from   w  w  w  .  ja va 2 s .c o m
    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();
    }
}