Example usage for com.lowagie.text Document addTitle

List of usage examples for com.lowagie.text Document addTitle

Introduction

In this page you can find the example usage for com.lowagie.text Document addTitle.

Prototype


public boolean addTitle(String title) 

Source Link

Document

Adds the title to a Document.

Usage

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Generates the report and sends it to the user over the provided servlet
 * response.//from w  ww.j  a v  a  2s  . com
 *
 * @param  requestInfo  State information about the request being processed.
 */
public void generateReport(RequestInfo requestInfo) {
    // Determine exactly what to include in the report.  We will want to strip
    // out any individual jobs that are part of an optimizing job that is also
    // to be included in the report.
    reportOptimizingJobs = new OptimizingJob[optimizingJobList.size()];
    optimizingJobList.toArray(reportOptimizingJobs);

    ArrayList<Job> tmpList = new ArrayList<Job>(jobList.size());
    for (int i = 0; i < jobList.size(); i++) {
        Job job = jobList.get(i);
        String optimizingJobID = job.getOptimizingJobID();
        if ((optimizingJobID != null) && (optimizingJobID.length() > 0)) {
            boolean matchFound = false;

            for (int j = 0; j < reportOptimizingJobs.length; j++) {
                if (optimizingJobID.equalsIgnoreCase(reportOptimizingJobs[j].getOptimizingJobID())) {
                    matchFound = true;
                    break;
                }
            }

            if (matchFound) {
                continue;
            }
        }

        tmpList.add(job);
    }
    reportJobs = new Job[tmpList.size()];
    tmpList.toArray(reportJobs);

    // Prepare to actually generate the report and send it to the user.
    HttpServletResponse response = requestInfo.getResponse();
    if (viewInBrowser) {
        response.setContentType("application/pdf");
    } else {
        response.setContentType("application/x-slamd-report-pdf");
    }
    response.addHeader("Content-Disposition", "filename=\"slamd_data_report.pdf\"");

    try {
        // Create the PDF document and associate it with the response to send to
        // the client.
        Document document = new Document(PageSize.LETTER);
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
        document.addTitle("SLAMD Generated Report");
        document.addCreationDate();
        document.addCreator("SLAMD Distributed Load Generator");
        writer.setPageEvent(this);

        // Open the document and add the table of contents.
        document.open();

        boolean needNewPage = writeContents(document);

        // Write the regular job information.
        for (int i = 0; i < reportJobs.length; i++) {
            if (needNewPage) {
                document.newPage();
            }
            writeJob(document, reportJobs[i]);
            needNewPage = true;
        }

        // Write the optimizing job information.
        for (int i = 0; i < reportOptimizingJobs.length; i++) {
            if (needNewPage) {
                document.newPage();
            }
            writeOptimizingJob(document, reportOptimizingJobs[i]);
            needNewPage = true;
        }

        // Close the document.
        document.close();
    } catch (Exception e) {
        // Not much we can do about this.
        e.printStackTrace();
        return;
    }
}

From source file:com.web.chon.bean.BeanBuscaCredito.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();//from www.  j a v a 2 s. co m
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "img"
            + File.separator + "pdf.png";
    pdf.addTitle("Estado de Cuenta " + cliente.getNombreCompleto());
}

From source file:Cotizacion.ExportarPDF.java

private static void agregarMetaDatos(Document document) {
    document.addTitle("PDF Cliente");
    document.addSubject("Usando iText");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor("Ana Karen Soto");
    document.addCreator("Ana Karen Soto");
}

From source file:CPS.Core.TODOLists.PDFExporter.java

License:Open Source License

