Example usage for com.lowagie.text Document addSubject

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

Introduction

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

Prototype


public boolean addSubject(String subject) 

Source Link

Document

Adds the subject to a Document.

Usage

From source file:com.stratelia.webactiv.newsEdito.control.PdfGenerator.java

License:Open Source License

/**
 * Method declaration/*from   w ww .j a  v a2 s.co  m*/
 * @param name
 * @param completePubList
 * @param langue
 * @throws NewsEditoException
 * @see
 */
public static void generatePubList(String name, Collection<CompletePublication> completePubList, String langue)
        throws NewsEditoException {
    SilverTrace.info("NewsEdito", "PdfGenerator.generatePubList", "NewsEdito.MSG_ENTRY_METHOD",
            "Pdf name = " + name);
    try {
        CompletePublication first = completePubList.iterator().next();
        String fileName = FileRepositoryManager.getTemporaryPath(
                first.getPublicationDetail().getPK().getSpace(),
                first.getPublicationDetail().getPK().getComponentName()) + name;
        ResourceLocator message = new ResourceLocator(
                "com.stratelia.webactiv.newsEdito.multilang.newsEditoBundle", langue);
        // creation of the document with a certain size and certain margins
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);

        // we add some meta information to the document
        document.addAuthor("Generateur de PDF Silverpeas");
        document.addSubject("Compilation de publications Silverpeas");
        document.addCreationDate();

        PdfWriter.getInstance(document, new FileOutputStream(fileName));
        document.open();

        createFirstPage(document, langue);

        HeaderFooter header = new HeaderFooter(new Phrase(message.getString("publicationCompilation")), false);
        HeaderFooter footer = new HeaderFooter(new Phrase("Page "), new Phrase("."));

        footer.setAlignment(Element.ALIGN_CENTER);

        document.setHeader(header);
        document.setFooter(footer);

        document.newPage();

        Font titleFont = new Font(Font.HELVETICA, 24, Font.NORMAL, new Color(255, 255, 255));
        Paragraph cTitle = new Paragraph(message.getString("listPublication"), titleFont);
        Chapter chapter = new Chapter(cTitle, 1);

        Iterator<CompletePublication> i = completePubList.iterator();
        CompletePublication complete = null;
        while (i.hasNext()) {
            complete = i.next();

            addPublication(chapter, complete);
        }

        document.add(chapter);

        document.close();
    } catch (Exception e) {
        throw new NewsEditoException("PdfGenerator.generatePubList", NewsEditoException.WARNING,
                "NewsEdito.EX_PROBLEM_TO_GENERATE_PUBLI_LIST", e);
    }
}

From source file:com.stratelia.webactiv.newsEdito.control.PdfGenerator.java

License:Open Source License

/**
 * Method declaration/*from  ww  w  . j  a  v  a  2s .  c o  m*/
 * @param name
 * @param archiveDetail
 * @param publicationBm
 * @param langue
 * @throws NewsEditoException
 * @see
 */
public static void generateArchive(String name, NodeDetail archiveDetail, PublicationBm publicationBm,
        String langue) throws NewsEditoException {
    SilverTrace.info("NewsEdito", "PdfGenerator.generateArchive", "NewsEdito.MSG_ENTRY_METHOD",
            "Pdf name = " + name);
    try {
        String fileName = FileRepositoryManager.getTemporaryPath(archiveDetail.getNodePK().getSpace(),
                archiveDetail.getNodePK().getComponentName()) + name;
        // creation of the document with a certain size and certain margins
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);

        // we add some meta information to the document
        document.addAuthor("Generateur de PDF Silverpeas");
        document.addSubject("Journal Silverpeas : " + archiveDetail.getName());
        document.addCreationDate();

        PdfWriter.getInstance(document, new FileOutputStream(fileName));
        document.open();

        createFirstPage(document, langue);

        // we define a header and a footer
        String descriptionArchive = archiveDetail.getDescription();
        if (descriptionArchive == null)
            descriptionArchive = " ";

        HeaderFooter header = new HeaderFooter(new Phrase(archiveDetail.getName() + " : " + descriptionArchive),
                false);
        HeaderFooter footer = new HeaderFooter(new Phrase("Page "), new Phrase("."));

        footer.setAlignment(Element.ALIGN_CENTER);

        document.setHeader(header);
        document.setFooter(footer);

        document.newPage();

        PdfGenerator.addEditorial(document, archiveDetail, publicationBm, langue);
        PdfGenerator.addMasterTable(document, archiveDetail, publicationBm);

        document.close();
    } catch (Exception e) {
        throw new NewsEditoException("PdfGenerator.generateArchive", NewsEditoException.WARNING,
                "NewsEdito.EX_PROBLEM_TO_GENERATE_ARCHIVE", e);
    }

}

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: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!
 * /*from  w w w  . j a v a  2 s  .c om*/
 * @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.unigoettingen.sub.commons.contentlib.pdflib.PDFManager.java

