Example usage for com.itextpdf.text Document addCreator

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

Introduction

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

Prototype


public boolean addCreator(String creator) 

Source Link

Document

Adds the creator to a Document.

Usage

From source file:com.example.drivequickstart.PDFActivity.java

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:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public void createPDF(Context context) throws DocumentException, IOException {
    LicenseKey.loadLicenseFile(context.getAssets().open("itextkey.xml"));
    this.mContext = context;
    Map<String, String> pdfParams = new HashMap();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_Hmmss", Locale.US);
    dateFormat.setTimeZone(TimeZone.getDefault());
    this.filename = "txtbook_" + dateFormat.format(new Date()) + ".pdf";
    float leftMargin = Txtbook.RIGHT_MARGIN_EVEN;
    float rightMargin = Txtbook.RIGHT_MARGIN_ODD;
    if (this.settings.addFrontCover.booleanValue()) {
        leftMargin = Txtbook.RIGHT_MARGIN_ODD;
        rightMargin = Txtbook.RIGHT_MARGIN_EVEN;
    }/*  w  w w. ja va 2s  .  c  o  m*/
    Document document = new Document(PageSize.LETTER, leftMargin, rightMargin, Txtbook.TOP_MARGIN,
            Txtbook.TOP_MARGIN);
    File file = new File(Environment.getExternalStorageDirectory(), this.filename);
    if (!(file.exists() && file.canRead())) {
        file.createNewFile();
    }
    this.writer = PdfWriter.getInstance(document, new FileOutputStream(file));
    this.writer.setCompressionLevel(this.settings.compressionLevel);
    this.writer.setStrictImageSequence(true);
    FontFactory.register("assets/fonts/DroidSans.ttf");
    this.sansFont6Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 6.0f, 0,
            new BaseColor(152, 152, 152));
    this.sansFont9 = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f);
    this.sansFont9Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f, 0,
            new BaseColor(103, 103, 103));
    this.sansFont11Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 11.0f, 0,
            new BaseColor(152, 152, 152));
    FontFactory.register("assets/fonts/CourierNew.ttf");
    this.serifFont8Gray = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 8.0f, 0,
            new BaseColor(103, 103, 103));
    this.serifFont11 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 11.0f);
    this.serifFont14 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 14.0f);
    this.serifFont24 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 24.0f);
    document.open();
    document.setMarginMirroring(true);
    document.addCreationDate();
    document.addCreator("Created with txt-book for Android www.txt-book.com");
    document.addTitle("txt-book for Android");
    if (this.settings.bookStyle == 1) {
        ConversationHeaderFooter hf = new ConversationHeaderFooter();
        hf.footerFont = this.sansFont9;
        hf.hasFrontCover = this.settings.addFrontCover;
        this.writer.setPageEvent(hf);
    } else {
        StorybookHeaderFooter hf2 = new StorybookHeaderFooter();
        hf2.title = this.settings.bookCoverTitle;
        hf2.headerFont = this.serifFont8Gray;
        hf2.hasFrontCover = this.settings.addFrontCover;
        this.writer.setPageEvent(hf2);
    }
    if (this.settings.addFrontCover.booleanValue()) {
        createFrontCoverPage(document, this.settings.bookCoverTitle,
                this.settings.addFrontCoverImage.booleanValue() ? this.settings.coverPhoto : null);
        pdfParams.put("PDF Front Cover", "YES");
    } else {
        pdfParams.put("PDF Front Cover", "NO");
    }
    if (this.settings.addFrontCoverImage.booleanValue()) {
        pdfParams.put("PDF Front Cover Image", "YES");
    } else {
        pdfParams.put("PDF Front Cover Image", "NO");
    }
    if (this.settings.bookStyle == 1) {
        createContentPagesConversation(document);
    } else {
        createContentPagesStorybook(document, this.settings.bookCoverTitle);
    }
    int pages = this.writer.getPageNumber();
    if (this.settings.bookStyle == 2) {
        ((StorybookHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true);
    } else {
        ((ConversationHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true);
    }
    if (this.settings.addBackCover.booleanValue()) {
        pages++;
        pdfParams.put("PDF Back Cover", "YES");
        if (pages % 2 == 1) {
            createBlankSpacerPage(document);
        }
        createBackCoverPage(document, this.settings.backCoverNote);
    } else {
        pdfParams.put("PDF Back Cover", "NO");
        if (pages % 2 == 1) {
            createBlankSpacerPage(document);
        }
    }
    if (this.settings.bookStyle == 2) {
        pdfParams.put("PDF Style", "Storybook");
    } else {
        pdfParams.put("PDF Style", "Conversation");
    }
    pdfParams.put("PDF Num Pages", Integer.valueOf(this.writer.getPageNumber()).toString());
    document.close();
    FlurryAgent.logEvent("PDF_CREATED", (Map) pdfParams);
}

From source file:com.iox.rms.mbean.UserBean.java

@SuppressWarnings("deprecation")
private byte[] generateInvoiceForCustomerPurchase(CustomerProduct cp) {
    byte[] data = null;

    if (cp != null) {
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {/*ww  w . ja  v  a  2 s.c o  m*/
            PdfWriter writer = PdfWriter.getInstance(document, baos);
            writer.setPageEvent(new HeaderFooter());
            writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
            if (!document.isOpen()) {
                document.open();
            }
            document.setPageSize(PageSize.A4);
            document.addAuthor("AutoLife");
            document.addCreationDate();
            document.addCreator("AutoLife");
            document.addSubject("Invoice");
            document.addTitle("Purchase Invoice");

            PdfPTable headerTable = new PdfPTable(3);

            ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance()
                    .getExternalContext().getContext();
            String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator
                    + "sattrak-logo.png";
            PdfPCell c = new PdfPCell(Image.getInstance(logo));
            c.setBorder(0);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);

            BaseFont helvetica = null;
            try {
                helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
            } catch (Exception e) {
            }
            Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);
            c = new PdfPCell(new Paragraph("INVOICE", font));
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            font = new Font(helvetica, 10, Font.NORMAL | Font.BOLD);
            c = new PdfPCell(new Paragraph("TRANSACTION REF. NO.: " + cp.getPurchaseTranRef(), font));
            c.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            c.setBorder(0);
            headerTable.addCell(c);

            document.add(headerTable);

            font = new Font(helvetica, 12, Font.NORMAL | Font.BOLD);
            Paragraph p = new Paragraph("DETAILS", font);
            p.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(p);

            PdfPTable pdfTable = new PdfPTable(3);

            font = new Font(helvetica, 8, Font.BOLDITALIC);
            pdfTable.addCell(new Paragraph("INITIATED DATE", font));
            pdfTable.addCell(new Paragraph("PRODUCT", font));
            pdfTable.addCell(new Paragraph("AMOUNT", font));
            font = new Font(helvetica, 8, Font.NORMAL);
            pdfTable.addCell(
                    new Paragraph(cp.getPurchaseTransaction().getTranInitDate().toLocaleString(), font));
            pdfTable.addCell(new Paragraph(cp.getProductBooked().getDetails(), font));
            pdfTable.addCell(new Paragraph("" + cp.getPurchasedAmount(), font));
            document.add(pdfTable);

            document.close();

            data = baos.toByteArray();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    return data;
}

From source file:com.khepry.frackhem.fxml.FracKhemGUIController.java

License:Apache License

private void saveTextAsPDF(String content, File file)
        throws FileNotFoundException, DocumentException, IOException, InterruptedException {
    Document document = new Document(PageSize.A4.rotate());
    PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(file));
    document.open();//ww w  .  ja va  2s. c o m
    document.addAuthor("Author of the Doc");
    document.addCreator("Creator of the Doc");
    document.addSubject("Subject of the Doc");
    document.addCreationDate();
    document.addTitle(file.getName());
    String html = htmlHeader.concat(markdown4jProcessor.process(content.trim()));
    //        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, new ByteArrayInputStream(html.getBytes("UTF-8")), this.getClass().getResourceAsStream(cssFileFullPath));
    XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document,
            new ByteArrayInputStream(html.getBytes("UTF-8")));
    document.close();
    pdfWriter.close();
    displayFile(file.getAbsolutePath(), sleepMillis);
}

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 www  . j  a  v  a 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  w w . java  2  s.  c  o m*/

    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);/*from w  w  w . ja va2s.  c om*/
    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;//from  w w w. j a  v  a  2s  .co 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");
}