Example usage for com.itextpdf.layout Document Document

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

Introduction

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

Prototype

public Document(PdfDocument pdfDoc, PageSize pageSize) 

Source Link

Document

Creates a document from a PdfDocument with a manually set PageSize .

Usage

From source file:com.isw.cec.Servlet.GenerarFoliosServlet.java

License:Open Source License

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String appPath = request.getServletContext().getRealPath("");
    String savePath = appPath + File.separator + SAVE_DIR;

    File fileSaveDir = new File(savePath);
    if (!fileSaveDir.exists())
        fileSaveDir.mkdirs();//  w w  w  .j  a  va 2s.co m

    String fileName = java.util.UUID.randomUUID().toString() + ".pdf";
    Curso curso = (Curso) request.getAttribute("curso");
    List<Entry<String, String>> alum_fol = Reader.getAlumFolios(curso.getID());

    OutputStream fos = new FileOutputStream(savePath + File.separator + fileName);
    PdfWriter writer = new PdfWriter(fos);

    PdfDocument pdf = new PdfDocument(writer);

    Document document = new Document(pdf, PageSize.A4);
    document.setMargins(85, 57, 71, 71);

    PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
    PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD);

    Paragraph p = new Paragraph("Folios de los alumnos inscritos al curso");
    p.setTextAlignment(TextAlignment.CENTER);
    document.add(p);

    p = new Paragraph(curso.getNombre());
    p.setFont(bold);
    p.setTextAlignment(TextAlignment.CENTER);
    p.setMarginBottom(70);
    document.add(p);

    Table table = new Table(new float[] { 1, 1 });
    table.setWidthPercent(100);

    Cell c = new Cell().add(new Paragraph("ALUMNO").setFont(bold));
    c.setTextAlignment(TextAlignment.CENTER);
    table.addHeaderCell(c);

    c = new Cell().add(new Paragraph("FOLIO").setFont(bold));
    c.setTextAlignment(TextAlignment.CENTER);
    table.addHeaderCell(c);

    for (Entry<String, String> e : alum_fol) {
        table.addCell(new Cell().add(new Paragraph(e.getKey()).setFont(font)));
        table.addCell(new Cell().add(new Paragraph(e.getValue()).setFont(font)));
    }

    document.add(table);

    document.close();

    Writer.openCurso(curso.getID(), fileName);
    response.getWriter().println("OK");
}

From source file:machinetoolstore.core.util.PdfGenerator.java

public static boolean getGeneratedPdfByArtifact(ThreeRollMill artifact, String fileName) throws Exception {
    PdfWriter writer = new PdfWriter(GENERATED_FILES_PATH + fileName);
    PdfDocument pdfDocument = new PdfDocument(writer);
    Document document = new Document(pdfDocument, PageSize.A4);

    document.setMargins(15, 15, 15, 40);
    PdfFont mainFont = PdfFontFactory.createFont(FONTS_PATH + "calibril.ttf", "cp1251", false);

    //Header// w ww  .ja va  2 s . c  o  m
    Paragraph headerParagraph = new Paragraph(artifact.getBrand() + " " + artifact.getModel());
    headerParagraph.setItalic();
    headerParagraph.setTextAlignment(TextAlignment.CENTER);
    headerParagraph.setFont(mainFont);
    headerParagraph.setFontSize(20);
    document.add(headerParagraph);

    //Image block witch characteristic
    Table table = new Table(3);
    table.setWidthPercent(100);

    //Image cell
    Cell imageCell = new Cell();
    imageCell.setBorder(Border.NO_BORDER);
    Image machineImage = new Image(ImageDataFactory.create(IMAGE_PATH + artifact.getMainPhoto()));
    machineImage.setWidth(100);
    machineImage.setHeight(100);
    imageCell.add(machineImage);

    //Main characteristic cell
    Cell mainCharacteristicCell = new Cell();
    List mainCharacteristicList = new List().setSymbolIndent(5).setListSymbol("\uFFFF").setFont(mainFont)
            .setFontSize(12);
    mainCharacteristicList.add("ID:").add(":").add(" ?:")
            .add("?:").add("??:").add(", $:");
    mainCharacteristicCell.add(mainCharacteristicList);

    Cell valuesCell = new Cell();
    List valuesList = new List().setSymbolIndent(5).setListSymbol("\uFFFF").setFont(mainFont).setFontSize(12);
    valuesList.add(artifact.getId().toString()).add(artifact.getManufacturer())
            .add(artifact.getYearOfIssue().toString()).add(artifact.getLocation())
            .add(artifact.getMachineState()).add(artifact.getMachinePrice().toString());
    valuesCell.add(valuesList);

    table.addCell(imageCell);
    table.addCell(mainCharacteristicCell);
    table.addCell(valuesCell);

    //Paragraph
    Paragraph contentParagraph = new Paragraph("? ?");
    contentParagraph.setItalic();
    contentParagraph.setTextAlignment(TextAlignment.CENTER);
    contentParagraph.setFont(mainFont);
    contentParagraph.setFontSize(14);
    contentParagraph.setFixedPosition(1, 635, 600);
    document.add(contentParagraph);

    //Main table
    Table mainTable = new Table(2);
    mainTable.setFont(mainFont);
    mainTable.setFontSize(10);
    mainTable.setMarginTop(35);
    mainTable.addCell(" ?").addCell(artifact.getType());
    mainTable.addCell(" , ")
            .addCell(artifact.getMaterialThickness().toString());
    mainTable.addCell(" , ").addCell(artifact.getMaterialWidth().toString());
    mainTable.addCell("? , /").addCell(artifact.getBendingSpeed().toString());
    mainTable.addCell("Min   max ?, ")
            .addCell(artifact.getMinDiameterMaxBend().toString());
    mainTable.addCell("  , ")
            .addCell(artifact.getTopRollDiameter().toString());
    mainTable.addCell(" ? , ")
            .addCell(artifact.getMiddleRollDiameter().toString());
    mainTable.addCell("???   ? , ")
            .addCell(artifact.getDistanceOfBottomTwoRolls().toString());
    mainTable.addCell(
            "?  ? ?  ?, ")
            .addCell(artifact.getMaterialProofStress().toString());
    mainTable.addCell("?  ?, ")
            .addCell(artifact.getMainEnginePower().toString());
    mainTable.addCell(" , ").addCell(artifact.getMachineDimensions());
    mainTable.addCell("? ?, ").addCell(artifact.getMachineWeight().toString());
    mainTable.addCell("?").addCell(artifact.getDescription());

    document.add(table);
    document.add(mainTable);
    document.close();

    return true;
}

