Example usage for com.itextpdf.text PageSize A4

List of usage examples for com.itextpdf.text PageSize A4

Introduction

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

Prototype

Rectangle A4

To view the source code for com.itextpdf.text PageSize A4.

Click Source Link

Document

This is the a4 format

Usage

From source file:Servlets.ReportsServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w ww  .java  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 {
    try {

        Paragraph pp;
        Paragraph palaglapgh, signParagraph, dateParagrapgh;
        Chunk chk;
        Paragraph underText;
        Chunk chuk1;
        Chunk chuk2;
        Paragraph regionText;
        String x;
        ResultSet dir;
        Paragraph regionTexts;
        String repLot;
        repLot = request.getParameter("report");

        String repNum = request.getParameter("ITLot");
        Paragraph newDate;
        response.setContentType("application/pdf");
        OutputStream out = response.getOutputStream();

        //Create document for pdf
        Document doc = new Document();

        //PDF writer to write into document
        PdfWriter docwriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        switch (repLot) {
        default:

            break;
        case "IT Report":

            //Copied code start from here
            try {
                // //file path
                //String path = "docs/" + "Name";
                docwriter = PdfWriter.getInstance(doc, out);
            } catch (DocumentException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            //document header attributes
            doc.addAuthor("CHED CU");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Grant Monitor");
            doc.addTitle(repLot);
            doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape
            //doc.setPageSize(PageSize.A4);
            doc.setMargins(20f, 20f, 10f, 10f);

            //open document
            doc.open();

            //Creating a paragraphs and chunks
            pp = new Paragraph("Cocoa Health And Extension Division", forTitle);
            pp.setAlignment(Element.ALIGN_CENTER);

            palaglapgh = new Paragraph("(Cocobod)", bfBold12);
            palaglapgh.setAlignment(Element.ALIGN_CENTER);

            signParagraph = new Paragraph("Sign: ..............", bfBold12);
            signParagraph.setAlignment(Element.ALIGN_LEFT);

            dateParagrapgh = new Paragraph("Date: ...........", bfBold12);

            chk = new Chunk("From GIS Office, Accra", bfBold12);
            chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            underText = new Paragraph(chk);
            underText.setAlignment(Element.ALIGN_CENTER);

            chuk1 = new Chunk("Lot No:", forTitle2);
            chuk1.setUnderline(.1f, -2f);
            chuk2 = new Chunk(repNum.toUpperCase(), forTitle2);

            regionText = new Paragraph(repLot, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            x = "";
            dir = manager.PDFdemos(repNum);
            try {
                if (dir.next()) {
                    x = dir.getString(12);

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

            regionTexts = new Paragraph(x, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            //add the PDF table to the paragraph
            //palaglapgh.add(table);
            //Table Generation block
            regionText.add(reports(repNum, repLot, .25f));

            //SECTION TO ADD ELEMENTS TO PDF
            // add the paragraph to the document
            doc.add(pp);
            //doc.add(Chunk.NEWLINE);       //Adds a new blank line
            doc.add(palaglapgh);
            doc.add(underText);

            doc.add(chuk1);
            doc.add(chuk2);

            //Current Date and time insertion
            newDate = new Paragraph(date, bf12);
            newDate.setAlignment(Element.ALIGN_RIGHT);
            doc.add(newDate);
            doc.add(regionTexts);
            doc.add(regionText);

            doc.add(Chunk.NEWLINE); //Adds a new blank line
            doc.add(Chunk.NEWLINE);

            doc.add(signParagraph);
            doc.add(dateParagrapgh);

            //close the document
            doc.close();

            //close the writer
            docwriter.close();

            out.close();

            break;

        case "TR Report":

            //Copied code start from here
            try {
                // //file path
                //String path = "docs/" + "Name";
                docwriter = PdfWriter.getInstance(doc, out);
            } catch (DocumentException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            //document header attributes
            doc.addAuthor("CHED CU");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Grant Monitor");
            doc.addTitle(repLot);
            //doc.setPageSize(PageSize.A4.rotate());      //This sets page size to A4 and orientation to Landscape
            doc.setPageSize(PageSize.A4);
            doc.setMargins(30f, 30f, 20f, 20f);

            //open document
            doc.open();

            //Creating a paragraphs and chunks
            pp = new Paragraph("Cocoa Health And Extension Division", forTitle);
            pp.setAlignment(Element.ALIGN_CENTER);

            palaglapgh = new Paragraph("(Cocobod)", bfBold12);
            palaglapgh.setAlignment(Element.ALIGN_CENTER);

            signParagraph = new Paragraph("Sign: ..............", bfBold12);
            signParagraph.setAlignment(Element.ALIGN_LEFT);

            dateParagrapgh = new Paragraph("Date: ...........", bfBold12);

            chk = new Chunk("From GIS Office, Accra", bfBold12);
            chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            underText = new Paragraph(chk);
            underText.setAlignment(Element.ALIGN_CENTER);

            chuk1 = new Chunk("Lot No:", forTitle2);
            chuk1.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            chuk2 = new Chunk(repNum.toUpperCase(), forTitle2);

            regionText = new Paragraph(repLot, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);

            x = "";
            dir = manager.PDFdemos(repNum);
            try {
                if (dir.next()) {
                    x = dir.getString(12);

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

            regionTexts = new Paragraph(x, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            //add the PDF table to the paragraph
            //palaglapgh.add(table);
            //Table Generation block
            regionText.add(reports(repNum, repLot, .1f));

            //SECTION TO ADD ELEMENTS TO PDF
            // add the paragraph to the document
            doc.add(pp);
            //doc.add(Chunk.NEWLINE);       //Adds a new blank line
            doc.add(palaglapgh);
            doc.add(underText);

            doc.add(chuk1);
            doc.add(chuk2);

            //Current Date and time insertion
            newDate = new Paragraph(date, bf12);
            newDate.setAlignment(Element.ALIGN_RIGHT);
            doc.add(newDate);
            doc.add(regionTexts);
            doc.add(regionText);

            doc.add(Chunk.NEWLINE); //Adds a new blank line
            doc.add(Chunk.NEWLINE);

            doc.add(signParagraph);
            doc.add(dateParagrapgh);

            //close the document
            doc.close();

            //close the writer
            docwriter.close();

            out.close();

            break;

        case "RP Report":

            //Copied code start from here
            try {
                // //file path
                //String path = "docs/" + "Name";
                docwriter = PdfWriter.getInstance(doc, out);
            } catch (DocumentException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            //document header attributes
            doc.addAuthor("CHED CU");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Grant Monitor");
            doc.addTitle(repLot);
            doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape
            //doc.setPageSize(PageSize.A4);
            doc.setMargins(30f, 30f, 20f, 20f);

            //open document
            doc.open();

            //Creating a paragraphs and chunks
            pp = new Paragraph("Cocoa Health And Extension Division", forTitle);
            pp.setAlignment(Element.ALIGN_CENTER);

            palaglapgh = new Paragraph("(Cocobod)", bfBold12);
            palaglapgh.setAlignment(Element.ALIGN_CENTER);

            signParagraph = new Paragraph("Sign: ..............", bfBold12);
            signParagraph.setAlignment(Element.ALIGN_LEFT);

            dateParagrapgh = new Paragraph("Date: ...........", bfBold12);

            chk = new Chunk("From GIS Office, Accra", bfBold12);
            chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            underText = new Paragraph(chk);
            underText.setAlignment(Element.ALIGN_CENTER);

            chuk1 = new Chunk("RP Lot No:", forTitle2);
            chuk1.setUnderline(.1f, -2f);
            chuk2 = new Chunk(repNum.toUpperCase(), forTitle2);

            regionText = new Paragraph(repLot, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            x = "";
            dir = manager.PDFreplants(repNum);
            try {
                if (dir.next()) {
                    x = dir.getString(22);

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

            regionTexts = new Paragraph(x, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            //add the PDF table to the paragraph
            //palaglapgh.add(table);
            //Table Generation block
            regionText.add(RPreport(repNum));

            //SECTION TO ADD ELEMENTS TO PDF
            // add the paragraph to the document
            doc.add(pp);
            //doc.add(Chunk.NEWLINE);       //Adds a new blank line
            doc.add(palaglapgh);
            doc.add(underText);

            doc.add(chuk1);
            doc.add(chuk2);

            //Current Date and time insertion
            newDate = new Paragraph(date, bf12);
            newDate.setAlignment(Element.ALIGN_RIGHT);
            doc.add(newDate);
            doc.add(regionTexts);
            doc.add(regionText);

            doc.add(Chunk.NEWLINE); //Adds a new blank line
            doc.add(Chunk.NEWLINE);

            doc.add(signParagraph);
            doc.add(dateParagrapgh);

            //close the document
            doc.close();

            //close the writer
            docwriter.close();

            out.close();

            break;

        case "Rehab Report":

            //Copied code start from here
            try {
                // //file path
                //String path = "docs/" + "Name";
                docwriter = PdfWriter.getInstance(doc, out);
            } catch (DocumentException ex) {
                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
            }

            //document header attributes
            doc.addAuthor("CHED CU");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Grant Monitor");
            doc.addTitle(repLot);
            doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape
            //doc.setPageSize(PageSize.A4);
            doc.setMargins(5f, 5f, 3f, 3f);

            //open document
            doc.open();

            //Creating a paragraphs and chunks
            pp = new Paragraph("Cocoa Health And Extension Division", forTitle);
            pp.setAlignment(Element.ALIGN_CENTER);

            palaglapgh = new Paragraph("(Cocobod)", bfBold12);
            palaglapgh.setAlignment(Element.ALIGN_CENTER);

            signParagraph = new Paragraph("Sign: ..............", bfBold12);
            signParagraph.setAlignment(Element.ALIGN_LEFT);

            dateParagrapgh = new Paragraph("Date: ...........", bfBold12);

            chk = new Chunk("Component 1 Rehabilitation Tree Removal Cost From GIS Office, Accra", bfBold12);
            chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
            underText = new Paragraph(chk);
            underText.setAlignment(Element.ALIGN_CENTER);

            chuk1 = new Chunk("RP Lot No:", bfBold12);
            chuk1.setUnderline(.1f, -2f);
            chuk2 = new Chunk(repNum, bfBold12);

            regionText = new Paragraph(repLot, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            x = "";
            dir = manager.PDFRehab(repNum);//SHOULD BE CHANGED!!!!
            try {
                if (dir.next()) {
                    x = dir.getString(21);

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

            regionTexts = new Paragraph(x, forTitle2);
            regionText.setAlignment(Element.ALIGN_CENTER);
            //add the PDF table to the paragraph
            //palaglapgh.add(table);
            //Table Generation block
            regionText.add(reports(repNum));

            //SECTION TO ADD ELEMENTS TO PDF
            // add the paragraph to the document
            doc.add(pp);
            //doc.add(Chunk.NEWLINE);       //Adds a new blank line
            doc.add(palaglapgh);
            doc.add(underText);

            doc.add(chuk1);
            doc.add(chuk2);

            //Current Date and time insertion
            newDate = new Paragraph(date, bf12);
            newDate.setAlignment(Element.ALIGN_RIGHT);
            doc.add(newDate);
            doc.add(regionTexts);
            doc.add(regionText);

            doc.add(Chunk.NEWLINE); //Adds a new blank line
            doc.add(Chunk.NEWLINE);

            doc.add(signParagraph);
            doc.add(dateParagrapgh);

            //close the document
            doc.close();

            //close the writer
            docwriter.close();

            out.close();

            //Copied CODES
            break;

        }

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

}

From source file:simz1.ManagerHomeScreen.java

private void btnGenerateReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateReportActionPerformed
    int reply = JOptionPane.showConfirmDialog(null, "Do you wish to fianlize Accounts Report now?", "",
            JOptionPane.YES_NO_OPTION);
    if (reply == JOptionPane.YES_OPTION) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {/*w  w w . ja v  a  2s . co m*/
            String date = today.replace(":", "_");
            //New PDF File will be created as ACCReport2016_01_01 //today's date
            PdfWriter.getInstance(document,
                    new FileOutputStream("C:\\#SIMZ\\Account Reports\\ACCReport" + date + "" + ".pdf"));
            document.open();
            Image image2 = Image.getInstance("C:\\#SIMZ\\logo1.jpg");
            document.add(image2);
            Paragraph paragraph1 = new Paragraph(
                    "Perera and Sons Bakers(pvt)Ltd.\nAddress: 1/52, Galle Road,Colombo 03.\nT.P:0112552225\n\n");
            document.add(paragraph1);
            paragraph1 = new Paragraph("                Finalized Accounts Report - " + today + "",
                    FontFactory.getFont(FontFactory.HELVETICA, 18));
            document.add(paragraph1);
            //adding a table
            PdfPTable t = new PdfPTable(3);
            t.setSpacingBefore(25);
            t.setSpacingAfter(25);

            t.addCell(new PdfPCell(new Phrase("Description")));
            t.addCell(new PdfPCell(new Phrase("Credit(Rs.)")));
            t.addCell(new PdfPCell(new Phrase("Debit(Rs.)")));
            int rows = tblIncome.getRowCount();

            for (int i = 0; i < rows; i++) {
                t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 0) + "")));
                if (tblIncome.getValueAt(i, 1) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 1) + "")));
                }
                if (tblIncome.getValueAt(i, 2) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 2) + "")));
                }
            }
            document.add(t);
            float totalIncome = 0;
            for (int i = 0; i < rows; i++) {
                if (tblIncome.getValueAt(i, 1) != null) {
                    totalIncome = totalIncome + Float.parseFloat(tblIncome.getValueAt(i, 1).toString());
                } else {
                    totalIncome = totalIncome + 0;
                }
            }
            paragraph1 = new Paragraph("Total Income (Rs.) : " + totalIncome + "");
            document.add(paragraph1);
            float totalExpences = 0;
            for (int i = 0; i < rows; i++) {
                if (tblIncome.getValueAt(i, 2) != null) {
                    totalExpences = totalExpences + Float.parseFloat(tblIncome.getValueAt(i, 2).toString());
                } else {
                    totalExpences = totalExpences + 0;
                }
            }
            DecimalFormat roundValue = new DecimalFormat("###.##");
            float expense = Float.parseFloat(roundValue.format(totalExpences));
            paragraph1 = new Paragraph("Total Expence (Rs.) : " + expense + "");
            document.add(paragraph1);
            float profit = 0;
            profit = totalIncome - expense;
            totProfit = profit;
            trigger1 = 1;
            paragraph1 = new Paragraph("Total Profit (Rs.) : " + profit + "" + "\n\n");
            document.add(paragraph1);
            String name = dbOps.getName(name1.getText());
            paragraph1 = new Paragraph("Report Generated By : " + name);
            document.add(paragraph1);
            //view report
            int reply1 = JOptionPane.showConfirmDialog(null,
                    "Finalized Accounts Report named ACCReportToday'sDate successfully generated.\nDo you want to view the report?",
                    "", JOptionPane.YES_NO_OPTION);
            if (reply1 == JOptionPane.YES_OPTION) {
                if ((new File("C:\\#SIMZ\\Account Reports\\ACCReport" + date + "" + ".pdf")).exists()) {

                    Process p = Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler C:\\#SIMZ\\Account Reports\\ACCReport"
                                    + date + "" + ".pdf");
                    p.waitFor();
                }
            }
        } catch (Exception ex) {
            System.out.println(ex);
            JOptionPane.showMessageDialog(this, "File already exists!!!");
        }
        document.close();
    }
}

From source file:simz1.ManagerHomeScreen.java

private void btnFinalReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFinalReportActionPerformed
    int reply = JOptionPane.showConfirmDialog(null, "Do you wish to fianlize Products Report now?", "",
            JOptionPane.YES_NO_OPTION);
    if (reply == JOptionPane.YES_OPTION) {
        Document document = new Document(PageSize.A4);
        try {//from  www . ja v a2s .  co m
            String date = today.replace(":", "_");
            //New PDF File will be created as ProReport2016_01_01 //today's date
            PdfWriter.getInstance(document,
                    new FileOutputStream("C:\\#SIMZ\\Product Reports\\ProReport" + date + "" + ".pdf"));
            document.open();
            Image image2 = Image.getInstance("C:\\#SIMZ\\logo1.jpg");
            document.add(image2);
            Paragraph paragraph1 = new Paragraph(
                    "Perera and Sons Bakers(pvt)Ltd.\nAddress: 1/52, Galle Road,Colombo 03.\nT.P:0112552225\n\n");
            document.add(paragraph1);
            //Following blank space is for the alignment of the topic
            paragraph1 = new Paragraph("                Finalized Products Report - " + today + "",
                    FontFactory.getFont(FontFactory.HELVETICA, 18));
            document.add(paragraph1);
            //adding a table
            PdfPTable t = new PdfPTable(3);
            t.setSpacingBefore(25);
            t.setSpacingAfter(25);
            t.addCell(new PdfPCell(new Phrase("Product Name")));
            t.addCell(new PdfPCell(new Phrase("Received Quantity")));
            t.addCell(new PdfPCell(new Phrase("Remained Quantity")));
            int rows = tblReports.getRowCount();
            for (int i = 0; i < rows; i++) {
                t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 0) + "")));
                if (tblReports.getValueAt(i, 1) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 1) + "")));
                }
                if (tblReports.getValueAt(i, 2) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 2) + "")));
                }
            }
            document.add(t);
            paragraph1 = new Paragraph("Expired Item Details");
            document.add(paragraph1);
            PdfPTable t2 = new PdfPTable(2);
            t2.setSpacingBefore(25);
            t2.setSpacingAfter(25);
            t2.addCell(new PdfPCell(new Phrase("Product Name")));
            t2.addCell(new PdfPCell(new Phrase("Remained Quantity")));
            String dateToday = today.replace(":", "-");
            ResultSet rs = dbOps.getExpiredItemList(dateToday);
            while (rs.next()) {
                t2.addCell(new PdfPCell(new Phrase(rs.getString(1))));
                t2.addCell(new PdfPCell(new Phrase(rs.getString(3))));
            }
            document.add(t2);
            String user = dbOps.getName(name1.getText());
            paragraph1 = new Paragraph("Report Generated By : " + user);
            document.add(paragraph1);
            //view report
            int reply1 = JOptionPane.showConfirmDialog(null,
                    "Finalized Products Report named ProReportToday'sDate successfully generated.\nDo you want to view the report?",
                    "", JOptionPane.YES_NO_OPTION);
            trigger2 = 1;
            if (reply1 == JOptionPane.YES_OPTION) {
                if ((new File("C:\\#SIMZ\\Product Reports\\ProReport" + date + "" + ".pdf")).exists()) {

                    Process p = Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler C:\\#SIMZ\\Product Reports\\ProReport"
                                    + date + "" + ".pdf");
                    p.waitFor();
                }
            }

        } catch (SQLException | HeadlessException | IOException | InterruptedException | DocumentException ex) {
            System.out.println(ex);
            JOptionPane.showMessageDialog(this, "File already exists!!!");
        }
        document.close();
    }
}

