Example usage for com.itextpdf.text.pdf CMYKColor CMYKColor

List of usage examples for com.itextpdf.text.pdf CMYKColor CMYKColor

Introduction

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

Prototype

public CMYKColor(float floatCyan, float floatMagenta, float floatYellow, float floatBlack) 

Source Link

Document

Construct a CMYK Color.

Usage

From source file:BUS.ExportPDF.java

public boolean ExportPN(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/*  ww  w .ja v  a 2  s  .co m*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "PhieuNhap_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data

        PdfPTable t = new PdfPTable(7);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M phiu nhp", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);
        PdfPCell c6 = new PdfPCell(new Phrase("Nh cung cp", f));
        t.addCell(c6);
        PdfPCell c7 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c7);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
            t.addCell(new Phrase(al.get(i)[4], f));
            t.addCell(al.get(i)[5]);
        }
        document.add(t);
        // ?ng File
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportPX(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {//from  www .  ja v a2s  .c o m
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "PhieuXuat_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data
        PdfPTable t = new PdfPTable(5);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M phiu xut", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
        }
        document.add(t);

        // ?ng File
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportHD(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/*from w  w  w. j a va  2  s . c o m*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "Hoadon_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data
        PdfPTable t = new PdfPTable(6);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M ha n", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Tn khch hng", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);
        PdfPCell c6 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c6);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(new Phrase(al.get(i)[1], f));
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
            t.addCell(al.get(i)[4]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportTKDT(ArrayList<String[]> al, String year)
        throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {//from  ww w.  j  a v  a 2  s.com
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "ThongKeDoanhThu_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Nam can bao cao
        Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC,
                new CMYKColor(0, 255, 255, 17)));
        document.add(title2);

        //Chart
        Image image = Image.getInstance("src\\Library\\barChart3D.jpeg");
        image.scaleToFit(500, 400);
        document.add(new Paragraph());
        document.add(image);

        //Data
        PdfPTable t = new PdfPTable(4);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("Thng", f));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("Doanh thu", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Ti?n n", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Li", f));
        t.addCell(c4);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(al.get(i)[2]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportTKSP(ArrayList<String[]> al, String year)
        throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/*from   w  w w.  jav  a  2  s.c  om*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "ThongKeSanPham_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Nm c bo co
        Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC,
                new CMYKColor(0, 255, 255, 17)));
        document.add(title2);

        //Chart
        Image image = Image.getInstance("src\\Library\\pie_Chart3D.jpeg");
        image.scaleToFit(500, 400);
        document.add(new Paragraph());
        document.add(image);

        //Data
        PdfPTable t = new PdfPTable(5);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M sn phm", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Tn sn phm", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tng s lng", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c5);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(new Phrase(al.get(i)[1], f));
            t.addCell(al.get(i)[2]);
            t.addCell(al.get(i)[3]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:com.vectorprint.report.itext.ItextHelper.java

License:Open Source License

public BaseColor fromColor(Color color) {
    if (settings != null && settings.containsKey(ReportConstants.ICCCOLORPROFILE)) {
        try {//w  w  w  .ja va2 s  .co  m
            loadICC(settings.getURLProperty(null, ReportConstants.ICCCOLORPROFILE).openStream());
        } catch (IOException ex) {
            throw new VectorPrintRuntimeException(ex);
        }
        float[] toCIEXYZ = icc.fromRGB(color.getRGBComponents(null));//color.getColorSpace().toCIEXYZ(color.getComponents(null));
        if (toCIEXYZ.length > 3) {
            return new CMYKColor(toCIEXYZ[0], toCIEXYZ[1], toCIEXYZ[2], toCIEXYZ[3]);
        } else {
            return new CMYKColor(toCIEXYZ[0], toCIEXYZ[1], toCIEXYZ[2], 0);
        }
    } else {
        return new BaseColor(color.getRGB());
    }
}

From source file:org.scantegrity.common.InvisibleInkFactory.java

License:Open Source License

/**
 * Standard constructor that allows user to set font, fontsize, padding,
 * and optionally, a CSPRNG.//from  w w  w.ja  v  a 2s . co  m
 * 
 * @param p_fontName - Name of the font, e.g. "Times New Roman".
 * @param p_fontSize - Font Size
 * @param p_pad - Padding around the font
 * @param p_csprng - A cryptographically secure pseudo-random number 
 *                 generator
 */
public InvisibleInkFactory(String p_fontName, int p_fontSize, int p_pad, SecureRandom p_csprng) {

    c_font = new Font(p_fontName, Font.BOLD, p_fontSize);
    c_fontSize = p_fontSize;
    c_padding = p_pad;
    c_csprng = p_csprng;
    SetTrueAscent(DEFAULT_SYMBOLS);
    c_symbolMap = new TreeMap<Character, boolean[][]>();
    c_defFontColor = new CMYKColor(0, 1, 0, 0);
    c_defBgColor = new CMYKColor(0, 0, 1, 0);
    generateSymbolMap();
}

From source file:org.scantegrity.common.InvisibleInkFactory.java

License:Open Source License

private BufferedImage createImageFromBitMap(boolean[][] p_map) {
    if (p_map == null)
        return null;

    int l_mapWidth = p_map.length;
    int l_mapHeight = p_map[0].length;

    //Use the unit-dimensions to generate an image width/height.
    int l_imgWidth = 0;
    for (int l_i = 0; l_i < l_mapWidth; l_i++) {
        l_imgWidth += c_hGridSize[l_i % c_hGridSize.length];
        if (l_i + 1 != l_mapWidth + 1)
            l_imgWidth += c_hGridSpace[l_i % c_hGridSpace.length];
    }/*from  ww  w.j a v  a  2s.c  o m*/
    int l_imgHeight = 0;
    for (int l_i = 0; l_i < l_mapHeight; l_i++) {
        l_imgHeight += c_vGridSize[l_i % c_vGridSize.length];
        if (l_i + 1 != l_mapHeight)
            l_imgHeight += c_vGridSpace[l_i % c_vGridSpace.length];
    }

    //Create the image, use the map to determine magenta or cyan colors.
    BufferedImage l_ret;
    //Graphics2D l_g2d;
    l_ret = createCMYKImage(Math.round(l_imgWidth), Math.round(l_imgHeight));
    //l_g2d = l_ret.createGraphics();
    //imgx/imgy represent the current x and y offsets for the whole image.
    int l_imgx = 0;
    int l_imgy = 0;
    for (int l_x = 0; l_x < l_mapWidth; l_x++) {
        //Reset imgy to top of image.
        l_imgy = 0;
        for (int l_y = 0; l_y < l_mapHeight; l_y++) {
            float[] l_color = null;
            //The default is the background, we will try to find font colors.
            if (p_map[l_x][l_y]) {
                l_color = getRandomFontColor();
            } else {
                l_color = getRandomBgColor();
            }

            l_color = AddMask(l_color);

            //Draw the box
            int l_width = c_hGridSize[l_x % c_hGridSize.length];
            int l_height = c_vGridSize[l_y % c_vGridSize.length];
            CMYKColor l_c = new CMYKColor(l_color[0], l_color[1], l_color[2], l_color[3]);
            //l_g2d.setColor(l_c);
            //l_g2d.fillRect(l_imgx, l_imgy, l_width, l_height);
            fillRect(l_ret, l_c, l_imgx, l_imgy, l_width, l_height);
            //Update imgy with SIZE
            l_imgy += c_vGridSize[l_y % c_vGridSize.length];
            //Draw Horizontal Line (on the first run of this loop)
            if (l_x == 0 && l_y + 1 != l_mapHeight) {
                //l_g2d.setColor(c_gridColor);
                //l_g2d.fillRect(0, l_imgy, l_imgWidth, c_vGridSpace[l_y%c_vGridSpace.length]);
                fillRect(l_ret, c_gridColor, 0, l_imgy, l_imgWidth, c_vGridSpace[l_y % c_vGridSpace.length]);
            }
            //update imgy with SPACE
            l_imgy += c_vGridSpace[l_y % c_vGridSpace.length];
        }
        //update imgx with SIZE
        l_imgx += c_hGridSize[l_x % c_hGridSize.length];
        //Draw Vertical Line (we are doing the next column)
        if (l_x + 1 != l_mapWidth + 1) {
            //l_g2d.setColor(c_gridColor);
            //l_g2d.fillRect(l_imgx, 0, c_hGridSpace[l_x%c_hGridSpace.length], l_imgHeight);
            fillRect(l_ret, c_gridColor, l_imgx, 0, c_hGridSpace[l_x % c_hGridSpace.length], l_imgHeight);

        }
        //update imgx with SPACE
        l_imgx += c_hGridSpace[l_x % c_hGridSpace.length];
    }

    return l_ret;
}

From source file:project1.GENERALCV.java

private void createcvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createcvActionPerformed
    String firstname, lastname, contactno, email, phonenumber, address;
    String dob, martialStatus, cast, careerObjectives;
    String university, city, startdatee, enddatee, coursesAndQualification;
    String acedemicQualification, certificates, experience, techskills, addSkills;
    String achivements, additionalCertificates, references, hobbies;
    firstname = txtname.getText();//  w w w .  j  a v a  2  s. c o  m
    lastname = txtlastname.getText();

    email = txtemail.getText();
    phonenumber = txtMobileNo.getText();

    address = txtAddress.getText();

    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");

    String link = txtLink.getText();

    // dob= dateFormat.format(dateOfBirth.getDate());
    martialStatus = cmbMartialStatus.getSelectedItem().toString();
    // cast=txtcast.getText();
    //  careerObjectives=txtcareer.getText();

    university = txtCollegeName.getText();
    city = txtCity.getText();
    // startdatee=dateFormat.format(startdate.getDate());
    // enddatee=dateFormat.format(enddate.getDate());
    coursesAndQualification = txtExtraCourses.getText();

    //  certificates=txtcertificats.getText();
    // experience=txtexperience.getText();
    techskills = txttechnical.getText();
    // addSkills=txtadditional.getText();

    references = txtreference.getText();

    try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cvmaker", "root", "12345");

        pInsertPerson = con
                .prepareStatement("INSERT INTO PERSONS(NAMEE,CONTACTNO,EMAILID,ADDRESS) VALUES(?,?,?,?)");

        pInsertPerson.setString(1, firstname + lastname);
        pInsertPerson.setString(2, phonenumber);
        pInsertPerson.setString(3, email);
        pInsertPerson.setString(4, address);
        pInsertPerson.executeUpdate();

        JOptionPane.showMessageDialog(null, "Data Is Alo Saved In Database....");

        showRecords();

    } catch (Exception e) {

        System.out.println(e.toString());

    }

    Statement statement;

    String selectTableSQL = "SELECT ID FROM PERSONS";
    int ss = 0;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cvmaker", "root", "12345");

        statement = con.createStatement();

        //System.out.println(selectTableSQL);
        // execute select SQL stetementS
        ResultSet rs = statement.executeQuery(selectTableSQL);

        while (rs.next()) {

            ss = rs.getInt("ID");
        }
    } catch (SQLException e) {
        System.out.println(e.toString());

    } catch (ClassNotFoundException ex) {
        Logger.getLogger(FRESHERCV.class.getName()).log(Level.SEVERE, null, ex);
    }

    int newcvid = ss;

    try {

        OutputStream file = new FileOutputStream(new File("D:\\PDFFILES\\" + firstname + lastname + ".pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        //     Image im=Image.getInstance("E:\\PDFFILES\\FUUAST.png");
        //   document.add(new Paragraph(""));
        // document.add(im);

        Paragraph title1 = new Paragraph(firstname + " " + lastname + " Cv", FontFactory
                .getFont(FontFactory.HELVETICA, 36, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));

        Chapter chapter1 = new Chapter(title1, 1);

        chapter1.setNumberDepth(0);
        document.add(chapter1);

        document.add(new Paragraph("\n\n"));

        List unorderedList = new List(List.UNORDERED);
        unorderedList.add(new ListItem("Mobile No:" + phonenumber));
        unorderedList.add(new ListItem("Email:" + city));
        unorderedList.add(new ListItem("Address:" + address));
        //    unorderedList.add(new ListItem("End Date:" + enddatee));
        document.add(unorderedList);

        //  document.add(new Paragraph("Address:"+address));
        Paragraph title2 = new Paragraph("Personal Information", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title2.setAlignment(Element.ALIGN_CENTER);

        document.add(title2);
        //   document.add(new Paragraph("Date Of Birth:" + dob));

        document.add(new Paragraph("Martial Status:" + martialStatus));
        //   document.add(new Paragraph("Cast:"+cast));
        //   document.add(new Paragraph("Career Objectives:"+careerObjectives));

        Paragraph title3 = new Paragraph("Qualification", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title3.setAlignment(Element.ALIGN_CENTER);
        document.add(title3);
        PdfPTable table = new PdfPTable(2); // 3 columns.
        document.add(new Paragraph("\n\n"));
        PdfPCell cell1 = new PdfPCell(new Paragraph("Insituite Name:"));
        PdfPCell cell2 = new PdfPCell(new Paragraph(university));

        PdfPCell cell3 = new PdfPCell(new Paragraph("City:"));
        PdfPCell cell4 = new PdfPCell(new Paragraph(city));

        PdfPCell cell5 = new PdfPCell(new Paragraph("Start Date:"));
        // PdfPCell cell6 = new PdfPCell(new Paragraph(startdatee));

        PdfPCell cell7 = new PdfPCell(new Paragraph("End Date:"));
        //PdfPCell cell8 = new PdfPCell(new Paragraph(enddatee));

        PdfPCell cell71 = new PdfPCell(new Paragraph("Extra Courses:"));
        PdfPCell cell81 = new PdfPCell(new Paragraph(coursesAndQualification));
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        table.addCell(cell4);
        table.addCell(cell5);
        //   table.addCell(cell6);
        table.addCell(cell7);
        //   table.addCell(cell8);
        table.addCell(cell71);
        table.addCell(cell81);

        document.add(table);

        //  document.add(new Paragraph("Extra Courses:"+coursesAndQualification));
        //   document.add(new Paragraph("Certificates:"+certificates));
        //
        Paragraph title4 = new Paragraph("Experience", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title4.setAlignment(Element.ALIGN_CENTER);
        document.add(title4);
        //      document.add(new Paragraph(""+experience));

        Paragraph title5 = new Paragraph("Skills", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title5.setAlignment(Element.ALIGN_CENTER);
        document.add(title5);

        document.add(new Paragraph("Technical Skills:" + techskills));
        //    document.add(new Paragraph("Additional Skills:"+addSkills));
        Paragraph title6 = new Paragraph("References", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title6.setAlignment(Element.ALIGN_CENTER);
        document.add(title6);
        document.add(new Paragraph("References:" + references));

        //     Anchor anchor;
        //     anchor = new Anchor(link, FontFactory.getFont(FontFactory.HELVETICA,12, Font.UNDERLINE, new CMYKColor(0, 0,0,255)));
        //    anchor.setReference( link);
        Paragraph paragraph = new Paragraph("Profile Link:");
        //     paragraph.add(anchor);
        document.add(paragraph);
        Paragraph title11 = new Paragraph(
                "                                                 Cv Number:" + newcvid, FontFactory
                        .getFont(FontFactory.HELVETICA, 15, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));

        document.add(new Paragraph("\n\n"));
        document.add(title11);
        try {
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.OPEN)) {
                desktop.open(new File("D:\\PDFFILES\\" + firstname + lastname + ".pdf"));
            } else {
                System.out.println("Open is not supported");
            }
        } catch (IOException exp) {
            exp.printStackTrace();
        }
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:project1.SimplePdf.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:

    int id;//from  w w  w . java  2 s  .co  m
    String name;
    id = Integer.parseInt(txtid.getText());
    name = txtname.getText();

    try {

        OutputStream file = new FileOutputStream(new File("F:\\PDFFILES\\" + id + ".pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        //     Image im=Image.getInstance("E:\\PDFFILES\\FUUAST.png");
        //   document.add(new Paragraph(""));
        // document.add(im);
        Paragraph title1 = new Paragraph(name + id,

                FontFactory.getFont(FontFactory.HELVETICA,

                        36, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));

        Chapter chapter1 = new Chapter(title1, 1);

        chapter1.setNumberDepth(0);
        document.add(chapter1);

        document.add(new Paragraph("\n\n\n\n"));
        document.add(new Paragraph("Name: " + name));
        document.add(new Paragraph("Id: " + id));

        try {
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.OPEN)) {
                desktop.open(new File("D:\\PDFFILES\\" + id + ".pdf"));
            } else {
                System.out.println("Open is not supported");
            }
        } catch (IOException exp) {
            exp.printStackTrace();
        }
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }

}