private Document prepareDocument(String filename, final String title, final String author, final String creator,
        final Rectangle pageSize) {

    System.out.println("DEBUG(PDFExporter): Creating document: " + filename);

    Document d = new Document();

    d.setPageSize(pageSize);/*from  ww w  .  j  a v a  2 s  .  com*/
    // TODO alter page orientation?  maybe useful for seed order worksheet

    d.addTitle(title);
    d.addAuthor(author);
    //        d.addSubject( );
    //        d.addKeywords( );
    d.addCreator(creator);

    // left, right, top, bottom - scale in points (~72 points/inch)
    d.setMargins(35, 35, 35, 44);

    try {
        PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream(filename));
        // add header and footer
        writer.setPageEvent(new PdfPageEventHelper() {
            public void onEndPage(PdfWriter writer, Document document) {
                try {
                    Rectangle page = document.getPageSize();

                    PdfPTable head = new PdfPTable(3);
                    head.getDefaultCell().setBorderWidth(0);
                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                    head.addCell(new Phrase(author, fontHeadFootItal));

                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    head.addCell(new Phrase(title, fontHeadFootReg));

                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    head.addCell("");

                    head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
                    head.writeSelectedRows(0, -1, document.leftMargin(),
                            page.getHeight() - document.topMargin() + head.getTotalHeight(),
                            writer.getDirectContent());

                    PdfPTable foot = new PdfPTable(3);

                    foot.getDefaultCell().setBorderWidth(0);
                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                    foot.addCell(new Phrase(creator, fontHeadFootItal));

                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    foot.addCell("");

                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    foot.addCell(new Phrase("Page " + document.getPageNumber(), fontHeadFootReg));

                    foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
                    foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                            writer.getDirectContent());
                } catch (Exception e) {
                    throw new ExceptionConverter(e);
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }

    return d;
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Adds meta data to the PDF document. The information of using iText must
 * be part of the meta data due to the license of the iText library!
 * //  w  ww .ja  va2s .co  m
 * @param document
 *            represents the PDF before it is saved
 */
private void addMetaData(Document document) {
    document.addTitle("Humbuch Schule");
    document.addSubject("Using iText");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor("Schlager");
    document.addCreator("Schlager");
}

From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private Document writeDocument(Document document, List<SudokuData> sudokus) throws DocumentException {
    document.open();/*from  w  ww.  j av  a 2 s.  co m*/
    // TODO Von auen konfigurieren
    document.addAuthor("Jrgen Dufner");
    document.addCreationDate();
    document.addCreator("de.jdufner.sudoku.Generator");
    document.addKeywords("Sudoku");
    document.addTitle("Sudokus in unterschiedlichen Schwierigkeitsgraden");
    document.add(writePdfMetaTable(sudokus));
    document.close();
    return document;
}

From source file:de.maklerpoint.office.Schnittstellen.PDF.ExportListePDF.java

License:Open Source License

public void write() throws DocumentException, FileNotFoundException {

    SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");

    Document doc = null;

    if (titles.length > 7)
        doc = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    else/*from www.  j  a v a  2s.  co m*/
        doc = new Document(PageSize.A4, 20, 20, 20, 20);

    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(filename));
    doc.addAuthor("MaklerPoint - www.maklerpoint.de");
    doc.addCreator("MaklerPoint - www.maklerpoint.de");
    doc.addCreationDate();
    doc.addTitle(title);

    doc.open();

    doc.add(new Paragraph(title, FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, Color.BLACK)));

    Table t = new Table(titles.length, data.length + 1);
    t.setPadding(3);
    t.setSpacing(0);
    t.setBorderWidth(1);

    for (int i = 0; i < titles.length; i++) {
        Cell c1 = new Cell(titles[i]);
        c1.setHeader(true);
        t.addCell(c1);
    }
    t.endHeaders();

    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data[i].length; j++) {
            Cell c1 = null;
            if (data[i][j] != null)
                c1 = new Cell(data[i][j].toString());
            else
                c1 = new Cell("");
            t.addCell(c1);
        }
    }

    doc.add(t);

    if (footer == null) {
        doc.add(new Paragraph(
                ("Export " + title + " - Genereriert am " + df.format(new Date(System.currentTimeMillis())))
                        + " von MaklerPoint",
                FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL, Color.black)));
    } else {
        doc.add(new Paragraph(footer, FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL, Color.black)));
    }

    doc.close();
}

From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFManager.java

License:Apache License

/***************************************************************************
 * Creates a PDF, which is streams to the OutputStream out.
 * //w w  w .  j a  v a 2  s.  com
 * @param out {@link OutputStream}
 * @param pagesizemode {@link PdfPageSize}
 * 
 * 
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws FileNotFoundException the file not found exception
 * @throws ImageManagerException the image manager exception
 * @throws PDFManagerException the PDF manager exception
 * @throws ImageInterpreterException the image interpreter exception
 * @throws URISyntaxException
 ****************************************************************************/
