Example usage for com.itextpdf.text.pdf PdfPCell setPaddingLeft

List of usage examples for com.itextpdf.text.pdf PdfPCell setPaddingLeft

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setPaddingLeft.

Prototype

public void setPaddingLeft(float paddingLeft) 

Source Link

Document

Setter for property paddingLeft.

Usage

From source file:se.billes.pdf.renderer.model.text.TableParagraph.java

License:Open Source License

@Override
public void onRender(PdfPCell cell) throws PdfRenderException {

    PdfPTable table = new PdfPTable(widths.length);

    try {//  ww w. j a  v  a2  s.  c  o m
        table.setTotalWidth(getTotalWidthsAsPs());
        table.setLockedWidth(true);
        table.setSpacingAfter(0f);

        for (AbstractParagraph tableCell : cells) {

            PdfPCell c = new PdfPCell();
            float[] padding = new float[] { 0f, 0f, 0f, 0f };
            if (tableCell instanceof TableCell) {
                padding = ((TableCell) tableCell).getPadding();
            }
            c.setBorderWidth(0f);
            c.setLeft(0);
            c.setTop(0);
            c.setRight(0);
            c.setBottom(0);
            c.setUseAscender(true);
            c.setIndent(0);
            c.setHorizontalAlignment(Element.ALIGN_LEFT);
            c.setVerticalAlignment(Element.ALIGN_TOP);
            c.setPaddingLeft(SizeFactory.millimetersToPostscriptPoints(padding[0]));
            c.setPaddingBottom(SizeFactory.millimetersToPostscriptPoints(padding[3]));
            c.setPaddingRight(SizeFactory.millimetersToPostscriptPoints(padding[2]));
            c.setPaddingTop(SizeFactory.millimetersToPostscriptPoints(padding[1]));
            c.setBorder(0);
            tableCell.onRender(c);

            table.addCell(c);

        }
        cell.addElement(table);
    } catch (Exception e) {
        throw new PdfRenderException(e);
    }
}

From source file:se.billes.pdf.renderer.request.factory.CellFactory.java

License:Open Source License

public PdfPCell createCell(Block block) {
    float[] margins = block.getMargins();
    PdfPCell cell = new PdfPCell();
    cell.setBorderWidth(0);//from   ww  w . j  a v a  2  s  . c  om
    cell.setVerticalAlignment(VerticalAlign.getByName(block.getVerticalAlign()).getAlignment());
    cell.setLeft(0);
    cell.setTop(0);
    cell.setRight(0);
    cell.setBottom(0);
    cell.setUseAscender(block.isUseAscender());
    cell.setIndent(0);
    cell.setPaddingLeft(SizeFactory.millimetersToPostscriptPoints(margins[0]));
    cell.setPaddingBottom(SizeFactory.millimetersToPostscriptPoints(margins[3]));
    cell.setPaddingRight(SizeFactory.millimetersToPostscriptPoints(margins[1]));
    cell.setPaddingTop(SizeFactory.millimetersToPostscriptPoints(margins[2]));
    cell.setFixedHeight(SizeFactory.millimetersToPostscriptPoints(block.getPosition()[3]));
    cell.setBorder(0);
    cell.setCellEvent(new CellBlockEvent().createEvent(block));
    cell.setRotation(block.getRotation());
    return cell;
}

From source file:se.billes.pdf.renderer.request.factory.CellFactory.java

License:Open Source License

public PdfPCell getFillCell() {
    PdfPCell fillCell = new PdfPCell();
    fillCell.setBorderWidth(0f);//  w w  w.j a v a2  s .co  m
    fillCell.setLeft(0);
    fillCell.setTop(0);
    fillCell.setRight(0);
    fillCell.setBottom(0);
    fillCell.setUseAscender(true);
    fillCell.setIndent(0);
    fillCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    fillCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    fillCell.setPaddingLeft(0f);
    fillCell.setPaddingBottom(0f);
    fillCell.setPaddingRight(0f);
    fillCell.setPaddingTop(0f);
    fillCell.setBorder(0);
    renderEmptyCell(fillCell);

    return fillCell;
}

From source file:server.kartu.tik.iText.java

