Example usage for com.itextpdf.text Rectangle Rectangle

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

Introduction

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

Prototype

public Rectangle(final float urx, final float ury) 

Source Link

Document

Constructs a Rectangle -object starting from the origin (0, 0).

Usage

From source file:Evento.action.ZapisDoPdfAction.java

License:Apache License

public void createPDF(String[] imgURL, String place, String album) throws DocumentException {
    Document document = new Document();
    Rectangle pageSize = new Rectangle(szerokosc, wysokosc);
    document.setPageSize(pageSize);// ww w. j  a  va2 s .co  m

    try {

        PdfWriter.getInstance(document, new FileOutputStream(new File(place, "nowy.pdf")));
        document.open();

        Image tlo = Image.getInstance(new URL(zdjecieTla));
        tlo.setAbsolutePosition(0f, 0f);
        document.add(tlo);
        Paragraph preface = new Paragraph(album,
                new Font(FontFamily.HELVETICA, 72, Font.BOLDITALIC, new BaseColor(255, 255, 255)));
        preface.setAlignment(Element.ALIGN_CENTER);
        document.add(preface);
        document.newPage();
        for (int i = 0; i < imgURL.length; i++) {

            Image tlo2 = Image.getInstance(new URL(zdjecieTla));
            tlo2.setAbsolutePosition(0f, 0f);
            document.add(tlo2);
            Image image2 = Image.getInstance(new URL(imgURL[i]));
            if (szerokosc * 1.5f <= image2.getWidth() || wysokosc * 1.5f <= image2.getHeight()) {
                image2.scaleAbsolute(image2.getWidth() * 0.25f, image2.getHeight() * 0.25f);
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 0.25f) / 2,
                        wysokosc / 2 - (image2.getHeight() * 0.25f) / 2);
            } else if ((szerokosc * 0.8f <= image2.getWidth() || wysokosc * 0.8f <= image2.getHeight())
                    && (szerokosc * 1.2f >= image2.getWidth() || wysokosc * 1.2f >= image2.getHeight())) {
                image2.scaleAbsolute(image2.getWidth() * 0.8f, image2.getHeight() * 0.8f);
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 0.8f) / 2,
                        wysokosc / 2 - (image2.getHeight() * 0.8f) / 2);
            } else if ((szerokosc * 0.4f >= image2.getWidth() || wysokosc * 0.4f >= image2.getHeight())
                    && (szerokosc * 0.7f <= image2.getWidth() || wysokosc * 0.7f <= image2.getHeight())) {
                image2.scaleAbsolute(image2.getWidth() * 1.4f, image2.getHeight() * 1.4f);
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth() * 1.4f) / 2,
                        wysokosc / 2 - (image2.getHeight() * 1.4f) / 2);
            } else {
                image2.scaleAbsolute(image2.getWidth(), image2.getHeight());
                image2.setAbsolutePosition(szerokosc / 2f - (image2.getWidth()) / 2,
                        wysokosc / 2 - (image2.getHeight()) / 2);
            }
            for (int k = 0; k <= 1000; k++)
                ;
            for (int j = 0; j <= 1000; j++)
                ;
            document.add(image2);
            document.newPage();
        }

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

From source file:facturacion.pdf.FacturaPdf.java

private Document getDocument() {
    Document document = new Document(new Rectangle(getConvertCmsToPoints(26), getConvertCmsToPoints(30)));
    document.setMargins(0, 0, 80, 1);/*from  ww  w.j a v a2  s.c  o  m*/
    return document;
}

From source file:Forms.AddCustomers.java

