Example usage for com.itextpdf.text Document addSubject

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

Introduction

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

Prototype


public boolean addSubject(String subject) 

Source Link

Document

Adds the subject to a Document.

Usage

From source file:com.dexter.fuelcard.mbean.UtilMBean.java

public byte[] createInvoicePDF(int pageType, String title, String dateperiod, String amount, String chargeType,
        String chargeAmount, String total) {
    try {//from   w  w w.  java 2s  .c om
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FUELCARD");
        document.addCreationDate();
        document.addCreator("FUELCARD");
        document.addSubject("Invoice");
        document.addTitle(title);

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        PdfPCell c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(title, font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (dateperiod != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("For " + dateperiod, font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = new PdfPTable(4);
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Charge Type", font)); // % per transaction or flat per license
        pdfTable.addCell(new Paragraph("Charge Amount", font)); // the amount of the charge setting

        if (chargeType.equalsIgnoreCase("Percent-Per-Tran")) {
            pdfTable.addCell(new Paragraph("Total Amount", font)); // the amount of the charge setting
        } else {
            pdfTable.addCell(new Paragraph("Total License", font)); // the amount of the charge setting
        }
        //pdfTable.addCell(new Paragraph("Description", font)); // the 
        pdfTable.addCell(new Paragraph("Amount Due", font));

        font = new Font(helvetica, 8, Font.NORMAL);
        pdfTable.addCell(new Paragraph(chargeType, font));
        pdfTable.addCell(new Paragraph(chargeAmount, font));
        pdfTable.addCell(new Paragraph(total, font));
        pdfTable.addCell(new Paragraph(amount, font));

        pdfTable.setWidthPercentage(100);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();

        return baos.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.docdoku.server.extras.TitleBlockGenerator.java

License:Open Source License

protected void addMetaData(Document document) {
    document.addTitle(title);/*from  w  w  w  . j a  v  a  2s  .com*/
    document.addSubject(subject);
    document.addKeywords(keywords);
    document.addAuthor(authorName);
    document.addCreator(authorName);
}

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.github.albfernandez.joinpdf.JoinPdf.java

License:Open Source License

private void setParametersAndHeaders(final PdfWriter writer, final Document document) throws DocumentException {
    if (this.extraCompression) {
        writer.setFullCompression();/*from  ww  w  .j a v  a2s. co  m*/
    }
    if (this.isCrypt() && bouncyCastleLoaded) {
        int permisos = PdfWriter.ALLOW_PRINTING;
        writer.setEncryption(null, null, permisos, PdfWriter.ENCRYPTION_AES_128);
    }
    if (!StringUtils.isBlank(this.getMetadataAuthor())) {
        document.addAuthor(this.getMetadataAuthor());
    }
    if (!StringUtils.isBlank(this.getMetadataKeywords())) {
        document.addKeywords(this.getMetadataKeywords());
    }
    if (!StringUtils.isBlank(this.getMetadataTitle())) {
        document.addTitle(this.getMetadataTitle());
    }
    if (!StringUtils.isBlank(this.getMetadataSubject())) {
        document.addSubject(this.getMetadataSubject());
    }
}

From source file:com.github.sgelb.sldownloader.model.Pdf.java

License:Open Source License

public void mergePdfs() throws DocumentException, IOException {
    String title = book.getPdfTitle() + ".pdf";
    File saveFile = new File(saveFolder, title);

    int count = 1;
    while (saveFile.exists()) {
        title = book.getPdfTitle() + "_" + count++ + ".pdf";
        saveFile = new File(saveFolder, title);
    }/*from w  w w  .ja  v a2  s  .c om*/
    book.setInfo("saveFile", saveFile.toString());

    Document document = new Document();
    PdfCopy destPdf = new PdfCopy(document, new FileOutputStream(saveFile));
    document.open();
    PdfReader reader;
    int page_offset = 0;
    int n;
    ArrayList<HashMap<String, Object>> bookmarks = new ArrayList<HashMap<String, Object>>();
    List<HashMap<String, Object>> tmp;

    count = 1;
    System.out.println("Start mergin\u2026");
    for (File srcPdf : src) {

        if (Thread.interrupted()) {
            return;
        }

        System.out.print(":: " + count++ + "/" + src.size());
        reader = new PdfReader(srcPdf.toString());

        tmp = SimpleBookmark.getBookmark(reader);
        if (tmp != null) {
            SimpleBookmark.shiftPageNumbers(tmp, page_offset, null);
            bookmarks.addAll(tmp);
        }

        n = reader.getNumberOfPages();
        page_offset += n;
        for (int page = 0; page < n;) {
            destPdf.addPage(destPdf.getImportedPage(reader, ++page));
        }
        destPdf.freeReader(reader);
        reader.close();
        System.out.println(" succeed.");
    }
    if (!bookmarks.isEmpty()) {
        destPdf.setOutlines(bookmarks);
    }

    if (book.getInfo("author") != null)
        document.addAuthor(book.getInfo("author"));
    if (book.getInfo("title") != null)
        document.addTitle(book.getInfo("title"));
    if (book.getInfo("subtitle") != null)
        document.addSubject(book.getInfo("subtitle"));
    document.close();

    System.out.println("Merge complete. Saved to " + saveFile);
}

From source file:com.horizzon.inventerium.ExportPdf.java

private static void addMetaData(Document document) {
    document.addTitle("Transaction Details");
    document.addSubject("Detailed transaction");
    //  document.addKeywords("Java, PDF, iText");
    //  document.addAuthor("Lars Vogel");
    //  document.addCreator("Lars Vogel");
}

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 {//  w  ww . ja v  a2  s.c om
            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();/*w w w  . ja  v a 2 s  .com*/
    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.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  ww w  . j a  v  a  2s.  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);/*w  w  w  .  j a  v a2 s  .  co  m*/
    document.addCreator("Created with iTextG under the APGL");
}