Example usage for com.itextpdf.text Chunk NEWLINE

List of usage examples for com.itextpdf.text Chunk NEWLINE

Introduction

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

Prototype

Chunk NEWLINE

To view the source code for com.itextpdf.text Chunk NEWLINE.

Click Source Link

Document

This is a Chunk containing a newline.

Usage

From source file:ServletsReportesPDF.ReporteSiembraManual.java

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

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            Statement st3 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            st3 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from siembra_manual where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery("SELECT * from siembra_manual where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE SIEMBRA MANUAL", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(5);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Variedad de Semilla",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad de Bultos",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Bultos",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Total Obreros",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);
                    tabla.addCell(celda5);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_sim"));
                        tabla.addCell(rs2.getString("variedad_semilla_sim"));
                        tabla.addCell(rs2.getString("cantidad_bultos_sim"));
                        tabla.addCell(rs2.getString("precio_bulto_sim"));
                        tabla.addCell(rs2.getString("pago_total_obreros_sim"));

                    }
                    documento.add(tabla);

                    Paragraph par4 = new Paragraph();

                    par4.add(new Phrase(Chunk.NEWLINE));
                    Font fontFooter2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par4.add(new Phrase("", fontFooter2));
                    par4.setAlignment(Element.ALIGN_CENTER);
                    documento.add(par4);

                    PdfPTable tabla2 = new PdfPTable(3);
                    FontFactory.registerDirectories();
                    PdfPCell celda10 = new PdfPCell(new Paragraph("Costo Transporte",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda10.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda20 = new PdfPCell(new Paragraph("Costo Semilla",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda20.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda30 = new PdfPCell(new Paragraph("Valor Total Siembra",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla2.addCell(celda10);
                    tabla2.addCell(celda20);
                    tabla2.addCell(celda30);

                    while (rs3.next()) {
                        tabla2.addCell(rs3.getString("costo_transporte_sim"));
                        tabla2.addCell(rs3.getString("costo_semilla_sim"));
                        tabla2.addCell(rs3.getString("valor_total_sim"));
                    }

                    documento.add(tabla2);

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

                documento.close();

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

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteSiembraMecanizada.java

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

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            Statement st3 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            st3 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from siembra_mecanizada where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery("SELECT * from siembra_mecanizada where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE SIEMBRA MECANIZADA", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(6);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Variedad Semilla",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Costo Semilla",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Costo Secado Semilla",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda5 = new PdfPCell(new Paragraph("Cantidad Bultos",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda6 = new PdfPCell(new Paragraph("Valor Bulto",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);
                    tabla.addCell(celda5);
                    tabla.addCell(celda6);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_smzd"));
                        tabla.addCell(rs2.getString("variedad_semilla_smzd"));
                        tabla.addCell(rs2.getString("costo_semilla_smzd"));
                        tabla.addCell(rs2.getString("secado_semilla_smzd"));
                        tabla.addCell(rs2.getString("cantidad_bultos_smzd"));
                        tabla.addCell(rs2.getString("valor_bulto_smzd"));

                    }
                    documento.add(tabla);

                    Paragraph par4 = new Paragraph();

                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    Font fontFooter2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par4.add(new Phrase("REPORTE MANO DE OBRA SIEMBRA MECANIZADA", fontFooter2));
                    par4.setAlignment(Element.ALIGN_CENTER);
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par4);

                    PdfPTable tabla2 = new PdfPTable(4);
                    FontFactory.registerDirectories();
                    PdfPCell celda10 = new PdfPCell(new Paragraph("Costo Mquina",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda10.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda20 = new PdfPCell(new Paragraph("Cantidad Hectreas",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda20.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda30 = new PdfPCell(new Paragraph("Costo Mano Obra",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda30.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda40 = new PdfPCell(new Paragraph("Valor Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla2.addCell(celda10);
                    tabla2.addCell(celda20);
                    tabla2.addCell(celda30);
                    tabla2.addCell(celda40);

                    while (rs3.next()) {
                        tabla2.addCell(rs3.getString("costo_mq_sembradora_smzd"));
                        tabla2.addCell(rs3.getString("num_hect_sembradas_smzd"));
                        tabla2.addCell(rs3.getString("costo_mano_obra_smzd"));
                        tabla2.addCell(rs3.getString("valor_total_smzd"));
                    }

                    documento.add(tabla2);

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

                documento.close();

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

    } finally {
        out.close();
    }
}

From source file:src.servlets.ManageAdmin.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from  w  w w  .  ja v a 2  s  .  c om
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    Map m = request.getParameterMap();
    if (m.containsKey("GetPDF")) {
        try {
            String Report = getServletContext().getRealPath("") + "admin\\PDF_Report.pdf";

            FileOutputStream file = new FileOutputStream(Report);
            Document document = new Document();
            document.addAuthor("K00140908");
            PdfWriter.getInstance(document, file);
            ///////////////////////ADDING THE FILES TO PDF////////////////////
            //Inserting Image in PDF
            String uploadPath = getServletContext().getRealPath("") + "images\\logo.gif";

            Image img = Image.getInstance(uploadPath);

            img.scaleAbsolute(120f, 60f);// width,height of image in float

            //            Inserting Title in PDF  ORIGINAL
            //            Font fontTitle=new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.WHITE);
            //            Chunk title=new Chunk("PDF GENERATION in Java with iText", fontTitle);
            //            title.setBackground(new BaseColor(255,102,0), 1f, 1f, 1f, 3f);
            //            title.setLineHeight(30f);
            //            title.setUnderline(BaseColor.BLACK,5f,0.5f,2f,0.5f,PdfContentByte.LINE_CAP_ROUND);
            Font fontTitle = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK);
            Chunk title = new Chunk("Lit Realty System Report", fontTitle);
            title.setLineHeight(30f);

            //Inserting Table in PDF
            PdfPTable table = new PdfPTable(3);
            table.setWidthPercentage(100); // Sets the width percentage that the table will occupy in the page
            table.setSpacingAfter(10f);
            table.setSpacingBefore(15f);
            table.setWidths(new float[] { 2f, 2f, 2f }); // Sets relative width of table

            Font fontHeader = new Font(Font.FontFamily.HELVETICA, 15, Font.BOLD, BaseColor.BLUE);
            PdfPCell headercell = new PdfPCell(new Phrase("Property Photo", fontHeader)); // Creates new cell in table
            headercell.setBackgroundColor(new BaseColor(230, 230, 243));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            headercell = new PdfPCell(new Phrase("Property ID", fontHeader));
            headercell.setBackgroundColor(new BaseColor(233, 233, 233));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            headercell = new PdfPCell(new Phrase("Price", fontHeader));
            headercell.setBackgroundColor(new BaseColor(233, 233, 233));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            PdfPCell cell1 = new PdfPCell(img, false);

            table.addCell(cell1);
            table.addCell("134000");
            table.addCell("213445");
            table.addCell("134000");

            //Inserting List
            com.itextpdf.text.List list = new com.itextpdf.text.List(true, 30);
            list.add(new ListItem("Example1"));
            list.add(new ListItem("Example2"));
            list.add(new ListItem("Example3"));

            //Adding elements into PDF Document
            document.open();

            document.add(img);
            document.add(title);

            document.add(Chunk.NEWLINE);
            document.add(table);

            document.newPage();
            document.add(new Chunk("List of Examples").setUnderline(+1f, -5f));
            document.add(list);

            document.newPage();
            document.add(new Chunk("List of Examples").setUnderline(+1f, -5f));
            document.add(list);

            document.newPage();
            document.add(new Chunk("List of Properts By Agent X").setUnderline(+1f, -5f));
            //////////////////////GET Propertys From Entity///////////////
            List<Properties> allPropertiesList = PropertiesDB.getAllProperties();

            PdfPTable propertyTable = new PdfPTable(3);
            PdfPCell propertyHeadingcell1 = new PdfPCell(new Phrase("Photo"));
            PdfPCell propertyHeadingcell2 = new PdfPCell(new Phrase("Property ID"));
            PdfPCell propertyHeadingcell3 = new PdfPCell(new Phrase("Price"));

            propertyHeadingcell1.setBorder(Rectangle.NO_BORDER);
            propertyHeadingcell2.setBorder(Rectangle.NO_BORDER);
            propertyHeadingcell3.setBorder(Rectangle.NO_BORDER);

            propertyTable.addCell(propertyHeadingcell1);
            propertyTable.addCell(propertyHeadingcell2);
            propertyTable.addCell(propertyHeadingcell3);

            document.add(Chunk.NEWLINE);

            String uploadPathforPropertyPhoto = getServletContext().getRealPath("")
                    + "images\\properties\\thumbnails\\";

            Image propertyThumbnail;

            img.scaleAbsolute(120f, 60f);// width,height of image in float

            for (Properties anProperty : allPropertiesList) {
                propertyThumbnail = Image.getInstance(uploadPathforPropertyPhoto + anProperty.getPhoto());
                PdfPCell propertycell1 = new PdfPCell(propertyThumbnail, false);
                propertycell1.setPaddingBottom(20);
                PdfPCell propertycell2 = new PdfPCell(new Phrase(anProperty.getListingNum().toString()));
                PdfPCell propertycell3 = new PdfPCell(new Phrase(anProperty.getPrice().toString()));

                propertycell1.setBorder(Rectangle.NO_BORDER);
                propertycell2.setBorder(Rectangle.NO_BORDER);
                propertycell3.setBorder(Rectangle.NO_BORDER);

                propertyTable.addCell(propertycell1);
                propertyTable.addCell(propertycell2);
                propertyTable.addCell(propertycell3);

            }
            document.add(Chunk.NEWLINE);
            document.add(propertyTable);
            //////////////////////GET Propertys From Entity///////////////

            document.close();
            file.close();

            System.out.println("Pdf created successfully ! :)");

            String filePath = Report;
            File downloadFile = new File(filePath);
            FileInputStream inStream = new FileInputStream(downloadFile);

            // if you want to use a relative path to context root:
            String relativePath = getServletContext().getRealPath("");
            System.out.println("relativePath = " + relativePath);

            // obtains ServletContext
            ServletContext context = getServletContext();

            // gets MIME type of the file
            String mimeType = context.getMimeType(filePath);
            if (mimeType == null) {
                // set to binary type if MIME mapping not found
                mimeType = "application/octet-stream";
            }
            System.out.println("MIME type: " + mimeType);

            // modifies response
            response.setContentType(mimeType);
            response.setContentLength((int) downloadFile.length());

            // forces download
            String headerKey = "Content-Disposition";
            String headerValue = String.format("attachment; filename=\"%s\"", downloadFile.getName());
            response.setHeader(headerKey, headerValue);

            // obtains response's output stream
            OutputStream outStream = response.getOutputStream();

            byte[] buffer = new byte[4096];
            int bytesRead = -1;

            while ((bytesRead = inStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, bytesRead);
            }

            inStream.close();
            outStream.close();
            /////////////////

            processRequest(request, response);
        } catch (DocumentException ex) {
            Logger.getLogger(ManageAdmin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:ui.MainDriver.java

public void printTicket() {

    for (int t = 0; t < currentTicketList.size(); t++) {
        String myCodeText = currentTicketList.get(t).getTicketID() + " %0A "
                + currentTicketList.get(t).getBooking().getBookingID() + " - "
                + currentTicketList.get(t).getSchedule().getRoute().getDestination() + " - "
                + currentTicketList.get(t).getPassengerName() + " - "
                + currentTicketList.get(t).getPassengerContactNo() + " - "
                + currentTicketList.get(t).getSeatNo();
        String filePath = "src/ticket/" + currentTicketList.get(t).getTicketID() + ".png";
        int size = 165;
        String fileType = "png";
        File myFile = new File(filePath);
        try {/*  w  w w. j a  va2  s  .co  m*/
            Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<>();
            hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
            QRCodeWriter qrCodeWriter = new QRCodeWriter();
            BitMatrix byteMatrix = qrCodeWriter.encode(myCodeText, BarcodeFormat.QR_CODE, size, size, hintMap);
            int width = byteMatrix.getWidth();
            BufferedImage image = new BufferedImage(width, width, BufferedImage.TYPE_INT_RGB);
            image.createGraphics();

            Graphics2D graphics = (Graphics2D) image.getGraphics();
            graphics.setColor(Color.WHITE);
            graphics.fillRect(0, 0, width, width);
            graphics.setColor(Color.BLACK);

            for (int i = 0; i < width; i++)
                for (int j = 0; j < width; j++)
                    if (byteMatrix.get(i, j))
                        graphics.fillRect(i, j, 1, 1);

            ImageIO.write(image, fileType, myFile);
        } catch (WriterException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        Document document = new Document();
        try {
            PdfWriter.getInstance(document,
                    new FileOutputStream("src/ticketpdf/" + currentTicketList.get(t).getTicketID() + "DATE"
                            + new SimpleDateFormat("ddMMyyHHmmss").format(new Date()) + ".pdf"));
            document.open();

            Phrase p1 = new Phrase();
            Paragraph para = new Paragraph();
            com.itextpdf.text.Font font = new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.COURIER,
                    32, com.itextpdf.text.Font.BOLDITALIC);
            com.itextpdf.text.Font timesRomanfont = new com.itextpdf.text.Font(
                    com.itextpdf.text.Font.FontFamily.TIMES_ROMAN, 16, com.itextpdf.text.Font.BOLD);
            Chunk cc = new Chunk("#################################################################",
                    timesRomanfont);
            p1.add(cc);
            p1.add(Chunk.NEWLINE);
            p1.add(Chunk.NEWLINE);
            Chunk c = new Chunk("CJH BUS EXPRESS SDN. BHD.", font);
            p1.add(c);
            p1.add(Chunk.NEWLINE);
            p1.add(Chunk.NEWLINE);
            p1.add(cc);
            para.setAlignment(Element.ALIGN_CENTER);
            para.add(p1);
            document.add(para);

            Image image1 = Image.getInstance(filePath);
            document.add(image1);

            Phrase phrase = new Phrase();
            Paragraph paragraph = new Paragraph();

            Chunk c1 = new Chunk("Ticket ID                       : " + currentTicketList.get(t).getTicketID(),
                    timesRomanfont);
            phrase.add(c1);
            phrase.add(Chunk.NEWLINE);

            Chunk c2 = new Chunk(
                    "Booking ID                    : " + currentTicketList.get(t).getBooking().getBookingID(),
                    timesRomanfont);
            phrase.add(c2);
            phrase.add(Chunk.NEWLINE);

            Chunk c3 = new Chunk(
                    "Destination                    : "
                            + currentTicketList.get(t).getSchedule().getRoute().getDestination(),
                    timesRomanfont);
            phrase.add(c3);
            phrase.add(Chunk.NEWLINE);

            Chunk cDate = new Chunk(
                    "Departure Date             : " + currentTicketList.get(t).getSchedule().getDepartureDate(),
                    timesRomanfont);
            phrase.add(cDate);
            phrase.add(Chunk.NEWLINE);

            Chunk cTime = new Chunk(
                    "Departure Time            : " + currentTicketList.get(t).getSchedule().getDepartureTime(),
                    timesRomanfont);
            phrase.add(cTime);
            phrase.add(Chunk.NEWLINE);

            Chunk c4 = new Chunk("Passenger Name            : " + currentTicketList.get(t).getPassengerName(),
                    timesRomanfont);
            phrase.add(c4);
            phrase.add(Chunk.NEWLINE);

            Chunk c5 = new Chunk("Passenger Contact No   : " + currentTicketList.get(t).getPassengerContactNo(),
                    timesRomanfont);
            phrase.add(c5);
            phrase.add(Chunk.NEWLINE);

            Chunk c6 = new Chunk("Seat No                           : " + currentTicketList.get(t).getSeatNo(),
                    timesRomanfont);
            phrase.add(c6);
            phrase.add(Chunk.NEWLINE);

            if (reprintCounter == true) {
                Chunk cR = new Chunk("--- REPRINT ---", timesRomanfont);
                phrase.add(cR);
                phrase.add(Chunk.NEWLINE);
            }

            Chunk c7 = new Chunk("#################################################################",
                    timesRomanfont);
            phrase.add(c7);

            paragraph.add(phrase);
            document.add(paragraph);

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

        //            try {
        //                PdfReader reader = new PdfReader("src/ticketpdf/" + currentTicketList.get(t).getTicketID() + "DATE" + new SimpleDateFormat("ddMMyyHHmmss").format(new Date()) + ".pdf");
        //                int n = reader.getNumberOfPages();
        //                PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("src/ticketpdfWM/" + currentTicketList.get(t).getTicketID() + "WMDATE" + new SimpleDateFormat("ddMMyyHHmmss").format(new Date()) + ".pdf"));
        //                int i = 0;
        //                PdfContentByte under;
        //                Image img = Image.getInstance("src/images/b1.jpg");
        //                img.setAbsolutePosition(200, 400);
        //                while (i < n) {
        //                  i++;
        //                  under = stamp.getUnderContent(i);
        //                  under.addImage(img);
        //                }
        //                stamp.close();
        //            }
        //            catch (Exception de) {
        //                de.printStackTrace();
        //            }
    }
}

From source file:utils.PrintInvoice.java

public void getDocument() {
    try {/*from   w ww .  ja  va2s. c  o m*/
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("SaleBill#" + salebill.getId() + ".pdf"));

        document.open();
        ////////////////////////////////////////////////////////////////////////////////////
        ///////////////////Start Document Here/////////////////////////////////
        PdfContentByte directContent = writer.getDirectContent();
        Paragraph p1 = new Paragraph("SALE BILL");
        p1.setFont(FONT[4]);
        p1.setAlignment(Element.ALIGN_CENTER);

        document.add(p1);
        //show the company details here.
        Phrase company = new Phrase(new Chunk("BIO PHARMA\nAKOT 444101(M.S)", FONT[3]));
        document.add(company);
        document.add(new Phrase(
                "\nLicense No : 20B : AK-88888\n                     21B : AK-88889\n       Mobile : "
                        + SessionClass.getInstance().getMobileNumber(),
                FONT[2]));

        //            Phrase mobNum  = new Phrase("    Mobile : "+SessionClass.getInstance().getMobileNumber() );
        //            mobNum.setFont(FONT[2]);
        //            ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, mobNum, 35, 710, 0);

        System.out.println(dateFormatter.format(salebill.getBillDate()));
        //show the invoice details
        //  String txt = "Bill No. : " + salebill.getId()+"\nBill Date : " + dateFormatter.format(salebill.getBillDate()) +;
        Phrase invoiceDetails = new Phrase("Bill No. : " + salebill.getId());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 693, 0);
        invoiceDetails = new Phrase("Bill Date : " + dateFormatter2.format(salebill.getBillDate()));
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 681, 0);
        invoiceDetails = new Phrase("Mode of Payment : " + salebill.getMode());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 668, 0);

        //show the customer details
        Customer c = salebill.getCustomerId();
        Phrase custDetails = new Phrase("SOLD TO", FONT[3]);
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 693, 0);
        custDetails = new Phrase(c.getCompanyName());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 681, 0);
        custDetails = new Phrase(c.getSiteAddress());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 668, 0);
        custDetails = new Phrase("Licence : " + c.getLicenceNo());
        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 655, 0);

        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        //Item Particulars are shown here
        PdfPTable table = new PdfPTable(7);
        table.setTotalWidth(new float[] { 175, 80, 80, 50, 50, 50, 75 });
        table.setHeaderRows(1);

        //headers
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell("Particulars");
        table.addCell("Batch");
        table.addCell("Expiry");
        table.addCell("MRP");
        table.addCell("Rate");
        table.addCell("Qnty");
        table.addCell("SubTotal");
        table.getDefaultCell().setBackgroundColor(null);
        table.setSpacingAfter(5.0f);

        List<SaleBillPharmaItem> items = salebill.getSaleBillPharmaItemList();
        for (int i = 0; i < items.size(); i++) {
            PdfPCell desc = new PdfPCell(new Phrase(items.get(i).getItemName()));

            table.addCell(desc);

            PdfPCell batch = new PdfPCell(new Phrase(items.get(i).getBatch()));

            table.addCell(batch);

            PdfPCell expiry = null;
            Date tDate = null;
            try {
                tDate = dateFormatter2.parse(items.get(i).getExpDate());
            } catch (ParseException ex) {
                Logger.getLogger(PrintInvoice.class.getName()).log(Level.SEVERE, null, ex);
            }

            expiry = new PdfPCell(new Phrase(dateFormatter.format(tDate)));

            table.addCell(expiry);

            PdfPCell mrp = new PdfPCell(new Phrase(items.get(i).getMrp() + ""));
            //                 //mrp.setBorderColor(BaseColor.WHITE);
            //                 mrp.setBorderColorLeft(BaseColor.BLACK);
            //                 mrp.setBorderColorRight(BaseColor.WHITE);
            table.addCell(mrp);
            PdfPCell rate = new PdfPCell(new Phrase(items.get(i).getItemRate() + ""));
            //                 //rate.setBorderColor(BaseColor.WHITE);
            //                 rate.setBorderColorLeft(BaseColor.BLACK);
            //                 rate.setBorderColorRight(BaseColor.WHITE);
            table.addCell(rate);
            PdfPCell quantity = new PdfPCell(new Phrase(items.get(i).getQnty() + ""));
            //                 //quantity.setBorderColor(BaseColor.WHITE);
            //                 quantity.setBorderColorLeft(BaseColor.BLACK);
            //                 quantity.setBorderColorRight(BaseColor.WHITE);
            table.addCell(quantity);
            PdfPCell subtotal = new PdfPCell(new Phrase(items.get(i).getAmt() + ""));
            //                 //subtotal.setBorderColor(BaseColor.WHITE);
            //                 subtotal.setBorderColorLeft(BaseColor.BLACK);
            //                 subtotal.setBorderColorRight(BaseColor.WHITE);
            table.addCell(subtotal);

        }

        //now show the sub details
        //PdfPCell finalCell = new PdfPCell(new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + "                     Total Amount : Rs "));
        //Todo change code here to show vat amount when there is vat number
        PdfPCell finalCell = new PdfPCell(
                new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + "           Total Amount : Rs "));
        finalCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        finalCell.setColspan(6);
        table.addCell(finalCell);
        table.addCell("" + salebill.getTotalAmt());

        PdfPCell cdCell = new PdfPCell(new Phrase("Cash Discount (2 %) : (-) Rs"));
        cdCell.setColspan(6);
        cdCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cdCell);
        table.addCell("" + salebill.getDiscount());

        PdfPCell finalAmtCell = new PdfPCell(new Phrase("Final Amount : Rs"));
        finalAmtCell.setColspan(6);
        finalAmtCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(finalAmtCell);
        table.addCell("" + salebill.getFinalAmt());

        document.add(table);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        Paragraph sign = new Paragraph(new Chunk("Authorized signatory\n(BIO PHARMA)"));
        sign.setAlignment(Element.ALIGN_RIGHT);
        document.add(sign);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        document.add(Chunk.NEWLINE);

        Paragraph p = new Paragraph("THANK YOU FOR YOUR BUSINESS");
        p.setFont(FONT[4]);
        p.setAlignment(Element.ALIGN_CENTER);
        document.add(p);

        ///////////////////End Documnet here//////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////
        document.close(); // no need to close PDFwriter?

    } catch (DocumentException | FileNotFoundException e) {
        //LOGGER
        e.printStackTrace();
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Printing Error");
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.setScene(new Scene(VBoxBuilder.create()
                .children(new Text(
                        "The file to be printed is already open \n. Please close the file and Print Again"))
                .alignment(Pos.CENTER).padding(new Insets(50)).build()));
        dialogStage.show();
    }

}

From source file:Ventas.GeneradorFormato.java

public static void main(String[] args) {
    try {//from  w w w.j  a v a 2 s .com

        Document document = new Document(PageSize.LETTER, 50, 50, 85, 50);
        document.addAuthor("Ventas");
        document.addTitle("Ventas");

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        writer.setInitialLeading(16);
        Rectangle rct = new Rectangle(80, 104, 500, 688);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

        document.open();
        //            Paragraph parrafo2 = new Paragraph("De aqui en ", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED));
        //            parrafo2.setAlignment(0);
        document.add(Chunk.NEWLINE);
        document.add(new Paragraph("Fecha:"));
        Paragraph id_Venta = new Paragraph("ID_Venta:");
        id_Venta.setAlignment(0);
        document.add(id_Venta);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        //            document.add(parrafo2);
        document.add(new Paragraph("Nombre del cliente:"));
        //            document.add(Chunk.NEWLINE);
        //            document.add(Chunk.NEWLINE);
        document.add(new Paragraph("Apellido Paterno:"));
        //            document.add(Chunk.NEWLINE);
        document.add(new Paragraph("Apellido Materno:"));
        document.add(new Paragraph("Domicilio:"));
        document.add(new Paragraph("Calle:"));
        document.add(new Paragraph("Numero:"));
        document.add(new Paragraph(""));

        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.close();
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:Vista.GenerarPDF.java

private void btngenerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btngenerarActionPerformed
    String nave = "" + cmbtiponave.getSelectedItem();
    String ruta = txtruta.getText();
    try {//from  w  w  w  .  ja va  2 s .co m
        FileOutputStream archivo = new FileOutputStream(ruta + ".pdf");

        Document doc = new Document();
        PdfWriter.getInstance(doc, archivo);
        doc.open();
        Paragraph parrafo2 = new Paragraph("INFORME DE MANTENIMIENTOS");
        parrafo2.setAlignment(1);//el 1 es para centrar
        doc.add(parrafo2);

        doc.add(new Phrase(Chunk.NEWLINE));
        doc.add(new Phrase(Chunk.NEWLINE));

        doc.add(new Paragraph(
                "Acontinuacion se muestra una lista de los mantenimientos realizados a la aeronave " + nave
                        + ""));
        doc.add(new Phrase(Chunk.NEWLINE));
        PdfPTable tabla = new PdfPTable(6);
        tabla.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabla.setTotalWidth(PageSize.A4.getWidth() - 10);
        //el numero indica la cantidad de Columnas

        tabla.addCell("ID");
        tabla.addCell("Matricula");
        tabla.addCell("Estado");
        tabla.addCell("Tareas");
        tabla.addCell("Fecha inicio");
        tabla.addCell("Fecha termino");
        tabla.setWidths(new int[] { 1, 2, 4, 4, 3, 3 });
        Administrar_Mantenimientos av = new Administrar_Mantenimientos();

        ArrayList<Detalle_Mantenimiento> listaMantenimientos = av.listarMantenimientosMatricula(nave);
        for (int i = 0; i < listaMantenimientos.size(); i++) {
            tabla.addCell(String.valueOf(listaMantenimientos.get(i).getId()));
            tabla.addCell(listaMantenimientos.get(i).getMatricula());
            tabla.addCell(listaMantenimientos.get(i).getEstado());
            tabla.addCell(listaMantenimientos.get(i).getTareas_seleccionadas());
            tabla.addCell(listaMantenimientos.get(i).getFecha_inicio());
            tabla.addCell(listaMantenimientos.get(i).getFecha_termino());
        }

        // esto nos crea una tabla de 3 Columnas por 2 Filas
        doc.add(tabla);
        doc.close();
        JOptionPane.showMessageDialog(null, "PDF CREADO CON EXITO");

    } catch (Exception e) {
        System.out.println("error" + e);
    }

}

From source file:windows.wzListWindow.java

private void printDocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printDocActionPerformed
    Document document = new Document();
    Footer ft = new Footer();
    companyAdress comp = new companyAdress();

    try {/*from   w  w  w  .j a v  a 2  s.  c  o  m*/
        BaseFont ft1 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
        Font ffont = new Font(ft1, 12);

        BaseFont ft3 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
        Font bold = new Font(ft1, 12, Font.BOLD);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
        document.open();
        Paragraph pr = new Paragraph();
        pr.setFont(ffont);
        writer.setPageEvent(ft);
        ContractorEntity contractor = wz
                .getContractor(Integer.valueOf(WZTable.getValueAt(WZTable.getSelectedRow(), 2).toString()));
        pr.add(WZTable.getValueAt(WZTable.getSelectedRow(), 4).toString());
        pr.setAlignment(Element.ALIGN_RIGHT);
        document.add(pr);
        pr.clear();
        if ("SPRZT WYDANY".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 11).toString())) {
            Paragraph nr = new Paragraph("WYADNIE SPRZTU NR ", ffont);
            String yearSlashnr = WZTable.getValueAt(WZTable.getSelectedRow(), 1).toString();
            nr.add(new Chunk(yearSlashnr, bold));
            nr.setAlignment(Element.ALIGN_LEFT);
            document.add(nr);
            if ("WS".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 12).toString())) {
                pr.setAlignment(Element.ALIGN_LEFT);
                DocEntity docPS = wz.getDocument(wz.getPSForWs(
                        Integer.valueOf(WZTable.getValueAt(WZTable.getSelectedRow(), 0).toString())));
                pr.add("DOTYCZY: PS NR " + docPS.getDocNumber());
                document.add(pr);
                pr.clear();
                pr.setAlignment(Element.ALIGN_RIGHT);
            }
        }

        if ("SPRZT PRZYJTY".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 11).toString())) {
            int rok = Timestamp.valueOf(WZTable.getValueAt(WZTable.getSelectedRow(), 4).toString()).getYear()
                    + 1900;
            Paragraph nr = new Paragraph("PRZYJCIE SPRZTU NR ", ffont);
            String yearSlashnr = rok + "/" + WZTable.getValueAt(WZTable.getSelectedRow(), 1).toString();
            nr.add(new Chunk(yearSlashnr, bold));
            nr.setAlignment(Element.ALIGN_LEFT);
            document.add(nr);
        }
        pr.clear();
        pr.add(Chunk.NEWLINE);
        pr.add(Chunk.NEWLINE);
        document.add(pr);
        pr.clear();
        pr.setAlignment(Element.ALIGN_LEFT);
        pr.add(comp.getName());
        pr.add(Chunk.NEWLINE);
        pr.add("ul. " + comp.getStreet());
        pr.add(Chunk.NEWLINE);
        pr.add(comp.getPostal() + " " + comp.getCity());
        pr.add(Chunk.NEWLINE);
        pr.add("NIP: " + comp.getNip());
        pr.add(Chunk.NEWLINE);
        pr.add("Tel: " + comp.getPhone());
        pr.add(Chunk.NEWLINE);
        pr.add("Fax: " + comp.getFax());
        pr.add(Chunk.NEWLINE);
        pr.add("E-mail: " + comp.getEmail());
        pr.add(Chunk.NEWLINE);
        pr.add(Chunk.NEWLINE);
        pr.add("KLIENT:");
        pr.add(Chunk.NEWLINE);
        pr.add(contractor.getName());
        pr.add(Chunk.NEWLINE);
        pr.add("ul. " + contractor.getStreet());
        pr.add(Chunk.NEWLINE);
        pr.add(contractor.getPostalCode() + " " + contractor.getCity());
        pr.add(Chunk.NEWLINE);
        pr.add("NIP: " + contractor.getNip());
        pr.add(Chunk.NEWLINE);
        pr.add("Tel: " + contractor.getPhone());
        pr.add(Chunk.NEWLINE);
        pr.add("E-mail: " + contractor.getEmail());
        document.add(pr);

        pr.clear();
        pr.add(Chunk.NEWLINE);
        pr.add(Chunk.NEWLINE);
        pr.add("PRZYJTE URZDZENIA:");
        document.add(pr);

        //PUT IMAGE FROM DRIVE
        java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("C:/GIT/support/logo.jpg");
        Image img = com.itextpdf.text.Image.getInstance(awtImage, null);
        int indentation = 0;
        float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin()
                - indentation) / img.getWidth()) * 20;
        img.scalePercent(scaler);
        img.setAbsolutePosition(document.right() - 90, document.top() - 150);
        document.add(new Paragraph());
        document.add(img);

        //ADD TABLE

        PdfPTable table = new PdfPTable(7); // 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, 4f, 3f, 2f, 2f, 6f, 6f };
        table.setWidths(columnWidths);
        BaseFont ft2 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
        Font headerFont = new Font(ft2, 9);
        Paragraph pos1 = new Paragraph("", headerFont);
        Paragraph pos2 = new Paragraph("", headerFont);
        Paragraph pos3 = new Paragraph("", headerFont);
        Paragraph pos4 = new Paragraph("", headerFont);
        Paragraph pos5 = new Paragraph("", headerFont);
        Paragraph pos6 = new Paragraph("", headerFont);
        Paragraph pos7 = new Paragraph("", headerFont);

        //FORMATING TABLE
        pos1.clear();
        pos1.add("LP");
        PdfPCell cell1 = new PdfPCell(pos1);
        cell1.setBorderColor(BaseColor.BLACK);
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell1);
        pos2.clear();
        pos2.add("NAZWA");
        PdfPCell cell2 = new PdfPCell(pos2);
        cell2.setBorderColor(BaseColor.BLACK);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell2);
        pos3.clear();
        pos3.add("NR SERYJNY");
        PdfPCell cell3 = new PdfPCell(pos3);
        cell3.setBorderColor(BaseColor.BLACK);
        cell3.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell3);
        pos4.clear();
        pos4.add("CENA NETTO");
        PdfPCell cell4 = new PdfPCell(pos4);
        cell4.setBorderColor(BaseColor.BLACK);
        cell4.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell4);
        pos5.clear();
        pos5.add("CENA BRUTTO");
        PdfPCell cell5 = new PdfPCell(pos5);
        cell5.setBorderColor(BaseColor.BLACK);
        cell5.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell5);
        pos6.clear();
        pos6.add("PROBLEM");
        PdfPCell cell6 = new PdfPCell(pos6);
        cell6.setBorderColor(BaseColor.BLACK);
        cell6.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell6);
        pos7.clear();
        pos7.add("NAPRAWA");
        PdfPCell cell7 = new PdfPCell(pos7);
        cell7.setBorderColor(BaseColor.BLACK);
        cell7.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell7.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell7.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell7);

        cell2.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell3.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell5.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell6.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell7.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setBackgroundColor(BaseColor.WHITE);
        cell2.setBackgroundColor(BaseColor.WHITE);
        cell3.setBackgroundColor(BaseColor.WHITE);
        cell4.setBackgroundColor(BaseColor.WHITE);
        cell5.setBackgroundColor(BaseColor.WHITE);
        cell6.setBackgroundColor(BaseColor.WHITE);
        cell7.setBackgroundColor(BaseColor.WHITE);
        int counter = 1;
        for (DocProductEntity prod : productToShow) {
            //col 1 (LP)
            table.addCell(createCell("" + counter, Element.ALIGN_CENTER));
            counter++;
            //col 2 (NAME)
            table.addCell(createCell(prod.getName(), Element.ALIGN_LEFT));
            //col 3 (NR SER)
            table.addCell(createCell(prod.getSerial(), Element.ALIGN_CENTER));
            //col 4 (NETTO)
            table.addCell(createCell(String.valueOf(prod.getPrice()), Element.ALIGN_RIGHT));
            //col 5 (BRUTTO)
            table.addCell(createCell(String.valueOf(prod.getPrice() + (prod.getPrice() * 0.23)),
                    Element.ALIGN_RIGHT));
            //col 6 (PROBLEM)
            table.addCell(createCell(prod.getProblem(), Element.ALIGN_LEFT));
            //col 7 (REPAIRS)
            table.addCell(createCell(prod.getRepair(), Element.ALIGN_LEFT));
        }
        document.add(table);
        pr.setAlignment(Element.ALIGN_RIGHT);
        pr.clear();
        pr.add("PRZEWIDYWANIY KOSZT NAPRAWY:");
        document.add(pr);
        pr.clear();
        pr.add("Razem netto: " + nettoLabel.getText() + " Razem brutto: " + bruttoLabel.getText());
        document.add(pr);
        pr.clear();
        pr.add("Sownie: " + amountInWords(Float.valueOf(bruttoLabel.getText().replace(",", "."))));
        document.add(pr);
        pr.clear();
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        pr.add(".................................................");
        document.add(pr);
        pr.clear();
        pr.add("Podpis i piecztka pracownika");
        document.add(pr);
        if ("SPRZT WYDANY".equals(WZTable.getValueAt(WZTable.getSelectedRow(), 11).toString())) {
            pr.clear();
            pr.add(Chunk.NEWLINE);
            pr.add(Chunk.NEWLINE);
            pr.add(".................................................");
            document.add(pr);
            pr.clear();
            pr.add("Sprzt odebraem (Podpis klienta)");
            document.add(pr);
        }
        //CLOSING DOCUMENT
        document.close();
        writer.close();

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        StampPageXofY numeration = new StampPageXofY();
        tempName = nowTimestamp();
        numeration.manipulatePdf("test.pdf", tempName + ".pdf");
    } catch (IOException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }
    //OPEN READY DOCUMENT
    try {
        Desktop.getDesktop().open(new File(tempName + ".pdf"));
    } catch (IOException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }
}