From source file:sistemacontrole.MainWindow.java

public void GerarPDFFuncao() throws BadElementException, IOException {
    try {/*w ww . ja  v  a  2 s.c o  m*/
        //Define as fontes
        Font fontOBS = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL);
        Font fontTITULO2 = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL);
        Font fontTITULO = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
        fontTITULO.setColor(BaseColor.RED);

        Font fontDADO = new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.NORMAL);
        Document doc = new Document(PageSize.A4.rotate());

        // adiciona imagem ao pdf
        Image Logotipo = Image.getInstance("./src/Imagens/imagem_pdf.png");
        Logotipo.scalePercent((float) 47.5);
        PdfPTable tabelaGrfico = new PdfPTable(2);
        for (int i = 1; i < this.registro; i++) {
            Image LogotipoI = Image.getInstance("./Raw_Data/PainelEntrada" + i + ".jpg");
            Image LogotipoI2 = Image.getInstance("./Raw_Data/PainelSaida" + i + ".jpg");
            tabelaGrfico.addCell(LogotipoI);
            tabelaGrfico.addCell(LogotipoI2);
        }

        int count = this.tabelaDetalhes.getRowCount();

        PdfWriter.getInstance(doc, new FileOutputStream(TelaPDF.CampoNome.getText() + ".pdf"));
        doc.open();
        PdfPTable pdfTable = new PdfPTable(this.tabelaDetalhes.getColumnCount());
        //adding table headers
        for (int i = 0; i < 15; i++) {
            pdfTable.addCell(new Paragraph(this.tabelaDetalhes.getColumnName(i), fontTITULO));
        }

        PdfPTable pdfTableAuxiliar = new PdfPTable(this.tabelaDetalhes.getColumnCount());

        String[][] valores = new String[15][15];
        for (int i = 0; i < 15; i++) {
            for (int j = 0; j < 15; j++) {
                valores[i][j] = "";
            }
        }

        Object[] obj = null;
        int contador = 1;
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < 15; j++) {
                try {
                    System.out.println("Valor: " + tabelaDetalhes.getModel().getValueAt(i, j).toString()
                            + "Contado: " + contador);
                    valores[i][j] = tabelaDetalhes.getModel().getValueAt(i, j).toString();

                } catch (Exception e) {
                    System.out.println("ERRO  DEU  contador: " + contador);
                    contador++;
                }

            }

        }

        for (int i = 0; i < count; i++) {
            for (int j = 0; j < 15; j++) {
                pdfTableAuxiliar.addCell(new Paragraph(valores[i][j], fontDADO));
            }
        }

        Paragraph title = new Paragraph("Sistema de Controle de Tanques - TC Control" + "\n\n", fontTITULO2);
        title.setAlignment(Paragraph.ALIGN_CENTER);

        Calendar calendar = new GregorianCalendar();
        Date trialTime = new Date();
        calendar.setTime(trialTime);
        Paragraph DIA = new Paragraph("Data: " + calendar.get(Calendar.DATE) + "/"
                + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.YEAR));
        Paragraph HORA = new Paragraph("Hora: " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
                + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND));
        DIA.setAlignment(Paragraph.ALIGN_RIGHT);
        HORA.setAlignment(Paragraph.ALIGN_RIGHT);
        Paragraph espaco = new Paragraph("\n");
        Paragraph aviso = new Paragraph("\nGraficos dos Testes ordenados:");
        aviso.setAlignment(Paragraph.ALIGN_CENTER);

        Paragraph autores = new Paragraph(
                "\n" + "Desenvolvedores: @AlexandeLUZ - @AndersonDIAS - @HigoBESSA - @JaimeDANTAS", fontDADO);
        autores.setAlignment(Paragraph.ALIGN_CENTER);

        Paragraph obs = new Paragraph("\n" + "Observaes: " + TelaPDF.observacoes.getText(), fontOBS);
        obs.setAlignment(Paragraph.ALIGN_CENTER);

        //PARTE DO CASCATA DO TANQUE 1

        Paragraph cascataTitulo = new Paragraph("Parmetros do Tanque 1 (Escravo):  ", fontTITULO2);
        cascataTitulo.setAlignment(Paragraph.ALIGN_CENTER);

        //PdfPTable pdfTableCascata = new PdfPTable(5);
        //                if(cascata){
        //                   
        //                   Paragraph KP = new Paragraph("\n" +
        //                    "Kp" ,fontTITULO);
        //                   pdfTableCascata.addCell(KP);
        //                   Paragraph KD = new Paragraph("\n" +
        //                    "Kd" ,fontTITULO);
        //                   pdfTableCascata.addCell(KD);
        //                   Paragraph KI = new Paragraph("\n" +
        //                    "Ki" ,fontTITULO);
        //                   pdfTableCascata.addCell(KI);
        //                   Paragraph TI = new Paragraph("\n" +
        //                    "Ti" ,fontTITULO);
        //                   pdfTableCascata.addCell(TI);
        //                   Paragraph TD = new Paragraph("\n" +
        //                    "Td" ,fontTITULO);
        //                   pdfTableCascata.addCell(TD);
        //                   Paragraph KP_VALOR = new Paragraph((this.kp_t1),fontDADO);
        //                   Paragraph KD_VALOR = new Paragraph((this.kd_t1),fontDADO);
        //                   Paragraph KI_VALOR = new Paragraph((this.ki_t1),fontDADO);
        //                   Paragraph TI_VALOR = new Paragraph((this.ti_t1),fontDADO);
        //                   Paragraph TD_VALOR = new Paragraph((this.td_t1),fontDADO);
        //                   pdfTableCascata.addCell(KP_VALOR);
        //                   pdfTableCascata.addCell(KD_VALOR);
        //                   pdfTableCascata.addCell(KI_VALOR);
        //                   pdfTableCascata.addCell(TI_VALOR);
        //                   pdfTableCascata.addCell(TD_VALOR);
        //
        //                }

        doc.add(Logotipo);
        doc.add(title);
        doc.add(pdfTable);
        doc.add(pdfTableAuxiliar);
        if (cascata) {
            doc.add(cascataTitulo);
            doc.add(espaco);
            doc.add(pdfTableCascata);
        }
        doc.add(obs);
        doc.add(aviso);
        //doc.add(espaco);
        doc.add(tabelaGrfico);
        doc.add(espaco);
        doc.add(espaco);
        doc.add(DIA);
        doc.add(HORA);
        doc.add(autores);

        doc.close();
        System.out.println("done");
        mostrarAviso("Arquivo criado com sucesso!");
        TelaPDF.setVisible(false);
    } catch (DocumentException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        mostrarErro("Erro ao gerar PDF!");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        mostrarErro("Erro ao gerar PDF!");

    }

}

