Example usage for com.itextpdf.text Document newPage

List of usage examples for com.itextpdf.text Document newPage

Introduction

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

Prototype


public boolean newPage() 

Source Link

Document

Signals that an new page has to be started.

Usage

From source file:sipl.recursos.GenerarPDFtipomaterial.java

private static void addTitlePage(Document document)
        throws DocumentException, MalformedURLException, BadElementException, IOException {
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);//  w w  w.j  a v a2 s .c  om
    preface.add(new Paragraph(Titulo, catFont));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(
            "Reporte generado por: " + user.getNombre() + " " + user.getApellido() + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("Este documento es creado a peticin del autor", smallBold));

    addEmptyLine(preface, 6);
    Image img = Image.getInstance(direc + "img//logo_unab.jpg");
    img.scaleAbsolute(70, 100);
    img.setAlignment(Image.ALIGN_CENTER);
    Chunk c = new Chunk(img, 0, 0);
    preface.add(c);
    document.add(preface);
    document.newPage();
    Paragraph preface1 = new Paragraph();
    preface1.add(new Paragraph("Grfica", smallBold));
    addEmptyLine(preface1, 20);
    img = Image.getInstance(imgG);
    img.scaleAbsolute(400, 300);
    img.setAlignment(Image.ALIGN_CENTER);
    c = new Chunk(img, 0, 0);
    preface1.add(c);
    document.add(preface1);
    document.newPage();
}

From source file:sistemafacturacionlibros.PDFCreator.java

