Example usage for com.lowagie.text Document addAuthor

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

Introduction

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

Prototype


public boolean addAuthor(String author) 

Source Link

Document

Adds the author to a Document.

Usage

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 {//from   w ww  .  j  a v a2  s  .  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 w  w  .  j  a va 2 s  .c  o m
    // 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:it.prato.comune.tolomeo.web.TolomeoPrintPDFServlet.java

License:Open Source License

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LogInterface logger = getLogger(request);

    String titolo = request.getParameter("titolo");
    String descrizione = request.getParameter("descrizione");
    String scala = request.getParameter("scala");
    String mapx = request.getParameter("mapx");
    String mapy = request.getParameter("mapy");
    //creo URL alla mappa
    URL urlMappa = new URL(URLDecoder.decode(request.getParameter("urlMappa"), "UTF-8"));
    URI uriMappa = null;// w  w w .  ja v a  2  s.c  o m
    try {
        uriMappa = new URI(urlMappa.getProtocol(), null, urlMappa.getHost(), urlMappa.getPort(),
                urlMappa.getPath(), urlMappa.getQuery() + "&mode=map&scale=" + scala + "&mapxy=" + mapx + "+"
                        + mapy + "&map_size=500 500",
                null);
        logger.info("URI di stampa mappa: " + uriMappa);
    } catch (URISyntaxException e) {
        logger.error("URI errore di sintassi", e);
    }

    Font BOLD15 = new Font(Font.HELVETICA, 15, Font.BOLD);
    Font FONT12 = new Font(Font.HELVETICA, 12, Font.NORMAL);
    Font FONT10 = new Font(Font.HELVETICA, 10, Font.NORMAL);

    Document doc = new Document();
    ;
    PdfWriter pdf = null;
    Paragraph par = new Paragraph();

    try {

        //creo il PDF
        response.setContentType("application/pdf");
        pdf = PdfWriter.getInstance(doc, response.getOutputStream());

        //attributi file
        doc.addTitle("Mappa di Prato");
        doc.addAuthor("Comune di Prato");
        doc.open();

        //intestazione
        par.setAlignment(Paragraph.ALIGN_CENTER);
        print("Comune di Prato", BOLD15, par, doc);
        print(titolo, FONT10, par, doc);
        print("", FONT10, par, doc);

        //mappa
        Image mappa = Image.getInstance(uriMappa.toURL());
        mappa.setAlignment(Image.MIDDLE);
        mappa.setBorder(Rectangle.BOX);
        mappa.setBorderWidth(1f);
        doc.add(mappa);

    } catch (Exception e) {
        logger.error("Errore durante la creazione del PDF", e);
        printErr(doc);
    } finally {
        doc.close();
        pdf.close();
        response.getOutputStream().close();
    }
}

From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java

License:Apache License

public void save(OutputStream out, ReportBook reportBook) throws SaveReportException {

    double oldScaleX = GraphicUtil.getScaleX();
    double oldScaleY = GraphicUtil.getScaleY();
    try {//  w  ww  .  j  a v  a2s.  c o m
        GraphicUtil.setScaleX(1);
        GraphicUtil.setScaleY(1);

        ReportPage pageFormat;
        int i = 0;
        while (i < reportBook.size() - 1 && !reportBook.getReportModel(i).isVisible()) {
            i++;
        }

        pageFormat = reportBook.getReportModel(i).getReportPage();

        Paper paper = pageFormat.getPaper();
        Rectangle pageSize = new Rectangle(Math.round((float) paper.getWidth()),
                Math.round((float) paper.getHeight()));
        if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) {
            pageSize = pageSize.rotate();
        }
        Document document = new Document(pageSize, Math.round((float) pageFormat.getLeftMargin(Units.PT)),
                Math.round((float) pageFormat.getRightMargin(Units.PT)),
                Math.round((float) pageFormat.getTopMargin(Units.PT)),
                Math.round((float) pageFormat.getBottomMargin(Units.PT)));
        try {
            com.lowagie.text.pdf.PdfWriter.getInstance(document, out);
            document.addTitle(reportBook.getReportCaption());
            document.addCreator("JDBReport using iText");
            document.addAuthor(System.getProperty("user.name"));
            document.open();
            int listCount = 0;
            try {
                for (ReportModel model : reportBook) {
                    if (model.isVisible()) {
                        listCount = saveSheet(document, listCount, model);
                    }
                }
                document.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (DocumentException e) {
            throw new SaveReportException(e);
        }
    } finally {
        GraphicUtil.setScaleX(oldScaleX);
        GraphicUtil.setScaleY(oldScaleY);
    }
}

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);/*from   w w w  . j  av a2s .  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) {
            }
        }
    }
}

From source file:knop.psfj.exporter.PDFSumUpExporter.java

License:Open Source License

/**
 * Adds the title./*www  .j  av  a 2s  . c  o m*/
 * 
 * @param document
 *           the document
 */