From source file:src.GUI.PDFGEN.java

License:Open Source License

public void PDFAB(String Headline, int AmountExer, GUISETTINGSPDF k) {
    Document Doc = new Document();
    Rectangle Rec = new Rectangle(PageSize.A4);
    Doc.setPageSize(Rec);/*from   w  w w  . j ava2s  .c om*/
    try {
        F = File.createTempFile("Blatt", ".pdf");
        PdfWriter.getInstance(Doc, new FileOutputStream(F));
        Doc.open();
        Paragraph Para = new Paragraph(Headline, FONTS.FontHeader());
        Para.setAlignment(Element.ALIGN_CENTER);
        Doc.add(Para);
        First = new MEMORY();
        Current = First;
        GUISETTINGSPDF D = k;
        //Image Img = Image.getInstance("Logo");
        //Doc.add(Img);
        for (int i = 1; i <= AmountExer; i++) {
            List = new List(List.ORDERED, List.ALPHABETICAL);
            for (int c = 0; c < k.taskNumber; c++) {
                TERM Term = new TERM(k.aoAddition, k.aoSubtraction, k.aoMultiplication, k.aoDivision,
                        k.bracketDepht, k.Substitutions, k.Digits, k.decimalPlaces, k.justPositive);
                Current.writeExercise(Term.infix() + "=");
                Current.writeSolution(Double.parseDouble(Term.getSolution()));
                List.add(new ListItem(Current.readExercise()));
                Current.Next = new MEMORY();
                Current = Current.Next;
            }
            Doc.add(new Paragraph(" \n Aufgabe " + i, FONTS.Font()));
            k = k.next;
            Doc.add(List);
        }
        Doc.close();
        Desktop.getDesktop().open(F);
        PDFLB(AmountExer, D);
        Desktop.getDesktop().open(G);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:src.GUI.PDFGEN.java

License:Open Source License

private void PDFLB(int AmountExer, GUISETTINGSPDF k) {
    Document Doc = new Document();
    Rectangle Rec = new Rectangle(PageSize.A4);
    Doc.setPageSize(Rec);/*from  ww w .j ava2 s  . c  o  m*/
    try {
        G = File.createTempFile("Blatt", ".pdf");
        PdfWriter.getInstance(Doc, new FileOutputStream(G));
        Doc.open();
        Paragraph Para = new Paragraph("Lsungsblatt", FONTS.FontHeader());
        Para.setAlignment(Element.ALIGN_CENTER);
        Doc.add(Para);
        for (int i = 1; i <= AmountExer; i++) {
            List = new List(List.ORDERED, List.ALPHABETICAL);
            for (int c = 0; c < k.taskNumber; c++) {
                String S = First.readExercise() + First.readSolution();
                List.add(new ListItem(S));
                First = First.Next;
            }
            Doc.add(new Paragraph(" \n Aufgabe" + i, FONTS.Font()));
            Doc.add(List);
            k = k.next;
        }
        Doc.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:superlaskuttaja.logiikka.PdfExtractor.java

public void vieLaskuPdf(String laskunNumero) {
    try {//from   w w w  .j av a2  s .  c  o m
        String polku = "";
        String viiteTarkisteella;

        ResultSet rs = lataaja.getDbc()
                .executeQuery("select distinct viiteTarkisteella\n" + "from Lasku, Pankkiviivakoodi\n"
                        + "where laskunNumero = " + laskunNumero + "\n"
                        + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n" + "");
        rs.first();
        viiteTarkisteella = rs.getString(1);

        rs = lataaja.getDbc()
                .executeQuery("select pdfOletusvientipolku\n" + "from Asetukset\n" + "where asetuksetID = 1");
        if (rs.first()) {
            if (rs.getString(1) != null) {
                polku = rs.getString(1);
                chooser.setCurrentDirectory(new File(polku));
            }
            chooser.setSelectedFile(new File(viiteTarkisteella + ".pdf"));
        }
        int retrival = chooser.showSaveDialog(chooser);
        if (!polku.equals(chooser.getCurrentDirectory().getPath())) {
            lataaja.getDbc().executeUpdate("update Asetukset\n" + "set pdfOletusvientipolku = '"
                    + chooser.getCurrentDirectory().getPath() + "'\n" + "where asetuksetID = 1");
        }
        Document document = new Document(PageSize.A4, 40, 20, 30, 30);
        if (retrival == JFileChooser.APPROVE_OPTION) {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(chooser.getSelectedFile()));
            muodostaDokumentti(document, laskunNumero, writer);
            writer.close();
        } else {
        }
    } catch (SQLException sQLException) {
        sQLException.printStackTrace();
    } catch (HeadlessException headlessException) {
    } catch (FileNotFoundException fileNotFoundException) {
    } catch (DocumentException documentException) {
    } catch (ParseException parseException) {
    }
}

From source file:support.plus.reportit.export.export_pdf_class.java

License:Open Source License

public void exportToPDF(String RESULT, String filenumber, String filetag, String startdate, String enddate,
        String TextuserNameString, String TextuserNameBossString, String mondayText1, String mondayText2,
        String mondayText3, String mondayText4, String mondayText5, String mondayText6, String tuesdayText1,
        String tuesdayText2, String tuesdayText3, String tuesdayText4, String tuesdayText5, String tuesdayText6,
        String wednesdayText1, String wednesdayText2, String wednesdayText3, String wednesdayText4,
        String wednesdayText5, String wednesdayText6, String thursdayText1, String thursdayText2,
        String thursdayText3, String thursdayText4, String thursdayText5, String thursdayText6,
        String fridayText1, String fridayText2, String fridayText3, String fridayText4, String fridayText5,
        String fridayText6, String mondayTextTime1, String mondayTextTime2, String mondayTextTime3,
        String mondayTextTime4, String mondayTextTime5, String mondayTextTime6, String tuesdayTextTime1,
        String tuesdayTextTime2, String tuesdayTextTime3, String tuesdayTextTime4, String tuesdayTextTime5,
        String tuesdayTextTime6, String wednesdayTextTime1, String wednesdayTextTime2,
        String wednesdayTextTime3, String wednesdayTextTime4, String wednesdayTextTime5,
        String wednesdayTextTime6, String thursdayTextTime1, String thursdayTextTime2, String thursdayTextTime3,
        String thursdayTextTime4, String thursdayTextTime5, String thursdayTextTime6, String fridayTextTime1,
        String fridayTextTime2, String fridayTextTime3, String fridayTextTime4, String fridayTextTime5,
        String fridayTextTime6) throws DocumentException, IOException {

    // step 1//ww w . ja v a  2  s . c  om
    // Specifying the page size
    Document document = new Document(PageSize.A4, 0, 0, 0, 0);
    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(RESULT));
    // step 3
    document.open();
    // step 4
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));

    PdfPTable table = createFirstTable(filenumber, filetag, startdate, enddate, TextuserNameString,
            TextuserNameBossString, mondayText1, mondayText2, mondayText3, mondayText4, mondayText5,
            mondayText6, tuesdayText1, tuesdayText2, tuesdayText3, tuesdayText4, tuesdayText5, tuesdayText6,
            wednesdayText1, wednesdayText2, wednesdayText3, wednesdayText4, wednesdayText5, wednesdayText6,
            thursdayText1, thursdayText2, thursdayText3, thursdayText4, thursdayText5, thursdayText6,
            fridayText1, fridayText2, fridayText3, fridayText4, fridayText5, fridayText6, mondayTextTime1,
            mondayTextTime2, mondayTextTime3, mondayTextTime4, mondayTextTime5, mondayTextTime6,
            tuesdayTextTime1, tuesdayTextTime2, tuesdayTextTime3, tuesdayTextTime4, tuesdayTextTime5,
            tuesdayTextTime6, wednesdayTextTime1, wednesdayTextTime2, wednesdayTextTime3, wednesdayTextTime4,
            wednesdayTextTime5, wednesdayTextTime6, thursdayTextTime1, thursdayTextTime2, thursdayTextTime3,
            thursdayTextTime4, thursdayTextTime5, thursdayTextTime6, fridayTextTime1, fridayTextTime2,
            fridayTextTime3, fridayTextTime4, fridayTextTime5, fridayTextTime6);
    document.add(table);
    document.add(new Paragraph(" "));
    document.add(createSecondTable());
    // step 5
    document.close();

}

From source file:Tables.Printer.java

public void genTrans(TableView gentab, TableColumn name, TableColumn desc, TableColumn amt, TableColumn date,
        long total, String incOrExp) {
    try {/* w  ww.  j  a  v a 2s .  c om*/
        //            Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png");
        //            im.scaleAbsolute(150f, 150f);
        //            im.setAbsolutePosition(25,50);
        //            im.setBackgroundColor(BaseColor.PINK);

        dNow = new Date();
        String app = this.datForFile.format(dNow);
        String file = "\\Documents\\NjieAB_receipts\\general transactions\\GenTransRec" + app + ".pdf";
        System.out.println("file is " + file);
        fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea
        //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf");

        Document doc = new Document(PageSize.A4, 20, 20, 20, 20);
        PdfWriter writer = PdfWriter.getInstance(doc, fs);
        //specify column widths    
        float[] columnWidths = { 4f, 5f, 1.5f, 2f };
        PdfPTable table = new PdfPTable(columnWidths);

        //special font sizes    
        Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10);
        // set table width a percentage of the page width    
        table.setWidthPercentage(90f);

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR "));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        //doc.add(im);

        header(doc, "General " + incOrExp + " Transaction Table");

        doc.add(cell);
        System.out.println(doc.leftMargin());

        //insert column headings    
        insertTableHeading(table, "Transaction Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Description of Transaction", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Amount", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Date ", Element.ALIGN_MIDDLE, 1, bfBold12);
        table.setHeaderRows(1);

        /*Now i have to fill the table  */

        for (int i = 0; i < gentab.getItems().size(); i++) {
            insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, desc.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, amt.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, date.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12);
        }

        insertCell(table, "Total ", Element.ALIGN_RIGHT, 2, bfBold12);
        insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 3, bfBold12);
        insertCell(table, "", Element.ALIGN_RIGHT, 4, bfBold12);
        doc.add(table);

        footer(doc); // this is rgw footer of the page

        doc.addCreationDate();
        doc.close();
        System.out.println("finished the printing job");

        //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"));
        try {
            Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file));
        } catch (IOException iOException) {
            System.out.println("failed opening the file");
            iOException.printStackTrace();
        }
    } catch (Exception sd) {
        sd.printStackTrace();
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message(
                sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString())
                .showError();
    } finally {
    }
}