public void createPDF(OutputStream out, PdfPageSize pagesizemode, Watermark myWatermark)
        throws ImageManagerException, FileNotFoundException, IOException, PDFManagerException,
        ImageInterpreterException, URISyntaxException {

    Document pdfdoc = null;
    PdfWriter writer = null;

    Rectangle pagesize = null; // pagesize of the first page
    PdfPageLabels pagelabels = null; // object to store all page labels

    try {
        if ((imageURLs == null) || (imageURLs.isEmpty())) {
            throw new PDFManagerException("No URLs for images available, HashMap is null or empty");
        }

        // set the page sizes & pdf document
        pdfdoc = setPDFPageSizeForFirstPage(pagesizemode, pagesize);

        // writer for creating the PDF
        writer = createPDFWriter(out, pdfdoc);

        // set metadata for PDF as author and title
        // ------------------------------------------------------------------------------------
        if (this.title != null) {
            pdfdoc.addTitle(this.title);
        }
        if (this.author != null) {
            pdfdoc.addAuthor(this.author);
        }
        if (this.keyword != null) {
            pdfdoc.addKeywords(this.keyword);
        }
        if (this.subject != null) {
            pdfdoc.addSubject(this.subject);
        }
        // add title page to PDF
        if (pdftitlepage != null) {
            // create a title page
            pdftitlepage.render(pdfdoc);
        }

        // iterate over all files, they must be ordered by the key
        // the key contains the page number (as integer), the String
        // contains the Page name
        // ----------------------------------------------------------------------

        pagelabels = addAllPages(pagesizemode, writer, pdfdoc, myWatermark);

        // add page labels
        if (pagelabels != null) {
            writer.setPageLabels(pagelabels);
        }

        // create the required xmp metadata
        // for pdfa
        if (pdfa) {
            writer.createXmpMetadata();
        }
    } catch (ImageManagerException e) {
        if (pdfdoc != null) {
            pdfdoc.close();
        }
        if (writer != null) {
            writer.close();
        }
        throw e;
    } catch (PDFManagerException e) {
        if (pdfdoc != null) {
            pdfdoc.close();
        }
        if (writer != null) {
            writer.close();
        }
        throw e;
    } catch (ImageInterpreterException e) {
        if (pdfdoc != null) {
            pdfdoc.close();
        }
        if (writer != null) {
            writer.close();
        }
        throw e;
    } catch (IOException e) {
        if (pdfdoc != null) {
            pdfdoc.close();
        }
        if (writer != null) {
            writer.close();
        }
        throw e;
    }
    // close documents and writer
    try {
        if (pdfdoc != null && pdfdoc.isOpen()) {
            pdfdoc.close();
        }
        if (writer != null) {
            writer.close();
        }
    } catch (IllegalStateException e) {
        LOGGER.warn("Caught IllegalStateException when closing pdf document.");
    } catch (NullPointerException e) {
        throw new PDFManagerException("Nullpointer occured while closing pdfwriter");
    }
    LOGGER.debug("PDF document and writer closed");
}

From source file:Driver.RunTestCases.java

License:Open Source License

public void generateReport() {

    File file = new File("Report1.pdf");
    FileOutputStream fileout = null;
    try {//from   www.  j  a v  a  2s.  c om
        fileout = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, fileout);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.addAuthor("AGTT");
    document.addTitle("AGTT Report");

    document.open();
    Boolean status = true;
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader("Results.txt"));
        String line = null;
        String testCase = null;
        Chunk chunk = null;
        int index = 0;
        List list = new List();
        while ((line = reader.readLine()) != null) {
            if (line.contains("Case")) {

                if (index > 0) {
                    System.out.println(line + status + list.size());
                    if (status == false) {
                        chunk.setBackground(Color.RED);
                    }
                    if (status == true) {
                        chunk.setBackground(Color.GREEN);
                    }
                    document.add(chunk);
                    document.add((Element) list);
                    status = true;
                    list = new List();
                    testCase = null;
                }
                chunk = new Chunk(line + "\n");
                Font font = new Font(Font.TIMES_ROMAN);
                font.setSize(18);
                chunk.setFont(font);
                index++;
            } else {
                if (line.contains("not")) {
                    status = false;
                }
                list.add(line);
            }
            //   document.add(chunk);
        }
    } catch (IOException | DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:edu.eci.pdsw.g4.bean.control.web.SystemManageBean.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();//from ww w  .j  a v  a2s  .  co  m
    pdf.setPageSize(PageSize.A4);

    pdf.addTitle("Ficha del Equipo : " + loadTipoEquipo.getNombre_equipo());

    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    String logo = externalContext.getRealPath("") + File.separator + "resource" + File.separator
            + "ecijulio.png";

    pdf.add(Image.getInstance(logo));
    pdf.bottom(30);

    pdf.add(new Chunk(
            "Datos del Equipo : " + loadTipoEquipo.getNombre_equipo() + " con Placa No : " + getPlacaficha()));
}