Example usage for com.itextpdf.text Document addAuthor

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

Introduction

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

Prototype


public boolean addAuthor(String author) 

Source Link

Document

Adds the author to a Document.

Usage

From source file:com.maxl.java.amikodesk.SaveBasket.java

License:Open Source License

public void generatePdf(Author author, String filename, String type) {
    // A4: 8.267in x 11.692in => 595.224units x 841.824units (72units/inch)

    // marginLeft, marginRight, marginTop, marginBottom
    Document document = new Document(PageSize.A4, 50, 50, 80, 50);
    try {//from w  w  w  .  j a va 2 s  . com
        if (m_shopping_basket.size() > 0) {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
            writer.setBoxSize("art", new Rectangle(50, 50, 560, 790));

            HeaderFooter event = new HeaderFooter();
            writer.setPageEvent(event);

            document.open();

            PdfContentByte cb = writer.getDirectContent();

            document.addAuthor("ywesee GmbH");
            document.addCreator("AmiKo for Windows");
            document.addCreationDate();

            // Logo
            String logoImageStr = m_prefs.get(LogoImageID, Constants.IMG_FOLDER + "empty_logo.png");
            File logoFile = new File(logoImageStr);
            if (!logoFile.exists())
                logoImageStr = Constants.IMG_FOLDER + "empty_logo.png";

            Image logo = Image.getInstance(logoImageStr);
            logo.scalePercent(30);
            logo.setAlignment(Rectangle.ALIGN_RIGHT);
            document.add(logo);
            document.add(Chunk.NEWLINE);

            // Bestelladresse
            // --> String bestellAdrStr = m_prefs.get(BestellAdresseID, m_rb.getString("noaddress1")); 
            String bestellAdrStr = getAddressAsString(BestellAdresseID);
            Paragraph p = new Paragraph(12);
            // p.setIndentationLeft(60);
            p.add(new Chunk(bestellAdrStr, font_norm_10));
            document.add(p);
            document.add(Chunk.NEWLINE);

            // Title
            p = new Paragraph(m_rb.getString("order"), font_bold_16);
            document.add(p);

            // Date
            DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            Date date = new Date();
            p = new Paragraph(m_rb.getString("date") + ": " + dateFormat.format(date), font_bold_10);
            p.setSpacingAfter(20);
            document.add(p);

            // document.add(Chunk.NEWLINE);

            // Add addresses (Lieferadresse + Rechnungsadresse)
            /* --> OLD
            String lieferAdrStr = m_prefs.get(LieferAdresseID, m_rb.getString("noaddress2"));
            String rechnungsAdrStr = m_prefs.get(RechnungsAdresseID, m_rb.getString("noaddress3"));              
            */
            // --> NEW
            String lieferAdrStr = getAddressAsString(LieferAdresseID);
            String rechnungsAdrStr = getAddressAsString(RechnungsAdresseID);

            PdfPTable addressTable = new PdfPTable(new float[] { 1, 1 });
            addressTable.setWidthPercentage(100f);
            addressTable.getDefaultCell().setPadding(5);
            addressTable.setSpacingAfter(5f);
            addressTable.addCell(getStringCell(m_rb.getString("shipaddress"), font_bold_10, PdfPCell.NO_BORDER,
                    Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(getStringCell(m_rb.getString("billaddress"), font_bold_10, PdfPCell.NO_BORDER,
                    Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(
                    getStringCell(lieferAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(
                    getStringCell(rechnungsAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
            document.add(addressTable);

            document.add(Chunk.NEWLINE);

            // Add shopping basket
            if (type.equals("specific"))
                document.add(getShoppingBasketForAuthor(author, cb));
            else if (type.equals("all"))
                document.add(getFullShoppingBasket(cb, "all"));
            else if (type.equals("rest"))
                document.add(getFullShoppingBasket(cb, "rest"));
            LineSeparator separator = new LineSeparator();
            document.add(separator);
        }
    } catch (IOException e) {

    } catch (DocumentException e) {

    }

    document.close();
    // System.out.println("Saved PDF to " + filename);
}

From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java

License:Open Source License

public int handle(final User user, final User manager, final ExpenseNote en)
        throws MalformedURLException, IOException, DocumentException {

    log.info("Building list of expenses ...");
    List<Expense> expenses = Expense.list(en);
    log.info("Retrieved " + expenses.size() + " expenses from the datastore");

    log.info("Creating ExpenseNoteDocOutputStream");
    ExpenseNoteDocOutputStream stream = new ExpenseNoteDocOutputStream(en);

    Document document = new Document();
    PdfWriter.getInstance(document, stream);
    document.open();/*from w  ww  .j a  va2s  .com*/

    document.addTitle("Expense note " + en.id + " of " + user.name);
    document.addSubject("Expense note generated by Rogerthat Enterprise!");
    document.addKeywords("expense note");
    document.addAuthor(user.name);
    document.addCreator("Rogerthat OneApp Enterprise Mobility");

    Paragraph preface = new Paragraph();

    preface.add(new Paragraph("TP Vision expense note", titleFont));
    preface.add(new Paragraph(" "));

    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    Date date = new Date();
    preface.add(new Paragraph("Date: " + dateFormat.format(date)));
    preface.add(new Paragraph("Requestor: " + user.name));
    preface.add(new Paragraph("Approver: " + manager.name));
    preface.add(new Paragraph(" "));

    PdfPTable table = new PdfPTable(7);
    table.setWidthPercentage(110);
    table.setWidths(new int[] { 5, 15, 15, 35, 10, 15, 10 });
    addHeader(table, "Id");
    addHeader(table, "Date");
    addHeader(table, "Nature");
    addHeader(table, "Description");
    addHeader(table, "Account");
    addHeader(table, "Amount");
    addHeader(table, "Voucher");
    table.setHeaderRows(1);

    Collections.sort(expenses, new Comparator<Expense>() {
        @Override
        public int compare(Expense e1, Expense e2) {
            return (int) (e1.date - e2.date);
        }
    });
    int i = 0;
    double total = 0;
    for (Expense expense : expenses) {
        PdfPCell c1 = new PdfPCell(new Phrase("" + ++i));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        table.addCell(dateFormat.format(new Date(expense.date * 1000)));
        table.addCell(expense.nature);
        table.addCell(expense.description);
        table.addCell("" + expense.account);
        c1 = new PdfPCell(new Phrase(DECIMAL_FORMAT.format(expense.amount) + " " + expense.currency));
        c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(c1);
        table.addCell(expense.voucher);
        total += expense.amount;
    }

    preface.add(table);

    preface.add(new Paragraph(" "));
    preface.add(new Paragraph("Total: " + DECIMAL_FORMAT.format(total), titleFont));

    document.add(preface);

    i = 0;
    for (Expense expense : expenses) {
        i++;
        if (expense.receipt == null)
            continue;

        document.newPage();
        Paragraph receipt = new Paragraph();
        receipt.add(new Paragraph("Attachment " + i, titleFont));
        document.add(receipt);
        Image image = Image.getInstance(new URL(expense.receipt));
        image.setRotationDegrees(-90);
        float scaler = (document.getPageSize().getWidth() / image.getWidth()) * 100;

        image.scalePercent(scaler);
        document.add(image);
    }

    document.close();
    stream.close();

    return stream.getSize();

}

From source file:com.mstoyanov.music_lessons.pdf.CreatePDF.java

License:Open Source License

private static void addMetaData(Document document) {
    document.addTitle("Music School");
    document.addSubject("Music Lessons Weekly Schedule");
    document.addKeywords("Piano, Music Theory, Lessons");
    document.addAuthor(name);
    document.addCreator("Created with iTextG under the APGL");
}

From source file:com.mycompany.mavenproject1.Createpdf.java

public void createPDF(String pdfFilename) {

    Document doc = new Document();
    PdfWriter docWriter = null;//w w w.ja v a 2  s . c  o m
    initializeFonts();

    try {
        String path = "C:\\Users\\Thaskioglu\\Downloads\\" + pdfFilename;
        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path));
        doc.addAuthor("FabulousCar");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("FabulousCar");
        doc.addTitle("Invoice");
        doc.setPageSize(PageSize.LETTER);

        doc.open();
        PdfContentByte cb = docWriter.getDirectContent();

        boolean beginPage = true;
        int y = 0;

        for (int i = 0; i < 100; i++) {
            if (beginPage) {
                beginPage = false;
                generateLayout(doc, cb);
                generateHeader(doc, cb);
                y = 615;
            }
            generateDetail(doc, cb, i, y);
            y = y - 15;
            if (y < 50) {
                printPageNumber(cb);
                doc.newPage();
                beginPage = true;
            }
        }
        printPageNumber(cb);

    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (doc != null) {
            doc.close();
        }
        if (docWriter != null) {
            docWriter.close();
        }
    }
}

From source file:com.mycompany.mavenproject2.VirtualkeyController.java

private static void addMetaData(Document document) {
    document.addTitle("Item");
    document.addSubject("Item History ");
    document.addKeywords("Item, History, POS");
    document.addAuthor("Store Name");
    document.addCreator("Germanium Inc.");
}

From source file:com.photoshop.misc.Factuurgenerator.java

private void addMetaData(Document document) {
    document.addTitle("Factuur: " + order.getId()); //Moet order nummer uit database worden
    document.addAuthor("Photowinkel");
    document.addCreator("Photowinkel");
}

From source file:com.photoshop.misc.Indexkaartgenerator.java

private void addMetaData(Document document) {
    document.addTitle("Indexkaart: " + order.getId()); //Moet order nummer uit database worden
    document.addAuthor("Fotowinkel"); // naam fotograaf
    document.addCreator("Fotowinkel");
}

From source file:com.planning.project.controller.CreatePDF.java

private static void addMetaData(Document document) {
    document.addTitle("Generate PDF report");
    document.addSubject("Generate PDF report");
    document.addAuthor("Java Honk");
    document.addCreator("Java Honk");
}

From source file:com.propelics.pdfcreator.PdfcreatorModule.java

License:Open Source License

/**
 * @method generatePDFWithHTML// www . j a  v  a 2s  .  c o m
 * Generates a PDF with the given file name, based on a HTML file
 * @param {String} filename Name of the PDF file
 * @param {String} html String with the HTML
 * @param {String} [author] Author for metadata
 * Fires a "complete" event when the PDF is generated
 * Fires a "error" event when a error is presented
 */
@Kroll.method(runOnUiThread = true)
public void generatePDFWithHTML(final HashMap args) {
    Log.d(PROXY_NAME, "generatePDFWithHTML()");

    String html = "";
    String author = "";
    String filename = "";
    final float marginPt = 28.35f;//1cm == 28.35pt

    try {
        if (args.containsKey("filename")) {
            filename = (String) args.get("filename");
            Log.d(PROXY_NAME, "filename: " + filename);
        } else
            return;

        if (args.containsKey("html")) {
            html = (String) args.get("html");
            Log.d(PROXY_NAME, "html: " + html);
        } else
            return;

        if (args.containsKey("author")) {
            author = (String) args.get("author");
            Log.d(PROXY_NAME, "author: " + author);
        }

        //create a new document
        Document document = new Document(PageSize.LETTER, marginPt, marginPt, marginPt, 0);
        TiBaseFile file = TiFileFactory.createTitaniumFile(filename, true);

        // Parse to XHTML
        StringWriter xhtmlWriter = new StringWriter();
        Tidy tidy = new Tidy();

        // tidy.setXHTML(true);
        tidy.setXmlOut(true);
        tidy.parse(new StringReader(html), xhtmlWriter);
        String xhtml = xhtmlWriter.toString();

        //get Instance of the PDFWriter
        PdfWriter pdfWriter = PdfWriter.getInstance(document, file.getOutputStream());

        //document header attributes
        document.addAuthor(author);
        document.addCreationDate();
        document.setPageSize(PageSize.LETTER);

        //open document
        document.open();

        // From Stack Overflow lol

        MyFontFactory fontFactory = new MyFontFactory();
        FontFactory.setFontImp(fontFactory);

        // HtmlPipelineContext htmlContext = new HtmlPipelineContext(new CssAppliersImpl(fontFactory));
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
        Pipeline<?> pipeline = new CssResolverPipeline(cssResolver,
                new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, pdfWriter)));
        XMLWorker worker = new XMLWorker(pipeline, true);
        XMLParser p = new XMLParser(worker);
        p.parse(new StringReader(xhtml));

        // Finish SO c&P

        // Older code
        /*
        // Font Provider creation
        MyFontFactory fontProvider = new MyFontFactory();
        // fontProvider.register("/DroidSans.ttf");
                
        //get the XMLWorkerHelper Instance
        XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
        //convert to PDF
        worker.parseXHtml(pdfWriter, document, new ByteArrayInputStream(xhtml.getBytes("UTF-8")), null, fontProvider); //Load xhtml
        */

        //close the document
        document.close();
        //close the writer
        pdfWriter.close();

        sendCompleteEvent(filename);

    } catch (Exception e) {
        sendErrorEvent(e);
    }
}

From source file:com.sarav.donormgmttool.EmailWithPdf.java

/**
 * Writes the content of a PDF file (using iText API)
 * to the {@link OutputStream}./*ww w.  ja  v  a2 s . c  o m*/
 * @param outputStream {@link OutputStream}.
 * @throws Exception
 */
public void writePdf(OutputStream outputStream) throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, outputStream);

    document.open();

    document.addTitle("Test PDF");
    document.addSubject("Testing email PDF");
    document.addKeywords("iText, email");
    document.addAuthor("Jee Vang");
    document.addCreator("Jee Vang");

    Paragraph paragraph = new Paragraph();
    paragraph.add(new Chunk("hello!"));
    document.add(paragraph);

    document.close();
}