From source file:Tables.Printer.java

public void salarySuspension(TableView supIssTab, TableColumn name, TableColumn amount, TableColumn reason,
        TableColumn susDate, TableColumn status, long total) {
    String title = "Salary Suspension";

    try {/* ww  w . java2 s.  com*/
        //            Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png");
        //            im.scaleAbsolute(150f, 150f);
        //            im.setAbsolutePosition(25,50);
        //            im.setBackgroundColor(BaseColor.PINK);

        dNow = new Date();
        String app = this.datForFile.format(dNow);
        String file = "\\Documents\\NjieAB_receipts\\staff\\suspension " + app + ".pdf";

        System.out.println("file is " + file);
        fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea
        //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf");

        Document doc = new Document(PageSize.A4, 10, 10, 5, 10);
        PdfWriter writer = PdfWriter.getInstance(doc, fs);
        //specify column widths    
        float[] columnWidths = { 6f, 3f, 8f, 3f, 2f };
        PdfPTable table = new PdfPTable(columnWidths);

        //special font sizes    
        Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10);
        // set table width a percentage of the page width    
        table.setWidthPercentage(90f);

        PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR "));
        cell.setColspan(6);
        cell.setHorizontalAlignment(2);
        doc.open();
        //doc.add(im);

        header(doc, title);

        doc.add(cell);
        System.out.println(doc.leftMargin());

        //insert column headings    

        insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Amount ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Reason", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Date ", Element.ALIGN_MIDDLE, 1, bfBold12);
        insertTableHeading(table, "Status", Element.ALIGN_MIDDLE, 1, bfBold12);

        table.setHeaderRows(1);

        /*Now i have to fill the table  */

        for (int i = 0; i < supIssTab.getItems().size(); i++) {
            insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, amount.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, reason.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, susDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, status.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12);

        }

        insertCell(table, "", Element.ALIGN_RIGHT, 1, bfBold12);
        insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12);
        insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 1, bfBold12);
        doc.add(table);

        footer(doc); // this is rgw footer of the page

        doc.addCreationDate();
        doc.close();
        System.out.println("finished the printing job");

        try {
            Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file));
        } catch (IOException iOException) {
            System.out.println("failed opening the file");
        }
    } catch (Exception sd) {
        Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message(
                sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString())
                .showError();
    } finally {
    }

}