public String createPDF(String tanggal, ArrayList kegiatan, String divisi) {
    ArrayList<Kegiatan> list = new ArrayList<>(kegiatan);

    String output = System.getProperty("user.dir") + "\\src\\data\\pdf\\" + tanggal + " " + getNamalengkap()
            + "-" + getTglnoktp() + ".pdf";

    String namaDivisi = "";
    switch (divisi) {
    case "1":
        namaDivisi = "Ekonomi";
        break;/* ww  w.j  a  v a  2s  .  c  om*/
    case "2":
        namaDivisi = "Politik";
        break;
    case "3":
        namaDivisi = "Sosial Budaya";
        break;
    case "4":
        namaDivisi = "Keamanan";
        break;
    }

    Document document = new Document(PageSize.A4);
    try {
        PdfWriter.getInstance(document, new FileOutputStream(output));

        document.open();

        //------------------------------------------------------------------------------------- TITLE
        PdfPTable title = new PdfPTable(1);
        title.setWidthPercentage(100);
        Font f = new Font(FontFamily.HELVETICA, 14, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell celltitle = new PdfPCell(new Phrase("KARTU TIK (" + namaDivisi + ")", f));
        celltitle.setMinimumHeight(20);
        celltitle.setBackgroundColor(GrayColor.GRAYBLACK);
        celltitle.setHorizontalAlignment(Element.ALIGN_CENTER);
        celltitle.setColspan(3);
        title.addCell(celltitle);
        document.add(title);
        //-------------------------------------------------------------------------------------- END

        //------------------------------------------------------------------------------------- NAMA + ALIAS
        float[] columnWidths = { 8, 2 };
        PdfPTable tabel1 = new PdfPTable(columnWidths);
        tabel1.setWidthPercentage(100);

        PdfPTable innerTable1 = new PdfPTable(1);
        innerTable1.setWidthPercentage(100);
        PdfPTable innerTable2 = new PdfPTable(1);
        innerTable2.setWidthPercentage(100);
        PdfPCell cell;
        innerTable1.addCell(
                "1.  a. Nama Lengkap : " + getNamalengkap() + " \n\n     b. Alias : " + getAlias() + " \n\n");
        innerTable1.addCell("2.  Kebangsaan \n     a. Tgl. No. KTP : " + getTglnoktp()
                + " \n\n     b. Tgl. No. Pasport : " + getTglnopasport() + "\n\n");
        innerTable1.addCell("3.  Agama : " + getAgama());
        cell = new PdfPCell(innerTable1);
        cell.setMinimumHeight(135);
        tabel1.addCell(cell);
        if (getUrlfoto().equalsIgnoreCase("") || getUrlfoto().isEmpty() || getUrlfoto() == null) {

        } else {
            Image image = Image.getInstance(getUrlfoto());
            cell = new PdfPCell(image, false);
            if (image.getWidth() < 90) {
                cell.setPaddingLeft(8);
            } else {
                cell.setPaddingLeft(3);
            }
        }
        cell.setMinimumHeight(135);
        tabel1.addCell(cell);
        cell = new PdfPCell();
        cell.setColspan(14);
        tabel1.addCell(cell);

        document.add(tabel1);
        //------------------------------------------------------------------------------------- NAMA + ALIAS END

        //------------------------------------------------------------------------------------- TGL LAHIR + TEMPAT
        PdfPTable tabel4 = new PdfPTable(1);
        tabel4.setWidthPercentage(100);

        Paragraph pTglLahirnTempat = new Paragraph();
        pTglLahirnTempat.add("4.  a. Tgl. Lahir/ Umur : " + getTgllahir());
        pTglLahirnTempat.add("\n\n     b. Tempat Lahir     : " + getTempatlahir());
        pTglLahirnTempat.setLeading(0, 1);

        PdfPCell cTglLahirnTempat = new PdfPCell();
        cTglLahirnTempat.setMinimumHeight(45);
        cTglLahirnTempat.addElement(pTglLahirnTempat);
        tabel4.addCell(cTglLahirnTempat);

        document.add(tabel4);
        //------------------------------------------------------------------------------------- TGL LAHIR + TEMPAT END

        //------------------------------------------------------------------------------------- ALAMAT + PINDAHAN
        PdfPTable tabel5 = new PdfPTable(1);
        tabel5.setWidthPercentage(100);

        Paragraph pAlamat = new Paragraph();
        pAlamat.add("5.  Alamat : ");
        pAlamat.add(alamat);
        pAlamat.setLeading(0, 1);

        PdfPCell cAlamat = new PdfPCell();
        cAlamat.setMinimumHeight(18);
        cAlamat.addElement(pAlamat);
        tabel5.addCell(cAlamat);
        document.add(tabel5);

        PdfPTable tabel51 = new PdfPTable(1);
        tabel51.setWidthPercentage(100);

        Paragraph pAlamatUbah = new Paragraph();
        pAlamatUbah.add("6.  Perubahan Alamat :");
        pAlamatUbah.add("\n\n    1. ");
        pAlamatUbah.add("\n\n    2. ");
        pAlamatUbah.add("\n\n    3. ");
        pAlamatUbah.add("\n\n");
        pAlamatUbah.setLeading(0, 1);

        PdfPCell cAlamatUbah = new PdfPCell();
        cAlamatUbah.addElement(pAlamatUbah);
        tabel51.addCell(cAlamatUbah);
        document.add(tabel51);
        //------------------------------------------------------------------------------------- ALAMAT + PINDAHAN END

        //------------------------------------------------------------------------------------- KEDUDUKAN KELUARGA
        PdfPTable tabel6 = new PdfPTable(1);
        tabel6.setWidthPercentage(100);

        Paragraph pKedudukanKeluarga = new Paragraph();
        pKedudukanKeluarga.add("7.  Kedudukan dalam Keluarga : ");
        pKedudukanKeluarga.setLeading(0, 1);

        PdfPCell cKedudukanKeluarga = new PdfPCell();
        cKedudukanKeluarga.setMinimumHeight(20);
        cKedudukanKeluarga.addElement(pKedudukanKeluarga);
        tabel6.addCell(cKedudukanKeluarga);
        document.add(tabel6);

        PdfPTable tabel61 = new PdfPTable(1);
        tabel61.setWidthPercentage(100);

        Paragraph pNamaBapakIbu = new Paragraph();
        pNamaBapakIbu.add("8.  a.  Nama Bapak : ");
        pNamaBapakIbu.add("\n\n          Nama Ibu      : ");
        pNamaBapakIbu.add("\n\n     b.  Alamat : ");
        pNamaBapakIbu.setLeading(0, 1);

        PdfPCell cNamaBapakIbu = new PdfPCell();
        cNamaBapakIbu.setMinimumHeight(70);
        cNamaBapakIbu.addElement(pNamaBapakIbu);
        tabel61.addCell(cNamaBapakIbu);

        document.add(tabel61);
        //------------------------------------------------------------------------------------- KEDUDUKAN END

        //------------------------------------------------------------------------------------- PEKERJAAN
        PdfPTable tabel7 = new PdfPTable(2);
        tabel7.setWidthPercentage(100);

        Paragraph pPekerjaan = new Paragraph();
        pPekerjaan.add("9.  a. Pekerjaan : " + getPekerjaan());
        pPekerjaan.setLeading(0, 1);

        PdfPCell cPekerjaan = new PdfPCell();
        cPekerjaan.setMinimumHeight(20);
        cPekerjaan.addElement(pPekerjaan);
        tabel7.addCell(cPekerjaan);

        Paragraph pJabatan = new Paragraph();
        pJabatan.add("  b. Jabatan : " + getJabatan());
        pJabatan.setLeading(0, 1);

        PdfPCell cJabatan = new PdfPCell();
        cJabatan.setMinimumHeight(20);
        cJabatan.addElement(pJabatan);
        tabel7.addCell(cJabatan);

        document.add(tabel7);
        //------------------------------------------------------------------------------------- PEKERJAAN END

        //------------------------------------------------------------------------------------- INSTANSI DLL
        PdfPTable tabel8 = new PdfPTable(1);
        tabel8.setWidthPercentage(100);

        Paragraph pInstansi = new Paragraph();
        pInstansi.add("     c. Instansi/Lembaga/Kantor : " + getInstansilembagakantor());
        pInstansi.setLeading(0, 1);

        PdfPCell cInstansi = new PdfPCell();
        cInstansi.setMinimumHeight(20);
        cInstansi.addElement(pInstansi);
        tabel8.addCell(cInstansi);

        document.add(tabel8);
        //------------------------------------------------------------------------------------- INSTANSI DLL END

        //------------------------------------------------------------------------------------- NAMA ISTRI
        float[] colomn = { 7, 1, 2 };
        PdfPTable tabel9 = new PdfPTable(colomn);
        tabel9.setWidthPercentage(100);

        Paragraph pNamaIstriBapakIbu = new Paragraph();
        pNamaIstriBapakIbu.add("10.");
        pNamaIstriBapakIbu.add("\n       a. Nama Istri : ");
        pNamaIstriBapakIbu.add("\n\n       b. Nama Bapak Istri : ");
        pNamaIstriBapakIbu.add("\n\n       c. Nama Ibu Istri : ");
        pNamaIstriBapakIbu.add("\n\n       d. Alamat : ");
        pNamaIstriBapakIbu.setLeading(0, 1);

        PdfPCell cNamaIstriBapakIbu = new PdfPCell();
        cNamaIstriBapakIbu.setMinimumHeight(110);
        cNamaIstriBapakIbu.addElement(pNamaIstriBapakIbu);
        tabel9.addCell(cNamaIstriBapakIbu);

        Paragraph pUmurIstriBapakIbu = new Paragraph();
        pUmurIstriBapakIbu.add("  Umur :");
        pUmurIstriBapakIbu.setLeading(0, 1);

        PdfPCell cUmurIstriBapakIbu = new PdfPCell();
        cUmurIstriBapakIbu.setMinimumHeight(110);
        cUmurIstriBapakIbu.addElement(pUmurIstriBapakIbu);
        tabel9.addCell(cUmurIstriBapakIbu);

        Paragraph pPekerjaanIstriBapakIbu = new Paragraph();
        pPekerjaanIstriBapakIbu.add("  Pekerjaan :");
        pPekerjaanIstriBapakIbu.setLeading(0, 1);

        PdfPCell cPekerjaanIstriBapakIbu = new PdfPCell();
        cPekerjaanIstriBapakIbu.setMinimumHeight(110);
        cPekerjaanIstriBapakIbu.addElement(pPekerjaanIstriBapakIbu);
        tabel9.addCell(cPekerjaanIstriBapakIbu);

        document.add(tabel9);
        //------------------------------------------------------------------------------------- NAMA ISTRI END

        //------------------------------------------------------------------------------------- SANAK SAUDARA
        PdfPTable tabel10 = new PdfPTable(colomn);
        tabel10.setWidthPercentage(100);

        Paragraph pSanakSaudara = new Paragraph();
        pSanakSaudara.add("11.  Nama Sanak/Saudara yang menjadi Tanggungan : \n       1.\n       2.");
        pSanakSaudara.setLeading(0, 1);

        PdfPCell cSanakSaudara = new PdfPCell();
        cSanakSaudara.addElement(pSanakSaudara);
        tabel10.addCell(cSanakSaudara);

        Paragraph pSanakSaudara1 = new Paragraph();
        pSanakSaudara1.add("");
        pSanakSaudara1.setLeading(0, 1);

        PdfPCell cSanakSaudara1 = new PdfPCell();
        cSanakSaudara1.addElement(pSanakSaudara1);
        tabel10.addCell(cSanakSaudara1);

        Paragraph pSanakSaudara2 = new Paragraph();
        pSanakSaudara2.add("");
        pSanakSaudara2.setLeading(0, 1);

        PdfPCell cSanakSaudara2 = new PdfPCell();
        cSanakSaudara2.addElement(pSanakSaudara2);
        tabel10.addCell(cSanakSaudara2);

        document.add(tabel10);
        //------------------------------------------------------------------------------------- SANAK SAUDARA END

        //------------------------------------------------------------------------------------- ANAK2
        PdfPTable tabel11 = new PdfPTable(colomn);
        tabel11.setWidthPercentage(100);

        Paragraph pAnak2 = new Paragraph();
        pAnak2.add("12.  Anak-anak : ");
        pAnak2.add("\n\n       1. ");
        pAnak2.add("\n\n       2. ");
        pAnak2.add("\n\n       3. ");
        pAnak2.add("\n\n       4. ");
        pAnak2.add("\n\n       5. ");
        pAnak2.add("\n\n       6. ");
        pAnak2.add("\n");
        pAnak2.setLeading(0, 1);

        PdfPCell cAnak2 = new PdfPCell();
        cAnak2.setMinimumHeight(165);
        cAnak2.addElement(pAnak2);
        tabel11.addCell(cAnak2);

        Paragraph pUmurAnak2 = new Paragraph();
        pUmurAnak2.add("  Umur : ");
        pUmurAnak2.setLeading(0, 1);

        PdfPCell cUmurAnak2 = new PdfPCell();
        cUmurAnak2.setMinimumHeight(165);
        cUmurAnak2.addElement(pUmurAnak2);
        tabel11.addCell(cUmurAnak2);

        Paragraph pPekarjaanAnak2 = new Paragraph();
        pPekarjaanAnak2.add("  Pekerjaan : ");
        pPekarjaanAnak2.setLeading(0, 1);

        PdfPCell cPekerjaanAnak2 = new PdfPCell();
        cPekerjaanAnak2.setMinimumHeight(165);
        cPekerjaanAnak2.addElement(pPekarjaanAnak2);
        tabel11.addCell(cPekerjaanAnak2);

        document.add(tabel11);
        //------------------------------------------------------------------------------------- ANAK2 END

        //------------------------------------------------------------------------------------- CIRI-CIRI
        PdfPTable tabel12 = new PdfPTable(1);
        tabel12.setWidthPercentage(100);

        Paragraph pCiri2 = new Paragraph();
        pCiri2.add("13.  Ciri-ciri badan : ");
        pCiri2.add("\n\n       1. Rambut : " + getRambut());
        for (int i = 0; i < (35 - getRambut().length()); i++) {
            pCiri2.add(" ");
        }
        pCiri2.add("2. Muka : " + getMuka());
        for (int i = 0; i < (35 - getMuka().length()); i++) {
            pCiri2.add(" ");
        }
        pCiri2.add("3. Kulit : " + getKulit());
        pCiri2.setLeading(0, 1);

        PdfPCell cCiri2 = new PdfPCell();
        cCiri2.setMinimumHeight(45);
        cCiri2.addElement(pCiri2);
        tabel12.addCell(cCiri2);

        document.add(tabel12);
        //------------------------------------------------------------------------------------- CIRI-CIRI END

        //------------------------------------------------------------------------------------- LANJUTAN CIRI2
        PdfPTable tabel13 = new PdfPTable(1);
        tabel13.setWidthPercentage(100);

        Paragraph pCiri2Lanjutan = new Paragraph();
        for (int i = 0; i < 20; i++) {
            pCiri2Lanjutan.add(" ");
        }
        pCiri2Lanjutan.add("4.  Tinggi : " + getTinggi());
        for (int i = 0; i < (35 - getTinggi().length()); i++) {
            pCiri2Lanjutan.add(" ");
        }
        pCiri2Lanjutan.add("5.  Tanda Istimewa : " + getTandaistimewa());
        pCiri2Lanjutan.setLeading(0, 1);

        PdfPCell cCiri2Lanjutan = new PdfPCell();
        cCiri2Lanjutan.setMinimumHeight(20);
        cCiri2Lanjutan.addElement(pCiri2Lanjutan);
        tabel13.addCell(cCiri2Lanjutan);

        document.add(tabel13);
        //------------------------------------------------------------------------------------- LANJUTAN CIRI2

        //------------------------------------------------------------------------------------- RUMUS SIDIK JARI
        PdfPTable tabel14 = new PdfPTable(1);
        tabel14.setWidthPercentage(100);

        Paragraph pSidikJari = new Paragraph();
        pSidikJari.add("14.  Rumus Sidik Jari : " + getRumussidikjari());
        pSidikJari.setLeading(0, 1);

        PdfPCell cSidikJari = new PdfPCell();
        cSidikJari.setMinimumHeight(20);
        cSidikJari.addElement(pSidikJari);
        tabel14.addCell(cSidikJari);

        document.add(tabel14);
        //------------------------------------------------------------------------------------- RUMUS SIDIK JARI END

        //------------------------------------------------------------------------------------- RIWAYAT SEKOLAH
        float[] colom = { 8, 2 };
        PdfPTable tabel15 = new PdfPTable(colom);
        tabel15.setWidthPercentage(100);

        Paragraph pRiwayatSekolah = new Paragraph();
        pRiwayatSekolah.add("15.  Riwayat Sekolah : ");
        pRiwayatSekolah.add("\n\n       1. ");
        pRiwayatSekolah.add("\n\n       2. ");
        pRiwayatSekolah.add("\n\n       3. ");
        pRiwayatSekolah.add("\n\n       4. ");
        pRiwayatSekolah.add("\n\n       5. ");
        pRiwayatSekolah.add("\n\n       6. ");
        pRiwayatSekolah.setLeading(0, 1);

        PdfPCell cRiwayatSekolah = new PdfPCell();
        cRiwayatSekolah.setMinimumHeight(165);
        cRiwayatSekolah.addElement(pRiwayatSekolah);
        tabel15.addCell(cRiwayatSekolah);

        Paragraph pTahunLulus = new Paragraph();
        pTahunLulus.add("Tahun Lulus");
        pTahunLulus.setLeading(0, 1);

        PdfPCell cTahunLulus = new PdfPCell();
        cTahunLulus.setMinimumHeight(165);
        cTahunLulus.addElement(pTahunLulus);
        tabel15.addCell(cTahunLulus);

        document.add(tabel15);
        //------------------------------------------------------------------------------------- RIWAYAT SEKOLAH END

        //------------------------------------------------------------------------------------- KESENANGAN/KEGEMARAN/HOBI
        PdfPTable tabel16 = new PdfPTable(1);
        tabel16.setWidthPercentage(100);

        Paragraph pKesenenanganKegemaranHobi = new Paragraph();
        pKesenenanganKegemaranHobi.add("16.  Kesenangan/Kegemaran/Hobi : " + getHobi());
        pKesenenanganKegemaranHobi.setLeading(0, 1);

        PdfPCell cKesenenanganKegemaranHobi = new PdfPCell();
        cKesenenanganKegemaranHobi.setMinimumHeight(20);
        cKesenenanganKegemaranHobi.addElement(pKesenenanganKegemaranHobi);
        tabel16.addCell(cKesenenanganKegemaranHobi);

        document.add(tabel16);
        //------------------------------------------------------------------------------------- KESENANGAN/KEGEMARAN/HOBI END

        //------------------------------------------------------------------------------------- CATATAN KRIMINAL
        PdfPTable tabel17 = new PdfPTable(1);
        tabel17.setWidthPercentage(100);

        Paragraph pCatatanKriminal = new Paragraph();
        pCatatanKriminal.add("17.  Catatan kriminal yang ada : ");
        pCatatanKriminal.add("\n\n       1. " + getCatatankriminal1());
        pCatatanKriminal.add("\n\n       2. " + getCatatankriminal2());
        pCatatanKriminal.add("\n\n       3. " + getCatatankriminal3());
        pCatatanKriminal.setLeading(0, 1);

        PdfPCell cCatatanKriminal = new PdfPCell();
        cCatatanKriminal.setMinimumHeight(95);
        cCatatanKriminal.addElement(pCatatanKriminal);
        tabel17.addCell(cCatatanKriminal);

        document.add(tabel17);
        //------------------------------------------------------------------------------------- CATATAN KRIMINAL END

        //------------------------------------------------------------------------------------- KETERANGAN DLL
        PdfPTable tabel18 = new PdfPTable(1);
        tabel18.setWidthPercentage(100);

        Paragraph pDataKeteranganLain2 = new Paragraph();
        pDataKeteranganLain2.add("18.  Data Keterangan dan lain2 : ");
        pDataKeteranganLain2.add("\n\n\n");
        pDataKeteranganLain2.setLeading(0, 1);

        PdfPCell cDataKeteranganLain2 = new PdfPCell();
        cDataKeteranganLain2.addElement(pDataKeteranganLain2);

        if (list.size() > 0) {
            float[] kolomkegiatan = { 8, 2 };
            PdfPTable nestedTable = new PdfPTable(kolomkegiatan);

            nestedTable.addCell(new Paragraph("Kegiatan"));
            nestedTable.addCell(new Paragraph("Tanggal"));

            for (int i = 0; i < list.size(); i++) {
                nestedTable.addCell(new Paragraph(list.get(i).getNamakegiatan()));
                nestedTable.addCell(new Paragraph(list.get(i).getTanggal()));
            }

            cDataKeteranganLain2.addElement(nestedTable);
            cDataKeteranganLain2.setPaddingBottom(20f);
            tabel18.addCell(cDataKeteranganLain2);
        }

        document.add(tabel18);
        //------------------------------------------------------------------------------------- KETERANGAN DLL END

        document.close();

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return output;
}

From source file:servlet.GenerarPDF.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w  w.j  a v  a 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 {
    response.setContentType("text/html;charset=UTF-8");
    Document document = new Document();

    try {
        ConexionDB sqlite = new ConexionDB();
        java.sql.Connection cn = sqlite.Conectar();
        Statement st = cn.createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM mascotas;");

        response.setContentType("APPLICATION/download");
        response.setHeader("Content-Disposition", "filename=Mascotas.pdf");
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        Image image = Image.getInstance(
                "C:/Users/Cristian/Documents/NetBeansProjects/adopc-mascotas/web/imagenes/logo9.png");
        image.scaleAbsolute(100, 100);
        document.add(image);

        Paragraph preface = new Paragraph("LOVE MY PET");
        preface.setAlignment(Element.ALIGN_CENTER);
        document.add(preface);

        PdfPTable table = new PdfPTable(5); // 3 columns.
        table.setWidthPercentage(100); //Width 100%
        table.setSpacingBefore(10f); //Space before table
        table.setSpacingAfter(10f); //Space after table

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

        PdfPCell cellusuario = new PdfPCell(new Paragraph("usario"));
        cellusuario.setBorderColor(BaseColor.BLUE);
        cellusuario.setPaddingLeft(10);
        cellusuario.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellusuario.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell celltipo = new PdfPCell(new Paragraph("tipo"));
        celltipo.setBorderColor(BaseColor.BLUE);
        celltipo.setPaddingLeft(10);
        celltipo.setHorizontalAlignment(Element.ALIGN_CENTER);
        celltipo.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellnombre = new PdfPCell(new Paragraph("nombre"));
        cellnombre.setBorderColor(BaseColor.BLUE);
        cellnombre.setPaddingLeft(10);
        cellnombre.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellnombre.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell cellraza = new PdfPCell(new Paragraph("raza"));
        cellraza.setBorderColor(BaseColor.BLUE);
        cellraza.setPaddingLeft(10);
        cellraza.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellraza.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPCell celledad = new PdfPCell(new Paragraph("edad"));
        celledad.setBorderColor(BaseColor.BLUE);
        celledad.setPaddingLeft(10);
        celledad.setHorizontalAlignment(Element.ALIGN_CENTER);
        celledad.setVerticalAlignment(Element.ALIGN_MIDDLE);

        table.addCell(cellusuario);
        table.addCell(celltipo);
        table.addCell(cellnombre);
        table.addCell(cellraza);
        table.addCell(celledad);

        while (rs.next()) {

            PdfPCell cell1 = new PdfPCell(new Paragraph(rs.getString(1)));
            cell1.setPaddingLeft(1);
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell1);

            PdfPCell cell2 = new PdfPCell(new Paragraph(rs.getString(2)));
            cell2.setPaddingLeft(2);
            cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell2);

            PdfPCell cell3 = new PdfPCell(new Paragraph(rs.getString(3)));
            cell3.setPaddingLeft(3);
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell3.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell3);

            PdfPCell cell4 = new PdfPCell(new Paragraph(rs.getString(4)));
            cell4.setPaddingLeft(4);
            cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell4.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell4);

            PdfPCell cell5 = new PdfPCell(new Paragraph(rs.getString(5)));
            cell5.setPaddingLeft(5);
            cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell5.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell5);

        }

        document.add(table);
        //Add more content here
        cn.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:servlet.PdfGenerator.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w  w w.j  a  v a2s.c o  m*/
 *
 * @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 {
    Document report = new Document();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(report, baos);

        DBManager manager = (DBManager) getServletContext().getAttribute("dbmanager");
        Group groupToReport = manager.getGroup(Integer.parseInt(request.getParameter("id")));
        LinkedList<User> groupUsers = manager.getUsersForGroupAndVisible(groupToReport.getId());
        Timestamp lastPosted = manager.getLatestPost(groupToReport);
        int numberOfPosts = manager.getGroupPosts(groupToReport).size();
        String context = request.getServletContext().getRealPath("/");
        Iterator<User> groupIterator = groupUsers.iterator();

        report.open();
        // INSERTING DOCUMENT CONTENT AREA
        Font title = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 24);
        Font text = FontFactory.getFont(FontFactory.HELVETICA, 12);
        Paragraph documentHead = new Paragraph(groupToReport.getName(), title);
        Paragraph newLine = new Paragraph(Chunk.NEWLINE);
        Paragraph latestPost = new Paragraph("Latest post inserted on: " + lastPosted, text);
        Paragraph postsNumberToReport = new Paragraph("Number of posts: " + numberOfPosts, text);

        //LAYOUT AND FINAL PARAGRAPH EDITING AREA
        report.add(documentHead);
        report.add(newLine);
        report.add(postsNumberToReport);
        report.add(newLine);
        report.add(latestPost);
        report.add(newLine);
        PdfPTable usersTable = new PdfPTable(5);

        // LOOP FOR SETTING TABLE
        while (groupIterator.hasNext()) {
            User u = groupIterator.next();
            String userName = u.getName();
            PdfPCell avatarCell = new PdfPCell(Image.getInstance(context + u.getAvatar(request)));
            avatarCell.setBorder(0);
            avatarCell.setPaddingBottom(10);
            avatarCell.setColspan(1);
            PdfPCell userNameCell = new PdfPCell(new Phrase(userName));
            userNameCell.setColspan(4);
            userNameCell.setBorder(0);
            userNameCell.setPaddingBottom(10);
            userNameCell.setPaddingLeft(10);
            usersTable.addCell(avatarCell);
            usersTable.addCell(userNameCell);
        }
        usersTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        report.add(usersTable);

        report.close();

        // SETTING SOME RESPONSE HEADER
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        // SETTING THE CONTENT TYPE
        response.setContentType("application/pdf");
        // THE CONTENTLENGHT
        response.setContentLength(baos.size());
        System.out.println("ci sono");
        try (OutputStream os = response.getOutputStream()) {
            baos.writeTo(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:utils.pdf.cv_templates.Template1.java

private void addPersonalInformation(User user) throws DocumentException {

    Paragraph paragraph;// www.  j a  v a 2 s  .  c  om
    PdfPCell cell;
    PdfPTable table;
    table = new PdfPTable(new float[] { 0.5f, 2f });
    table.setWidthPercentage(100);
    table.setSpacingBefore(5);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.name + " " + user.surnames, font1);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.birthDate + "\n", font4);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph("Calle " + user.residenceAddress + " N " + user.residenceNumber + " "
            + user.residenceZipCode + " " + user.residenceCity + "\n", font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.phoneNumber, font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.email, font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    document.add(table);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addProfessionalExperience(List<ProfessionalExperience> experienceList) throws DocumentException {
    Paragraph paragraph;/*from  w  w w . j  av  a  2s  .c  o m*/
    PdfPCell cell;
    PdfPTable table;

    for (int i = 0; i < experienceList.size(); i++) {

        table = new PdfPTable(new float[] { 1f, 0.5f });
        table.setWidthPercentage(100);
        table.setSpacingBefore(5);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        if (i == 0) {
            paragraph = new Paragraph("Experiencia Profesional", font1);
            cell.setBorder(PdfPCell.NO_BORDER);
        } else {
            paragraph = new Paragraph("");
        }
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //Second column
        cell = new PdfPCell();
        cell.setPaddingLeft(10);
        cell.setPaddingTop(0);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph("");
        cell.addElement(paragraph);
        table.addCell(cell);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph(experienceList.get(i).job + "." + " " + experienceList.get(i).company, font2);
        cell.setBorder(PdfPCell.NO_BORDER);

        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //Second column
        cell = new PdfPCell();
        cell.setPaddingLeft(10);
        cell.setPaddingTop(0);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph(experienceList.get(i).startDate + " - " + experienceList.get(i).endDate,
                font3);
        cell.addElement(paragraph);
        table.addCell(cell);

        document.add(table);
    }
}

From source file:utils.pdf.cv_templates.Template1.java

private void addStudies(User user) throws DocumentException {
    Paragraph paragraph;//from  ww w  . j  a  v a2  s.  co  m
    PdfPCell cell;
    PdfPTable table;

    if (!user.studyTitle.equals("")) {
        table = new PdfPTable(new float[] { 1f });
        table.setWidthPercentage(100);
        table.setSpacingBefore(5);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph("Estudios", font1);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph(user.studyTitle + "." + " " + user.studyLocation, font2);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        document.add(table);
    }
}

From source file:utils.pdf.cv_templates.Template1.java

private void addSoftware(List<Software> softwareList) throws DocumentException {
    Paragraph paragraph1;/* w w  w  .j av  a  2 s .  co m*/
    Paragraph paragraph2;
    PdfPCell cell;
    PdfPTable table;
    table = new PdfPTable(new float[] { 1f });
    table.setWidthPercentage(100);
    table.setSpacingBefore(5);

    //First column
    cell = new PdfPCell();
    for (int i = 0; i < softwareList.size(); i++) {
        cell.setBorder(PdfPCell.NO_BORDER);
        if (i == 0) {
            paragraph1 = new Paragraph("Programas informticos:", font1);
            paragraph2 = new Paragraph(
                    softwareList.get(i).software + "." + " Nivel: " + softwareList.get(i).level, font2);
            cell.setBorder(PdfPCell.NO_BORDER);
        } else {
            paragraph1 = new Paragraph("");
            paragraph2 = new Paragraph(
                    softwareList.get(i).software + "." + " Nivel: " + softwareList.get(i).level, font2);
        }
        paragraph1.setAlignment(Paragraph.ALIGN_LEFT);
        paragraph2.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph1);
        cell.addElement(paragraph2);
    }
    table.addCell(cell);
    document.add(table);
}