public void addTitlePage(Document document, PdfPTable table, String total) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from w w w  .j  a  va 2 s.c o m*/
    // Lets write a big header
    preface.add(new Paragraph("Factura libros", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    //    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    //        smallBold));
    Date myDate = new Date();
    preface.add(new Paragraph("Fecha: " + new SimpleDateFormat("yyyy-MM-dd").format(myDate)));
    addEmptyLine(preface, 3);
    //    preface.add(new Paragraph("This document describes something which is very important ",
    //        smallBold));

    //    preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //        redFont));

    document.add(preface);
    document.add(table);
    addEmptyLine(new Paragraph(), 2);
    document.add(new Paragraph("Total = $" + total, catFont));
    // Start a new page
    document.newPage();
}

From source file:src.servlets.ManageAdmin.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from   ww w  .  j  ava2 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:SystemOperations.PdfGen.java

/**
 * Generate report for not returned vehicles.
 *
 * @param notReturnList ArrayList of {@link Reservation} that has not been
 * returned./*from w  w  w . j a  va 2s  .  co  m*/
 * @param title The title of the report.
 */
public static void genVehicleNotReturnReport(ArrayList<Reservation> notReturnList, String title) {
    try {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(title + ".pdf"));
        document.open();

        document.newPage();
        addMetaData(document, title);
        addTitle(document, title);

        PdfPTable table = new PdfPTable(5);
        addTableContent(table, "Contract #", "Vehicle Class", "Return Date", "Customer Name", "Customer Phone");
        for (Reservation res : notReturnList) {
            addTableContent(table, Integer.toString(res.getContractNo()), res.getVehicleClass(),
                    tf.format(res.getReturnTime()), res.getCustomerName(), res.getCustomerPhone());
        }
        document.add(table);

        document.close();
    } catch (Exception ex) {
        Logger.getLogger(PdfGen.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:SystemOperations.PdfGen.java

/**
 * Generate report for available vehicle class
 *
 * @param vcList ArrayList of available {@link VehicleClass}.
 * @param title Title of the report./*ww  w  .j a v a2s .c  o  m*/
 */
public static void genAvailableVehicleClassReport(ArrayList<VehicleClass> vcList, String title) {
    try {

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(title + ".pdf"));
        document.open();

        document.newPage();
        addMetaData(document, title);
        addTitle(document, title);

        PdfPTable table = new PdfPTable(5);
        addTableContent(table, "Vehicle Type", "Vehicle Class", "Hourly Rate", "Daily Rate", "Weekly Rate");
        for (VehicleClass vc : vcList) {
            addTableContent(table, vc.getVehicleType().toString(), vc.getClassName(), vc.getHourlyPrice(),
                    vc.getDailyPrice(), vc.getWeeklyPrice());
        }
        document.add(table);

        document.close();
    } catch (Exception ex) {
        Logger.getLogger(PdfGen.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:SystemOperations.PdfGen.java

/**
 * Generate report for vehicle for sale.
 *
 * @param vlist ArrayList of for sale {@link Vehicle}.
 * @param title Title of the report./*from   w ww.  j av a 2  s  .  co  m*/
 */
public static void genVehicleForSaleReport(ArrayList<Vehicle> vlist, String title) {
    try {

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(title + ".pdf"));
        document.open();

        document.newPage();
        addMetaData(document, title);
        addTitle(document, title);

        PdfPTable table = new PdfPTable(6);
        addTableContent(table, "Vehicle Number", "Vehicle Class", "Brand & Model", "Manufacturer Year",
                "Odometer", "Sale Price");
        for (Vehicle v : vlist) {
            addTableContent(table, Integer.toString(v.getVehicleNo()), v.getClassName(), v.getMode(),
                    df.format(v.getManufactureDate()), Integer.toString(v.getOdometer()), v.getSellingPrice());
        }
        document.add(table);

        document.close();
    } catch (Exception ex) {
        Logger.getLogger(PdfGen.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:SystemOperations.PdfGen.java

/**
 * Generate report for not rented reservation.
 *
 * @param resList ArrayList of not rented {@link Reservation}.
 * @param title Title of the report./*  w w w  . j a  v a2  s . c  o  m*/
 */
public static void genUnrentedReservation(ArrayList<Reservation> resList, String title) {
    try {

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(title + ".pdf"));
        document.open();

        document.newPage();
        addMetaData(document, title);
        addTitle(document, title);

        PdfPTable table = new PdfPTable(5);
        addTableContent(table, "Reservation #", "Vehicle Class", "Pickup Date", "Return Date", "Customer Name");
        for (Reservation res : resList) {
            addTableContent(table, res.getReservationNo(), res.getVehicleClass(),
                    tf.format(res.getPickupTime()), tf.format(res.getReturnTime()), res.getCustomerName());
        }
        document.add(table);

        document.close();
    } catch (Exception ex) {
        Logger.getLogger(PdfGen.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:SystemOperations.PdfGen.java

/**
 * Generate report for all vehicle list.
 *
 * @param vlist ArrayList of {@link Vehicle} to display in report.
 * @param title Title of the report./*from  w w  w  . j  a  v  a 2 s  .  c  om*/
 */
public static void genVehicleListReport(ArrayList<Vehicle> vlist, String title) {
    try {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(title + ".pdf"));
        document.open();

        document.newPage();
        addMetaData(document, title);
        addTitle(document, title);

        PdfPTable table = new PdfPTable(6);
        addTableContent(table, "Vehicle No", "Vehicle Class", "Brand & Model", "Manufacturer Year", "Odometer",
                "Status");
        for (Vehicle v : vlist) {
            addTableContent(table, Integer.toString(v.getVehicleNo()), v.getClassName(), v.getMode(),
                    df.format(v.getManufactureDate()), Integer.toString(v.getOdometer()),
                    v.getStatus().toString());
        }
        document.add(table);

        document.close();
    } catch (Exception ex) {
        Logger.getLogger(PdfGen.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:SystemOperations.PdfGen.java

/**
 * Generate report for vehicle list that used in daily rent and daily
 * return./*from ww w  .  ja  v a2  s.  c  om*/
 *
 * @param vlist ArrayList of {@link Vehicle} to display in report.
 * @param title Title of the report.
 */
public static void genVehicleReport(ArrayList<Vehicle> vlist, String title) {
    try {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(title + ".pdf"));
        document.open();

        document.newPage();
        addMetaData(document, title);
        addTitle(document, title);

        PdfPTable table = new PdfPTable(5);
        addTableContent(table, "Plate Number", "Vehicle Class", "Brand & Model", "Manufacturer Year",
                "BranchID");
        for (Vehicle v : vlist) {
            addTableContent(table, v.getPlateNo(), v.getClassName(), v.getMode(),
                    df.format(v.getManufactureDate()), Integer.toString(v.getBranchId()));
        }
        document.add(table);

        document.close();
    } catch (Exception ex) {
        Logger.getLogger(PdfGen.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:SystemOperations.PdfGen.java

/**
 * Generate reservation confirmation./*from  ww w  . j  av a2s. c  om*/
 * @param res The {@link Reservation} to generate confirmation.
 * @param title Title of the report.
 */
public static void genReservationConfirmation(Reservation res, String title) {
    try {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(title + ".pdf"));
        document.open();

        document.newPage();
        addMetaData(document, title);
        addTitle(document, title);

        addParagraph(document, "Your Reservation number is : " + res.getReservationNo());
        addParagraph(document, "Pickup Time: " + res.getPickupTime().toString());
        addParagraph(document, "Return Time: " + res.getReturnTime().toString());
        addParagraph(document, "Vehicle Class: " + res.getVehicleClass());

        addEmptyLine(document, 1);

        addLine(document, "Additional Equipment:");
        for (ReserveEquipment re : res.getReserveEquipment()) {
            addLine(document, "        " + re.getEquipmentType());
        }

        addLine(document, "Insurance: ");
        for (BuyInsurance insurance : res.getReserveInsurance()) {
            addLine(document, "        " + insurance.getInsuranceName());
        }

        addParagraph(document, "Your total cost will be: " + res.getEstimation());

        document.close();
    } catch (Exception ex) {
        Logger.getLogger(PdfGen.class.getName()).log(Level.SEVERE, null, ex);
    }
}