private void cardBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cardBtnActionPerformed
    String name = fNameTxt.getText() + " " + lNameTxt.getText();
    String cid = cusIdTxt.getText();
    Document document = new Document();
    Rectangle test = new Rectangle(350, 200);
    BaseColor color = new BaseColor(63, 72, 204);
    test.setBackgroundColor(color);//w  w w.j  a va 2s . c o  m
    document.setPageSize(test);

    File theDir = new File("E:\\CustomerCard");

    // if the directory does not exist, create it
    if (!theDir.exists()) {
        //System.out.println("creating directory: " + directoryName);
        boolean result = false;

        try {
            theDir.mkdir();
            result = true;
        } catch (SecurityException se) {
            System.out.println(se.getMessage());
        }
    }

    try {
        PdfWriter.getInstance(document, new FileOutputStream("E:\\CustomerCard\\card(" + cid + ").pdf"));

        document.open();
        //Image image;

        //image = Image.getInstance("api.png");

        //document.add(image);

        document.add(new Paragraph("           Customer Discount Card",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD, BaseColor.GRAY)));
        document.add(new Paragraph("     "));
        document.add(new Paragraph("              Name : " + name,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK)));
        document.add(new Paragraph("     "));
        document.add(new Paragraph("              Card ID: " + cid,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK)));
        document.close();

        try {
            //Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+"E:\\CustomerCard\\card("+cid+").pdf");
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "
                    + "C:\\Users\\Vidu\\Desktop\\CustomerIDCard\\card(" + cid + ").pdf");
        } catch (Exception ex) {
            Logger.getLogger(SellPage.class.getName()).log(Level.SEVERE, null, ex);
        }
        //document.add(new Paragraph(date,FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL,BaseColor.BLACK)));
        fNameTxt.setText("");
        lNameTxt.setText("");
        cusIdTxt.setText("");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Forms.SellPage.java

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed

    CashType c = new CashType();
    c.setVisible(true);/*from   w  ww.  java  2s .  co m*/

    c.jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            String receive = c.jTextField1.getText();
            if (receive.equalsIgnoreCase("")) {
                JOptionPane.showMessageDialog(null, "Enter Amount");
            } else if (!receive.matches("[0-9]+")) {
                JOptionPane.showMessageDialog(null, "Enter Valid Amount");
                c.jTextField1.setText("");
            } else {
                float rec = Float.parseFloat(receive);
                //create sell
                String b = "sellno" + jTextField3.getText();

                if (CreatingSell(b)) {
                    System.out.println("Success is final");
                }

                ///code for updatng solddtime

                if (new SoldTimeUpdater().getToday(b)) {
                    System.out.println("soldtime updated");
                }

                ////code for updating sold

                String sq = "SELECT * FROM " + b;

                try {

                    Connection con = (Connection) DriverManager
                            .getConnection("jdbc:mysql://localhost:3306/nafis", "root", "");
                    Statement s = (Statement) con.prepareStatement(sq);

                    ResultSet rs = s.executeQuery(sq);

                    while (rs.next()) {
                        String name = rs.getString(2);
                        String price = rs.getString(4);
                        String buy_price = rs.getString(7);
                        String type = rs.getString(8);
                        String qua = rs.getString(3);

                        if (new SellTable().SearchExistItem(name, price + "", "sold")) {

                            new SellTable().updateItem("sold", name, Float.parseFloat(price), qua);

                        }

                        else if (new SellTable().addItem("sold", name, Float.parseFloat(price), " 2%",
                                Float.parseFloat(buy_price), type, qua)) {

                        } else {
                            JOptionPane.showMessageDialog(null, "problem");
                        }
                    }

                } catch (Exception e) {

                }

                //code for invoice

                float a = 0;

                int length;
                String sql = "SELECT * FROM " + b;

                File theDir = new File("E:\\Recept");

                // if the directory does not exist, create it
                if (!theDir.exists()) {
                    //System.out.println("creating directory: " + directoryName);
                    boolean result = false;

                    try {
                        theDir.mkdir();
                        result = true;
                    } catch (SecurityException se) {
                        //handle it
                    }
                }

                try {

                    Connection con = (Connection) DriverManager
                            .getConnection("jdbc:mysql://localhost:3306/nafis", "root", "");
                    Statement s = (Statement) con.prepareStatement(sql);

                    ResultSet rs = s.executeQuery(sql);

                    Document document = new Document();

                    Rectangle test = new Rectangle(223, 380);
                    document.setPageSize(test);
                    PdfWriter.getInstance(document, new FileOutputStream("E:\\Recept\\" + b + ".pdf"));
                    document.open();
                    document.addCreationDate();
                    document.add(new Paragraph("                        INVOICE",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    //document.add(new Paragraph("--------------------------------------------------------",FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL,BaseColor.BLACK)));
                    document.add(new Paragraph("          " + new Date().toString(),
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("                      INVOICE NO:" + jTextField3.getText(),
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("Product                 Qty          Price         Total",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.UNDERLINE, BaseColor.BLACK)));
                    //document.add(new Paragraph("--------------------------------------------------------",FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL,BaseColor.BLACK)));

                    while (rs.next()) {
                        String name = rs.getString(2);
                        String qua = rs.getString(3);
                        String rate = rs.getString(4);
                        String amount = rs.getString(6);
                        a = a + Float.parseFloat(amount);
                        if (name.length() <= 25) {
                            length = name.length();
                        } else {
                            length = 25;
                        }
                        document.add(new Paragraph(name.substring(0, length),
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                        document.add(new Paragraph(
                                "                               " + qua + "             " + rate
                                        + "            " + amount + "",
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                        //document.add(new Paragraph("                                        ",FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL,BaseColor.BLACK)));
                        //t.addCell(rate);
                        //t.addCell(amount);

                    }

                    //document.add(new Paragraph("                                   "));
                    //document.add(new Paragraph("                                   "));
                    document.add(new Paragraph("--------------------------------------------------------",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph(
                            "                                                Total=" + a + "tk",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));

                    //document.add(new Paragraph("                                   "));
                    //document.add(new Paragraph("                                   "));
                    if (jTextField6.getText().equalsIgnoreCase("") == false) {
                        float dis = Float.parseFloat(jTextField6.getText());
                        a = a - ((a * dis) / 100);

                        document.add(new Paragraph(
                                "Customer ID =" + jTextField4.getText() + "  After Discount=" + a + "tk",
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    }
                    if (jTextField8.getText().equalsIgnoreCase("") == false) {
                        float dis = Float.parseFloat(jTextField8.getText());
                        a = a - ((a * dis) / 100);

                        document.add(new Paragraph(
                                "Discount =" + jTextField8.getText() + "%    After Discount=" + a + "tk",
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    }

                    if (jTextField7.getText().equalsIgnoreCase("") == false) {
                        float vat = Float.parseFloat(jTextField7.getText());
                        float v = (a * vat) / 100;
                        a = a + ((a * vat) / 100);

                        document.add(new Paragraph(
                                "Vat =" + jTextField7.getText() + "%               Vat=" + v + "tk",
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));

                    }
                    document.add(new Paragraph("                                     Net Amount=" + a + "tk",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("                              Receive Amount=" + rec + "tk",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph(
                            "                             Returned Amount=" + (rec - a) + "tk     ",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));

                    document.add(new Paragraph("         Goods Once Sold Can not be Return",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("--------------------------------------------------------",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("             Unity Point Of Sales System",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));

                    document.close();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, "problem in memoo");
                }

                ///////////////////////////
                //to open pdf invoice
                try {

                    Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler " + "E:\\Recept\\" + b + ".pdf");
                } catch (IOException ex) {
                    Logger.getLogger(SellPage.class.getName()).log(Level.SEVERE, null, ex);
                }

                ////update todaySell

                Date dNow = new Date();

                SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");

                String date = "" + ft.format(dNow);

                if (new updatingTodaySell().checkdate(date)) {

                    System.out.println("updating");
                    String read = "SELECT * FROM " + b;

                    try {

                        Connection con = (Connection) DriverManager
                                .getConnection("jdbc:mysql://localhost:3306/nafis", "root", "");

                        Statement s = (Statement) con.prepareStatement(read);

                        ResultSet rs = s.executeQuery(read);

                        while (rs.next()) {

                            String name = rs.getString(2);
                            String price = rs.getString(4);
                            String buy_price = rs.getString(7);
                            String type = rs.getString(8);
                            String qua = rs.getString(3);

                            if (new updatingTodaySell().searchtodaysell(name, buy_price)) {

                                System.out.println(qua);
                                new updatingTodaySell().update(name, qua, buy_price, date);
                                System.out.println("update done");
                            } else {

                                new updatingTodaySell().add(name, qua, price, buy_price, type, date);

                            }

                        }

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

                } else {

                    String sqldrop = "DELETE FROM `todaysell` WHERE 1";

                    try {

                        Connection con = (Connection) DriverManager
                                .getConnection("jdbc:mysql://localhost:3306/nafis", "root", "");

                        Statement s = (Statement) con.prepareStatement(sqldrop);

                        s.execute(sqldrop);

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

                    String adddate = "INSERT INTO `todaysell`(`no`, `name`, `quantity`, `price`, `buyprice`, `type`, `date`) VALUES (NULL,'a','0','0','0','NULL','"
                            + date + "')";

                    try {

                        Connection con = (Connection) DriverManager
                                .getConnection("jdbc:mysql://localhost:3306/nafis", "root", "");

                        Statement s = (Statement) con.prepareStatement(adddate);

                        s.execute(adddate);

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

                    String read = "SELECT * FROM " + b;

                    try {

                        Connection con = (Connection) DriverManager
                                .getConnection("jdbc:mysql://localhost:3306/nafis", "root", "");

                        Statement s = (Statement) con.prepareStatement(read);

                        ResultSet rs = s.executeQuery(read);

                        while (rs.next()) {

                            String name = rs.getString(2);
                            String price = rs.getString(4);
                            String buy_price = rs.getString(7);
                            String type = rs.getString(8);
                            String qua = rs.getString(3);

                            new updatingTodaySell().add(name, qua, price, buy_price, type, date);
                        }

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

                }

                //droping previous sell
                int num = Integer.parseInt(jTextField3.getText());
                String ab = "sellno" + num;

                String sql1 = "SELECT * FROM information_schema.tables WHERE table_schema = 'nafis' AND table_name = '"
                        + ab + "' LIMIT 1";

                try {
                    Connection con = (Connection) DriverManager
                            .getConnection("jdbc:mysql://localhost:3306/nafis", "root", "");

                    Statement s = (Statement) con.prepareStatement(sql1);

                    ResultSet rs = s.executeQuery(sql1);

                    if (rs.next()) {
                        if (new SellTable().dropTable(ab)) {

                            System.out.println("droped table " + ab);
                        } else {
                            JOptionPane.showMessageDialog(null, "problem cancelling");
                        }

                    }

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

                //To update the number of sellno in db

                new SellTable().updateSellNumber();
                sellno = new SellTable().getSellNumber();
                //To show sellno in frame
                jTextField3.setText(sellno + 1 + "");

                new SellTable().createtable("sellno" + jTextField3.getText());
                retreve();

                retreve("sellno" + jTextField3.getText());

                //

                ///clear discount
                jLabel12.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
                jTextField2.setText("");

                c.dispose();

            }

        }

        private void matches(String string) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

    });

}

From source file:fxml.test.PDFService.java

public void generatePdf() {
    //   Document document = new Document(PageSize.A4.rotate());
    Document document = new Document(new Rectangle(1008, 612));

    try {/*from w w  w  . j  a  va  2s . c o  m*/
        PdfWriter.getInstance(document, new FileOutputStream("table.pdf"));

        document.setMargins(90, 80, 35, 40);
        document.open();

        if (!list.isEmpty()) {

            list.add("Total Credit");
            list.add("Total GPA");
            list.add("Letter Grade");
            list.add("Cumulative");
            list.add("Remarks");
            list.add("GC");

            if (inputs.get(1).contains("8th")) {

                list.add("PC. No");
                list.add("OC. No");
                list.add("D/AF. No");
                list.add("Others");
            }

            int totalCoureseSize = list.size();
            int totalCourseLoop = totalCoureseSize / 12;
            int courseLoopVariable = 0;

            if (totalCoureseSize % 12 > 0) {
                totalCourseLoop += 1;
            }

            int totalStudentSize = studentList.size();
            int totalStudentLoop = (totalStudentSize / 15);
            int studentLoopVariable = 0;

            if (totalStudentSize % 15 > 0) {
                totalStudentLoop += 1;
            }

            if (totalStudentLoop > 0) {

                for (studentLoopVariable = 0; studentLoopVariable < totalStudentLoop; studentLoopVariable++) {

                    //start print the courses when it is multiple of 12
                    if (totalCourseLoop > 0) {

                        for (courseLoopVariable = 0; courseLoopVariable < totalCourseLoop; courseLoopVariable++) {

                            int courseStart = courseLoopVariable * 12;
                            int studentStart = studentLoopVariable * 15;

                            //start document header
                            document.add(createDocumentHeader());
                            //end document header

                            //start table header
                            PdfPTable table = createTableHeader(courseStart);
                            //end table header

                            //start table body
                            table = createTableBody(studentStart, courseStart, table);
                            //end table body

                            //adding table and footer
                            table.setSpacingAfter(27);
                            document.add(table);
                            document.add(createFooter1());
                            document.add(createFooter2());
                            //end adding table and footer
                            //go to new page..
                            document.newPage();
                        }
                    }
                }
            }
        }

        document.close();

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        AlertMessage.showAlertMessage(Alert.AlertType.ERROR, "Error creating Pdf document.Please try again");
        e.printStackTrace();
    }
}

From source file:GeMSE.Popups.PopupMenuType.java

License:Open Source License

private void SaveAsPDF(java.awt.event.ActionEvent e, File file) {
    Document document = new Document(new Rectangle(_component.getSize().width, _component.getSize().height));
    try {// w  ww.j a va2 s .c om
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();
        PdfTemplate template = contentByte.createTemplate(_component.getSize().width,
                _component.getSize().height);
        Graphics graphics = new PdfGraphics2D(template, _component.getSize().width,
                _component.getSize().height);
        _component.print(graphics);
        graphics.dispose();
        contentByte.addTemplate(template, 0, 0);
    } catch (DocumentException | FileNotFoundException e2) {
    } finally {
        if (document.isOpen())
            document.close();
    }
}

From source file:GeMSE.Visualization.Graph.GraphVis.java

License:Open Source License

private void SaveAsPDF(File file) {
    Document document = new Document(new Rectangle(graphPanel.getSize().width, graphPanel.getSize().height));
    try {/*  w w w  . ja v  a 2s .c om*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();
        PdfTemplate template = contentByte.createTemplate(graphPanel.getSize().width,
                graphPanel.getSize().height);
        Graphics graphics = new PdfGraphics2D(template, graphPanel.getSize().width,
                graphPanel.getSize().height);
        graphPanel.print(graphics);
        graphics.dispose();
        contentByte.addTemplate(template, 0, 0);
    } catch (DocumentException | FileNotFoundException e2) {
    } finally {
        if (document.isOpen())
            document.close();
    }
}

From source file:gravabncertificado007.CarimboCertificado.java

public void aplicaCarimboBin(String BN, String caminhoarquivo)
        throws DocumentException, IOException, RuntimeException {

    PdfReader.unethicalreading = true;//from w  w  w.  j  av a 2 s  . co  m
    //Cria o reader para o primeiro PDF

    PdfReader reader = new PdfReader(caminhoarquivo);
    Rectangle psize = reader.getPageSize(1);
    float width = psize.getWidth();
    float height = psize.getHeight();

    Document document = new Document(new Rectangle(width, height));

    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf"));

    document.open();

    int i = 0;
    BN = BN.substring(BN.length() - 13, BN.length() - 4);
    PdfContentByte cb = writer.getDirectContent();
    while (i < reader.getNumberOfPages()) {
        i++;

        document.newPage();

        PdfContentByte under = writer.getDirectContentUnder();
        PdfImportedPage page1 = writer.getImportedPage(reader, i);
        cb.addTemplate(page1, 0, i * 0.2f);

        //CARIMBO DA BN
        BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 14);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 32, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 22, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 12, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0);
        cb.endText();

    }

    document.close();
    writer.close();
    reader.close();

}

From source file:gravabncertificado007.CarimboCertificado.java

public void aplicaCariboGedi(String BN, String caminhoarquivo)
        throws DocumentException, IOException, RuntimeException {

    PdfReader.unethicalreading = true;/* w  w  w .  ja  v  a  2s  .c  o  m*/
    //Cria o reader para o primeiro PDF

    PdfReader reader = new PdfReader(caminhoarquivo);
    Rectangle psize = reader.getPageSize(1);
    float width = psize.getWidth();
    float height = psize.getHeight();

    Document document = new Document(new Rectangle(width, height));

    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-G.pdf"));

    document.open();

    int i = 0;
    BN = BN.substring(BN.length() - 13, BN.length() - 4);
    PdfContentByte cb = writer.getDirectContent();
    while (i < reader.getNumberOfPages()) {
        i++;

        document.newPage();

        PdfContentByte under = writer.getDirectContentUnder();
        PdfImportedPage page1 = writer.getImportedPage(reader, i);
        cb.addTemplate(page1, 0, i * 0.2f);

        BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 14);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "  _________________  ", width / 6, 44, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 32, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 22, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |Copia Controlada |", width / 6, 28, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 16, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 12, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |_________________|", width / 6, 14, 0);
        cb.endText();
    }

    document.close();
    writer.close();
    reader.close();

}

From source file:groove.io.external.util.GraphToPDF.java

License:Apache License

@Override
public void renderGraph(JGraph<?> graph, File file) throws PortException {
    // Get graph bounds. If not available, do nothing (probably empty graph)
    Rectangle2D bounds = graph.getGraphBounds();
    if (bounds == null) {
        return;/*from  w  w w.j  av  a  2 s . c  om*/
    }
    Rectangle bound = new Rectangle((float) bounds.getWidth(), (float) bounds.getHeight());

    try (FileOutputStream fos = new FileOutputStream(file)) {
        Document document = new Document(bound);
        // Open file, create PDF document
        PdfWriter writer = PdfWriter.getInstance(document, fos);
        // Set some metadata
        document.addCreator(Version.getAbout());

        // Open document, get graphics
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        boolean onlyShapes = true;
        //The embedded fonts most likely do not contain all necessary glyphs, so using outlines instead
        // onlyShapes makes PDF considerably bigger, but no alternative at the moment
        PdfGraphics2D pdf2d = new PdfGraphics2D(cb, (float) bounds.getWidth(), (float) bounds.getHeight(),
                new DefaultFontMapper(), onlyShapes, false, (float) 100.0);

        // Render
        toGraphics(graph, pdf2d);

        // Cleanup
        pdf2d.dispose();
        document.close();
    } catch (DocumentException | IOException e) {
        throw new PortException(e);
    }
}