From source file:model.PrintPDF.java

public void inThongKeCanBo(ArrayList<CanBo> listCanBo, String pathName, String nam, int gt, String tongNhanVien,
        String soNVVH) {//w w w . j ava 2 s  . co m
    PdfWriter pdfWriter = null;
    String gioiTinh = "";
    if (gt == 1) {
        gioiTinh = "n";
    } else {
        gioiTinh = "nam";
    }

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k cn b " + gioiTinh + " nm " + nam + "\n\n").setFont(hfont)
                .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("S in thoi").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listCanBo.size(); i++) {
            table.addCell(new Paragraph((i + 1) + "").setFont(hfont).setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getMaCB()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getHoTen()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(dateFormat.format(listCanBo.get(i).getNgaySinh())).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getSDT()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
        }
        document.add(table);
        document.add(new Paragraph("\n\n Tng s nhn vin            :  " + tongNhanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(" Tng s nhn vin sp v? hu :  " + tongNhanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));

        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:model.PrintPDF.java

public void thongKeDoanPhi(ArrayList<String> listDataTable, String pathName, String nam, String tongDoanVien,
        String tienDoanPhi) {// w w  w  . ja  va 2s .  co  m
    PdfWriter pdfWriter = null;
    String gioiTinh = "";

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k on vin  " + gioiTinh + " nm " + nam + "\n\n")
                .setFont(hfont).setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("S ti khon ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph("\n\n Tng s on vin           :  " + tongDoanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(" ?on ph (VN? / ?on Vin) :  " + tienDoanPhi + "VN?")
                .setFont(hfont).setTextAlignment(TextAlignment.LEFT));
        double tongTienDoanPhi = Integer.parseInt(tongDoanVien) * Integer.parseInt(tienDoanPhi);
        document.add(new Paragraph(" Tng s ti?n on ph            :  " + tongTienDoanPhi + " VND")
                .setFont(hfont).setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:model.PrintPDF.java

public void thongKeCongDoanPhi(ArrayList<String> listDataTable, String pathName, String nam,
        String tongCongDoanVien, String tienCongDoanPhi) {
    PdfWriter pdfWriter = null;//from   w w  w  .  jav  a 2  s.c  o m

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k cng on vin  nm " + nam + "\n\n").setFont(hfont)
                .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 3, 3 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Chc v ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Cng on ph ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph("\n\n Tng s nhn vin           :  " + tongCongDoanVien)
                .setFont(hfont).setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(" Tng cng on ph  :  " + tienCongDoanPhi).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));

        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:model.PrintPDF.java

public void thongKeDangPhi(ArrayList<String> listDataTable, String pathName, String nam, String tongDangVien) {
    PdfWriter pdfWriter = null;/*from   ww w .jav a 2  s .  c o  m*/

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k ng vin  " + " nm " + nam + "\n\n").setFont(hfont)
                .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Chc v ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("?ng ph ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph("\n\n Tng s ng vin           :  " + tongDangVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:model.PrintPDF.java

public void thongKeTienThi(ArrayList<String> listDataTable, String pathName) {
    PdfWriter pdfWriter = null;/*  w  ww.j av a  2s. c  o  m*/

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k ti?n thi ging vin  " + "\n\n").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Mn h?c").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("S SV ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ph thi").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:model.PrintPDF.java

public void thongKeThieuNhi(ArrayList<String> listDataTable, String pathName) {
    PdfWriter pdfWriter = null;//from  ww w .  j  a  v a  2  s.  c o  m

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k cc chu thiu nhi   " + "\n\n").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 3, 3, 3, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn cn b ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:org.zafritech.zidingorms.io.pdf.PdfServiceImpl.java

@Override
public ByteArrayOutputStream DownloadPDF(Long id) {

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PdfWriter writer = new PdfWriter(outputStream);
    PdfDocument pdf = new PdfDocument(writer);
    PageSize pagesize = PageSize.A4;//from  w w w  . ja  v a 2  s .c o  m

    Artifact artifact = artifactRepository.findOne(id);

    pdf.addEventHandler(PdfDocumentEvent.START_PAGE, new Header(artifact.getArtifactLongName()));

    //        TableHeader handler = new TableHeader();
    //        pdf.addEventHandler(PdfDocumentEvent.START_PAGE, handler); 

    PageXofY event = new PageXofY(pdf);
    pdf.addEventHandler(PdfDocumentEvent.END_PAGE, event);

    try (Document document = new Document(pdf, pagesize)) {

        Div div = new Div();

        document.setMargins(70, 50, 70, 50);

        styles = createPdfStyles(document);

        List<Item> items = itemRepository.findByArtifactIdOrderBySortIndexAsc(id);

        document.setTextAlignment(TextAlignment.CENTER);
        addEmptyLine(document, 20);
        document.add(
                new Paragraph(artifact.getArtifactProject().getProjectName()).addStyle(styles.get("Title")));
        document.add(new Paragraph(artifact.getArtifactType().getArtifactTypeLongName())
                .addStyle(styles.get("Subtitle")));
        document.add(new Paragraph(artifact.getIdentifier()).addStyle(styles.get("Normal")));

        addEmptyLine(document, 45);

        document.setTextAlignment(TextAlignment.LEFT);
        document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));

        for (Item item : items) {

            if (item.getItemClass().equals("HEADER")) {

                switch (item.getItemLevel()) {

                case 1:
                    document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
                    document.add(new Paragraph(item.getItemValue()).addStyle(styles.get("Header1")));
                    break;

                case 2:
                    document.add(new Paragraph(item.getItemValue()).addStyle(styles.get("Header2")));
                    break;

                case 3:
                    document.add(new Paragraph(item.getItemValue()).addStyle(styles.get("Header3")));
                    break;

                case 4:
                    document.add(new Paragraph(item.getItemValue()).addStyle(styles.get("Header4")));
                    break;

                case 5:
                    document.add(new Paragraph(item.getItemValue()).addStyle(styles.get("Header5")));
                    break;

                default:
                    document.add(new Paragraph(item.getItemValue()).addStyle(styles.get("Normal")));
                }

            } else if (item.getItemClass().equals("REQUIREMENT")) {

                Paragraph p = new Paragraph();
                p.add((item.getIdentifier()).trim() + ":").add(new Tab()).add((item.getItemValue()).trim());
                document.add(p);

                addEmptyLine(document, 1);

            } else {

                document.add(new Paragraph(item.getItemValue()).addStyle(styles.get("Normal")));
            }
        }

        document.add(div);
        event.writeTotal(pdf);
        document.close();

        return outputStream;

    } catch (Exception e) {

        return null;
    }
}

From source file:wbs.jsf1.pdf.LottoReceiptBean0.java

public byte[] createPdfFrom(Lottoschein lottoschein) {
    try {/*from www. ja v a 2 s .  c om*/
        zahlen = lottoschein;

        ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
        PdfWriter writer = new PdfWriter(pdfStream);
        PdfDocument pdf = new PdfDocument(writer);
        PageSize pageSize = new PageSize(PageSize.A6);
        Document document = new Document(pdf, pageSize);
        document.setMargins(20, 20, 40, 20);
        PdfFont font = PdfFontFactory.createFont(FontConstants.HELVETICA);
        PdfFont bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD);
        // Header
        document.add(getHeaderTable());
        // Lottozahlen auflisten
        document.add(getZiehungsDatenTable(font, bold));
        // Losnummer
        document.add(getLosnummerTable(font, bold));
        // Spieltage
        document.add(getSpieltageTable(font, bold));
        // Laufzeit
        document.add(getLaufzeitTable(font, bold));
        // Betrag
        document.add(getBetragTable(font, bold));
        document.close();
        LOG.log(Level.INFO, "PDF succesfully created.");
        return pdfStream.toByteArray();
    } catch (IOException ex) {
        Logger.getLogger(LottoReceiptBean0.class.getName()).log(Level.SEVERE, "pdf creation problem", ex);
    }
    return null;
}