Example usage for com.itextpdf.text PageSize FLSE

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

Introduction

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

Prototype

Rectangle FLSE

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

Click Source Link

Document

This is the European Foolscap format

Usage

From source file:coreservlets.reportPDF.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w  w  w.j  a va 2s .  com*/
 *
 * @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");
    try (PrintWriter out = response.getWriter()) {
        response.setContentType("application/pdf");
        /** create Object Of document */
        Document document = new Document(PageSize.FLSE);
        /** set margin of page */
        document.setMargins(1.25F, 0.75F, 5F, 0.75F);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
        document.open();
        /** Table For header address */
        PdfPTable headerTable = new PdfPTable(3);
        headerTable.setWidthPercentage(91);
        /** Add company Address*/
        /** First Cell  For address*/
        PdfPCell headerCell = new PdfPCell();
        headerCell.addElement(new Paragraph("My comapany"));
        /** add cell to headerTable*/
        headerTable.addCell(headerCell);
        /** Second cell For CompanyLogo */
        headerCell = new PdfPCell();
        /** get context object */
        ServletContext context = request.getSession().getServletContext();
        /** get Real  Path of image */
        String path = context.getRealPath(login.getPath());
        /** set image to cell*/
        Image img = Image.getInstance(path);
        headerCell.setImage(img);
        /** add cell to headerTable*/
        headerTable.addCell(headerCell);
        /** Third cell for lable of document **/
        headerCell = new PdfPCell();
        String allLedger = "ALL LEDGER";
        headerCell.addElement(new Paragraph(
                allLedger + "\n" + "From Date:" + session.getAttribute("firstDate") + "\nTo Date:"
                        + session.getAttribute("lastDate"),
                new Font(Font.TIMES_ROMAN, 10f, Font.BOLD, Color.black)));

        /** add cell to headerTable*/

        headerTable.addCell(headerCell);
        /** add table to document */

        document.add(headerTable);
        document.close();
        /** Don't know why??*/
        response.setContentLength(baos.size());
        /** comment it if u don't want to download pdf*/
        //response.addHeader("Content-Disposition", "attachment; filename=\"ledgers.pdf\"");

        /** get out put Stream*/
        out = response.getOutputStream();
        /** write to--- Don't know*/
        baos.writeTo(out);
        /** Clear OutputStream*/
        out.flush();
        out.close();

    }
}