private void addTitle(Document document) {

    ReportSections rs = new ReportSections();
    try {
        document.addTitle("PSFj Report");
        document.addAuthor("PSFj");

        document.add(rs.bigTitle("PSFj Report"));
        document.add(rs.littleNote(FileUtils.getTodayDate()));

    } catch (Exception e) {
        System.err.println("Error when adding title to the report");
        e.printStackTrace();
    }
}

From source file:managedbean.afos.FlightDutyBacking.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();/*from w  w w. j  a  va2  s.  c om*/
    pdf.setPageSize(PageSize.A4);
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
            + File.separator + "logo.png";
    Image logoImg = Image.getInstance(logo);
    logoImg.scalePercent(20f);
    SimpleDateFormat sdf = new SimpleDateFormat("E, dd/MM/yyyy 'at' hh:mm:ss a");

    Font titleFont = new Font();
    Font subtitleFont = new Font();
    titleFont.setSize(16);
    titleFont.setStyle(Font.BOLD);
    subtitleFont.setSize(12);
    subtitleFont.setStyle(Font.BOLD);

    Paragraph title = new Paragraph(flightReport.getType() + " Duty Report", titleFont);
    title.setAlignment(Element.ALIGN_CENTER);
    title.setSpacingAfter(12f);

    Paragraph subTitle1 = new Paragraph("Flight Information:", subtitleFont);
    subTitle1.setSpacingAfter(8f);

    Paragraph subTitle2 = new Paragraph(flightReport.getType() + " Checklist:", subtitleFont);
    subTitle2.setSpacingBefore(12f);
    subTitle2.setSpacingAfter(12f);

    com.lowagie.text.List list = new com.lowagie.text.List(true, 15);
    list.setLettered(true);
    list.add("Flight: " + selectedFlightSchedule.getFlight().getFlightNo());
    list.add("Return Flight: " + selectedFlightSchedule.getFlight().getReturnedFlight().getFlightNo());
    Airport departure, arrival;
    departure = selectedFlightSchedule.getLeg().getDepartAirport();
    arrival = selectedFlightSchedule.getLeg().getArrivalAirport();
    sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(departure)));
    list.add("Departure Time: " + sdf.format(selectedFlightSchedule.getDepartDate()) + " ("
            + departure.getCity().getCityName() + " Time)");
    sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(arrival)));
    list.add("Arrival Time: " + sdf.format(selectedFlightSchedule.getArrivalDate()) + " ("
            + arrival.getCity().getCityName() + " Time)");
    list.add("Origin: " + departure.getCity().getCityName() + " (" + departure.getAirportName() + ")");
    list.add("Destination: " + arrival.getCity().getCityName() + " (" + arrival.getAirportName() + ")");

    pdf.add(logoImg);
    pdf.add(new Paragraph(" "));
    pdf.add(title);
    pdf.add(subTitle1);
    pdf.add(list);
    pdf.add(subTitle2);
    pdf.setMargins(72, 72, 72, 72);
    pdf.addAuthor("Merlion Airline");
    pdf.addCreationDate();
    sdf.applyPattern("dd/MM/yyyy_hh:mm:ss");
    pdf.addTitle("Post-Flight Duty Report_" + selectedFlightSchedule.getFlight().getFlightNo() + "_"
            + sdf.format(selectedFlightSchedule.getDepartDate()));
}

From source file:mesquite.lib.MesquitePDFFile.java

License:Open Source License

/**
 *@arg document Document object representing the output file
 * Add metadata to the PDF fle//from w  ww.j av a  2s . c om
 */