License:Apache License

/***************************************************************************
 * Creates a PDF, which is streams to the OutputStream out.
 * /* ww  w .  j  a v a  2  s  . c om*/
 * @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:es.uniovi.asw.personalletter.PDFTextWritter.java

/**
 * Metadata del documento.//from  w  w w  .  j a va  2 s.c  o m
 * @param document Documento en cuestin
 */
private void addMetaData(Document document) {
    document.addTitle("My first PDF");
    document.addSubject("Using iText");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor("Lars Vogel");
    document.addCreator("Lars Vogel");
}

From source file:is.idega.idegaweb.egov.cases.business.CaseWriter.java

License:Open Source License

protected MemoryFileBuffer writePDF(IWContext iwc) {
    Font titleFont = new Font(Font.HELVETICA, 14, Font.BOLD);
    Font labelFont = new Font(Font.HELVETICA, 11, Font.BOLD);
    Font textFont = new Font(Font.HELVETICA, 11, Font.NORMAL);

    try {/*  w ww. j a  va2s .  co m*/
        MemoryFileBuffer buffer = new MemoryFileBuffer();
        MemoryOutputStream mos = new MemoryOutputStream(buffer);

        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, mos);
        document.addAuthor("Idegaweb eGov");
        document.addSubject("Case");
        document.open();
        document.newPage();

        String title = iwrb.getLocalizedString("case_overview", "Case overview");
        Paragraph cTitle = new Paragraph(title, titleFont);
        cTitle.setSpacingAfter(24);
        document.setPageCount(1);
        document.add(cTitle);

        int[] widths = { 25, 75 };
        PdfPTable table = new PdfPTable(2);
        table.setWidths(widths);
        table.getDefaultCell().setBorder(0);
        table.getDefaultCell().setPaddingBottom(8);

        CaseCategory category = theCase.getCaseCategory();
        CaseCategory parentCategory = category.getParent();
        CaseType type = theCase.getCaseType();
        User user = theCase.getOwner();
        Address address = user != null ? getUserBusiness(iwc).getUsersMainAddress(user) : null;
        PostalCode postal = null;
        if (address != null) {
            postal = address.getPostalCode();
        }
        Phone phone = null;
        if (user != null) {
            try {
                phone = getUserBusiness(iwc).getUsersHomePhone(user);
            } catch (NoPhoneFoundException e) {
                //No phone found...
            }
        }
        Email email = null;
        if (user != null) {
            try {
                email = getUserBusiness(iwc).getUsersMainEmail(user);
            } catch (NoEmailFoundException e) {
                //No email found...
            }
        }

        IWTimestamp created = new IWTimestamp(theCase.getCreated());

        if (user != null) {
            table.addCell(new Phrase(iwrb.getLocalizedString("name", "Name"), labelFont));
            table.addCell(new Phrase(
                    new Name(user.getFirstName(), user.getMiddleName(), user.getLastName()).getName(locale),
                    textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("personal_id", "Personal ID"), labelFont));
            table.addCell(new Phrase(PersonalIDFormatter.format(user.getPersonalID(), locale), textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("address", "Address"), labelFont));
            table.addCell(new Phrase(address != null ? address.getStreetAddress() : "-", textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("zip_code", "Postal code"), labelFont));
            table.addCell(new Phrase(postal != null ? postal.getPostalAddress() : "-", textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("home_phone", "Home phone"), labelFont));
            table.addCell(new Phrase(phone != null ? phone.getNumber() : "-", textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("email", "Email"), labelFont));
            table.addCell(new Phrase(email != null ? email.getEmailAddress() : "-", textFont));

            table.addCell(new Phrase(""));
            table.addCell(new Phrase(""));
            table.addCell(new Phrase(""));
            table.addCell(new Phrase(""));
        }

        table.addCell(new Phrase(iwrb.getLocalizedString("case_nr", "Case nr."), labelFont));
        table.addCell(new Phrase(theCase.getPrimaryKey().toString(), textFont));

        if (getCasesBusiness(iwc).useTypes()) {
            table.addCell(new Phrase(iwrb.getLocalizedString("case_type", "Case type"), labelFont));
            table.addCell(new Phrase(type.getName(), textFont));
        }

        if (parentCategory != null) {
            table.addCell(new Phrase(iwrb.getLocalizedString("case_category", "Case category"), labelFont));
            table.addCell(new Phrase(parentCategory.getLocalizedCategoryName(locale), textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("sub_case_category", "Case category"), labelFont));
            table.addCell(new Phrase(category.getLocalizedCategoryName(locale), textFont));
        } else {
            table.addCell(new Phrase(iwrb.getLocalizedString("case_category", "Case category"), labelFont));
            table.addCell(new Phrase(category.getLocalizedCategoryName(locale), textFont));
        }

        table.addCell(new Phrase(iwrb.getLocalizedString("created_date", "Created date"), labelFont));
        table.addCell(new Phrase(created.getLocaleDateAndTime(locale, IWTimestamp.SHORT, IWTimestamp.SHORT),
                textFont));

        if (theCase.getSubject() != null) {
            table.addCell(new Phrase(iwrb.getLocalizedString("subject", "Subject"), labelFont));
            table.addCell(new Phrase(theCase.getSubject(), textFont));
        }

        table.addCell(new Phrase(iwrb.getLocalizedString("message", "Message"), labelFont));
        table.addCell(new Phrase(theCase.getMessage(), textFont));

        if (theCase.getReference() != null) {
            table.addCell(new Phrase(iwrb.getLocalizedString("reference", "Reference"), labelFont));
            table.addCell(new Phrase(theCase.getReference(), textFont));
        }

        table.setWidthPercentage(100);
        document.add(table);

        document.close();
        try {
            mos.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        buffer.setMimeType("application/pdf");
        return buffer;

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

    return null;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

protected Document getLetterDocumentTemplate() {
    // Margins defined in millimeters:
    float headFootMarginsMM = 9.0f;
    float leftRightMarginsMM = 30.0f;

    // Margins defined in points:
    float headFootMargins = getPointsFromMM(headFootMarginsMM);
    float leftRightMargins = getPointsFromMM(leftRightMarginsMM);
    Document document = new Document(PageSize.A4, leftRightMargins, leftRightMargins, headFootMargins,
            headFootMargins);/*from  w ww  . j  av a2s  .com*/
    // document.setMargins(leftRightMargins,leftRightMargins,headFootMargins,headFootMargins);
    document.addAuthor("IdegaWeb");
    document.addSubject("PrintedLetter");
    // document.open();
    return document;
}

From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java

License:Open Source License

private static void addMetaData(Document document) {
    document.addTitle("Report Eventi");
    document.addSubject("Report Eventi selezionati nella console Govpay");
    document.addKeywords("Report, Eventi, Govpay");
    document.addAuthor("Govpay");
    document.addCreator("Govpay");
}

From source file:keel.GraphInterKeel.datacf.visualizeData.VisualizePanelCharts2D.java

License:Open Source License

private void topdfjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_topdfjButtonActionPerformed
    // Save chart as a PDF file
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Save chart");
    KeelFileFilter fileFilter = new KeelFileFilter();
    fileFilter.addExtension("pdf");
    fileFilter.setFilterName("PDF images (.pdf)");
    chooser.setFileFilter(fileFilter);/*w  ww.j a  v  a  2  s  .co  m*/
    chooser.setCurrentDirectory(Path.getFilePath());
    int opcion = chooser.showSaveDialog(this);
    Path.setFilePath(chooser.getCurrentDirectory());
    if (opcion == JFileChooser.APPROVE_OPTION) {
        String nombre = chooser.getSelectedFile().getAbsolutePath();
        if (!nombre.toLowerCase().endsWith(".pdf")) {
            // Add correct extension
            nombre += ".pdf";
        }
        File tmp = new File(nombre);
        if (!tmp.exists() || JOptionPane.showConfirmDialog(this,
                "File " + nombre + " already exists. Do you want to replace it?", "Confirm",
                JOptionPane.YES_NO_OPTION, 3) == JOptionPane.YES_OPTION) {
            try {
                Document document = new Document();
                PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(nombre));
                document.addAuthor("KEEL");
                document.addSubject("Attribute comparison");
                document.open();
                PdfContentByte cb = writer.getDirectContent();
                PdfTemplate tp = cb.createTemplate(550, 412);
                Graphics2D g2 = tp.createGraphics(550, 412, new DefaultFontMapper());
                Rectangle2D r2D = new Rectangle2D.Double(0, 0, 550, 412);
                chart2.setBackgroundPaint(Color.white);
                chart2.draw(g2, r2D);
                g2.dispose();
                cb.addTemplate(tp, 20, 350);
                document.close();
            } catch (Exception exc) {
            }
        }
    }
}