private void addMetaData(Document document) {
    document.addCreator(
            "Mesquite " + MesquiteModule.getMesquiteVersion() + " using portions of " + document.getVersion());
    try {
        String uname = System.getProperty("user.name");
        document.addAuthor(uname);
    } catch (SecurityException e) {
        document.addAuthor("Unknown");
    }
    document.addKeywords("Mesquite"); // more later
    //document.addTitle(this.component.getParent().getName());  // ToDo: get the window's actual title 
}

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

public void buildPDF(MimeMessage message, String replyURL, OutputStream pdfStream)
        throws DocumentException, MessagingException, IOException {
    Document document = createDocument();

    PdfWriter pdfWriter = createPdfWriter(document, pdfStream);

    document.open();/*from   w  w  w  .java 2 s.c  o m*/

    String[] froms = null;

    try {
        froms = EmailAddressUtils.addressesToStrings(message.getFrom(), true /* mime decode */);
    } catch (MessagingException e) {
        logger.warn("From address is not a valid email address.");
    }

    if (froms != null) {
        for (String from : froms) {
            document.addAuthor(from);
        }
    }

    String subject = null;

    try {
        subject = message.getSubject();
    } catch (MessagingException e) {
        logger.error("Error getting subject.", e);
    }

    if (subject != null) {
        document.addSubject(subject);
        document.addTitle(subject);
    }

    String[] tos = null;

    try {
        tos = EmailAddressUtils.addressesToStrings(message.getRecipients(RecipientType.TO),
                true /* mime decode */);
    } catch (MessagingException e) {
        logger.warn("To is not a valid email address.");
    }

    String[] ccs = null;

    try {
        ccs = EmailAddressUtils.addressesToStrings(message.getRecipients(RecipientType.CC),
                true /* mime decode */);
    } catch (MessagingException e) {
        logger.warn("CC is not a valid email address.");
    }

    Date sentDate = null;

    try {
        sentDate = message.getSentDate();
    } catch (MessagingException e) {
        logger.error("Error getting sent date.", e);
    }

    Collection<Part> attachments = new LinkedList<Part>();

    String body = BodyPartUtils.getPlainBodyAndAttachments(message, attachments);

    attachments = preprocessAttachments(attachments);

    if (body == null) {
        body = MISSING_BODY;
    }

    /*
     * PDF does not have tab support so we convert tabs to spaces
     */
    body = StringReplaceUtils.replaceTabsWithSpaces(body, tabWidth);

    PdfPTable headerTable = new PdfPTable(2);

    headerTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    headerTable.setWidthPercentage(100);
    headerTable.setWidths(new int[] { 1, 6 });
    headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    Font headerFont = createHeaderFont();

    FontSelector headerFontSelector = createHeaderFontSelector();

    PdfPCell cell = new PdfPCell(new Paragraph("From:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);

    String decodedFroms = StringUtils.defaultString(StringUtils.join(froms, ", "));

    headerTable.addCell(headerFontSelector.process(decodedFroms));

    cell = new PdfPCell(new Paragraph("To:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(StringUtils.join(tos, ", "))));

    cell = new PdfPCell(new Paragraph("CC:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(StringUtils.join(ccs, ", "))));

    cell = new PdfPCell(new Paragraph("Subject:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(subject)));

    cell = new PdfPCell(new Paragraph("Date:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable.addCell(ObjectUtils.toString(sentDate));

    cell = new PdfPCell(new Paragraph("Attachments:", headerFont));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

    headerTable.addCell(cell);
    headerTable
            .addCell(headerFontSelector.process(StringUtils.defaultString(getAttachmentHeader(attachments))));

    document.add(headerTable);

    if (replyURL != null) {
        addReplyLink(document, replyURL);
    }

    /*
     * Body table will contain the body of the message
     */
    PdfPTable bodyTable = new PdfPTable(1);
    bodyTable.setWidthPercentage(100f);

    bodyTable.setSplitLate(false);

    bodyTable.setSpacingBefore(15f);
    bodyTable.setHorizontalAlignment(Element.ALIGN_LEFT);

    addBodyAndAttachments(pdfWriter, document, bodyTable, body, attachments);

    Phrase footer = new Phrase(FOOTER_TEXT);

    PdfContentByte cb = pdfWriter.getDirectContent();

    ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, footer, document.right(), document.bottom(), 0);

    document.close();
}