Example usage for com.lowagie.text Document addCreator

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

Introduction

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

Prototype


public boolean addCreator(String creator) 

Source Link

Document

Adds the creator to a Document.

Usage

From source file:com.matic.sudoku.io.export.PdfExporter.java

License:Open Source License

/**
 * Generate and export multiple boards to PDF
 * /*from w  w  w .ja  v a  2 s  .c  om*/
 * @param exporterParameters PDF exporter parameters
 * @param generator Generator used for puzzle generation
 * @throws IOException If any PDF library error occurs
 * @throws DocumentException If any error occurs while writing the PDF file
 */
public void write(final ExporterParameters exporterParameters, final Generator generator,
        final int boardDimension) throws IOException, DocumentException {
    //How many PDF-pages are needed to fit all puzzles using the desired page formatting
    final int optimisticPageCount = exporterParameters.getPuzzleCount()
            / exporterParameters.getPuzzlesPerPage();
    final int pageCount = exporterParameters.getPuzzleCount() % exporterParameters.getPuzzlesPerPage() > 0
            ? optimisticPageCount + 1
            : optimisticPageCount;

    final Document document = new Document(PageSize.A4, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN,
            DOCUMENT_MARGIN);
    final OutputStream outputStream = new FileOutputStream(exporterParameters.getOutputPath());
    final PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);

    final String creator = Sudoku.getNameAndVersion();
    document.addSubject("Puzzles generated by " + creator);
    document.addCreator(creator);
    document.open();

    final Rectangle pageSize = document.getPageSize();
    final int pageHeight = (int) pageSize.getHeight();
    final int pageWidth = (int) pageSize.getWidth();

    //Get appropriate number of rows and columns needed to divide a page into
    final int horizontalDimension = exporterParameters.getPuzzlesPerPage() > 2 ? 2 : 1;
    final int verticalDimension = exporterParameters.getPuzzlesPerPage() > 1 ? 2 : 1;

    //Get available space for each board (with margins) on a page
    final int boardWidth = pageWidth / horizontalDimension;
    final int boardHeight = pageHeight / verticalDimension;

    final Board board = new Board(boardDimension, SymbolType.DIGITS);
    board.setSize(boardWidth, boardHeight);
    board.handleResized();

    //Get available height/width on a page for a puzzle itself
    final int puzzleWidth = board.getPuzzleWidth();
    int puzzlesPrinted = 0;

    final PdfContentByte contentByte = pdfWriter.getDirectContent();
    final Grading[] gradings = getGeneratedPuzzleGradings(exporterParameters.getGradings(),
            exporterParameters.getOrdering(), exporterParameters.getPuzzleCount());

    pageCounter: for (int page = 0; page < pageCount; ++page) {
        document.newPage();
        final Graphics2D g2d = contentByte.createGraphics(pageWidth, pageHeight);
        for (int y = 0, i = 0; i < verticalDimension; y += boardHeight, ++i) {
            for (int x = 0, j = 0; j < horizontalDimension; x += boardWidth, ++j) {
                //Check whether to generate a new puzzle or print empty boards 
                final ExportMode exportMode = exporterParameters.getExportMode();
                final Grading selectedGrading = exportMode == ExportMode.BLANK ? null
                        : gradings[puzzlesPrinted];
                if (exportMode == ExportMode.GENERATE_NEW) {
                    board.setPuzzle(generatePuzzle(generator, getSymmetry(exporterParameters.getSymmetries()),
                            selectedGrading));
                    board.recordGivens();
                }

                //Calculate puzzle drawing origins
                final int originX = x + (int) (boardWidth / 2 - (puzzleWidth / 2));
                final int originY = y + (int) (boardHeight / 2) - (puzzleWidth / 2);

                board.setSymbolType(getSymbolType(exporterParameters.getSymbolType()));
                board.setDrawingOrigin(originX, originY);
                board.draw(g2d, false, false);

                drawLegend(g2d,
                        getLegendString(exporterParameters.isShowNumbering(),
                                exporterParameters.isShowGrading(), puzzlesPrinted + 1, selectedGrading),
                        originX, originY, puzzleWidth);

                if (++puzzlesPrinted == exporterParameters.getPuzzleCount()) {
                    //We've printed all puzzles, break
                    g2d.dispose();
                    break pageCounter;
                }
            }
        }
        g2d.dispose();
    }
    document.close();
    outputStream.flush();
    outputStream.close();
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

@Override
public void addMetaData(final Document document) {
    document.addSubject("Using iText");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor("QCADOO");
    document.addCreator("QCADOO");
}

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Generates the report and sends it to the user over the provided servlet
 * response.//from w  w w .  j  av  a2s  .co m
 *
 * @param  requestInfo  State information about the request being processed.
 */
public void generateReport(RequestInfo requestInfo) {
    // Determine exactly what to include in the report.  We will want to strip
    // out any individual jobs that are part of an optimizing job that is also
    // to be included in the report.
    reportOptimizingJobs = new OptimizingJob[optimizingJobList.size()];
    optimizingJobList.toArray(reportOptimizingJobs);

    ArrayList<Job> tmpList = new ArrayList<Job>(jobList.size());
    for (int i = 0; i < jobList.size(); i++) {
        Job job = jobList.get(i);
        String optimizingJobID = job.getOptimizingJobID();
        if ((optimizingJobID != null) && (optimizingJobID.length() > 0)) {
            boolean matchFound = false;

            for (int j = 0; j < reportOptimizingJobs.length; j++) {
                if (optimizingJobID.equalsIgnoreCase(reportOptimizingJobs[j].getOptimizingJobID())) {
                    matchFound = true;
                    break;
                }
            }

            if (matchFound) {
                continue;
            }
        }

        tmpList.add(job);
    }
    reportJobs = new Job[tmpList.size()];
    tmpList.toArray(reportJobs);

    // Prepare to actually generate the report and send it to the user.
    HttpServletResponse response = requestInfo.getResponse();
    if (viewInBrowser) {
        response.setContentType("application/pdf");
    } else {
        response.setContentType("application/x-slamd-report-pdf");
    }
    response.addHeader("Content-Disposition", "filename=\"slamd_data_report.pdf\"");

    try {
        // Create the PDF document and associate it with the response to send to
        // the client.
        Document document = new Document(PageSize.LETTER);
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
        document.addTitle("SLAMD Generated Report");
        document.addCreationDate();
        document.addCreator("SLAMD Distributed Load Generator");
        writer.setPageEvent(this);

        // Open the document and add the table of contents.
        document.open();

        boolean needNewPage = writeContents(document);

        // Write the regular job information.
        for (int i = 0; i < reportJobs.length; i++) {
            if (needNewPage) {
                document.newPage();
            }
            writeJob(document, reportJobs[i]);
            needNewPage = true;
        }

        // Write the optimizing job information.
        for (int i = 0; i < reportOptimizingJobs.length; i++) {
            if (needNewPage) {
                document.newPage();
            }
            writeOptimizingJob(document, reportOptimizingJobs[i]);
            needNewPage = true;
        }

        // Close the document.
        document.close();
    } catch (Exception e) {
        // Not much we can do about this.
        e.printStackTrace();
        return;
    }
}

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:CPS.Core.TODOLists.PDFExporter.java

License:Open Source License

private Document prepareDocument(String filename, final String title, final String author, final String creator,
        final Rectangle pageSize) {

    System.out.println("DEBUG(PDFExporter): Creating document: " + filename);

    Document d = new Document();

    d.setPageSize(pageSize);/*from  w w w .j  av  a 2 s.  c  o m*/
    // TODO alter page orientation?  maybe useful for seed order worksheet

    d.addTitle(title);
    d.addAuthor(author);
    //        d.addSubject( );
    //        d.addKeywords( );
    d.addCreator(creator);

    // left, right, top, bottom - scale in points (~72 points/inch)
    d.setMargins(35, 35, 35, 44);

    try {
        PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream(filename));
        // add header and footer
        writer.setPageEvent(new PdfPageEventHelper() {
            public void onEndPage(PdfWriter writer, Document document) {
                try {
                    Rectangle page = document.getPageSize();

                    PdfPTable head = new PdfPTable(3);
                    head.getDefaultCell().setBorderWidth(0);
                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                    head.addCell(new Phrase(author, fontHeadFootItal));

                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    head.addCell(new Phrase(title, fontHeadFootReg));

                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    head.addCell("");

                    head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
                    head.writeSelectedRows(0, -1, document.leftMargin(),
                            page.getHeight() - document.topMargin() + head.getTotalHeight(),
                            writer.getDirectContent());

                    PdfPTable foot = new PdfPTable(3);

                    foot.getDefaultCell().setBorderWidth(0);
                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                    foot.addCell(new Phrase(creator, fontHeadFootItal));

                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    foot.addCell("");

                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    foot.addCell(new Phrase("Page " + document.getPageNumber(), fontHeadFootReg));

                    foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
                    foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                            writer.getDirectContent());
                } catch (Exception e) {
                    throw new ExceptionConverter(e);
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }

    return d;
}

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!
 * /* w  ww  .j av a  2s  .  c o m*/
 * @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.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private Document writeDocument(Document document, List<SudokuData> sudokus) throws DocumentException {
    document.open();/*from ww w  . j ava 2 s.c om*/
    // TODO Von auen konfigurieren
    document.addAuthor("Jrgen Dufner");
    document.addCreationDate();
    document.addCreator("de.jdufner.sudoku.Generator");
    document.addKeywords("Sudoku");
    document.addTitle("Sudokus in unterschiedlichen Schwierigkeitsgraden");
    document.add(writePdfMetaTable(sudokus));
    document.close();
    return document;
}

From source file:de.maklerpoint.office.Schnittstellen.PDF.ExportListePDF.java

License:Open Source License

public void write() throws DocumentException, FileNotFoundException {

    SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");

    Document doc = null;

    if (titles.length > 7)
        doc = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    else/*from  ww w  .j ava  2  s . c o m*/
        doc = new Document(PageSize.A4, 20, 20, 20, 20);

    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(filename));
    doc.addAuthor("MaklerPoint - www.maklerpoint.de");
    doc.addCreator("MaklerPoint - www.maklerpoint.de");
    doc.addCreationDate();
    doc.addTitle(title);

    doc.open();

    doc.add(new Paragraph(title, FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, Color.BLACK)));

    Table t = new Table(titles.length, data.length + 1);
    t.setPadding(3);
    t.setSpacing(0);
    t.setBorderWidth(1);

    for (int i = 0; i < titles.length; i++) {
        Cell c1 = new Cell(titles[i]);
        c1.setHeader(true);
        t.addCell(c1);
    }
    t.endHeaders();

    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data[i].length; j++) {
            Cell c1 = null;
            if (data[i][j] != null)
                c1 = new Cell(data[i][j].toString());
            else
                c1 = new Cell("");
            t.addCell(c1);
        }
    }

    doc.add(t);

    if (footer == null) {
        doc.add(new Paragraph(
                ("Export " + title + " - Genereriert am " + df.format(new Date(System.currentTimeMillis())))
                        + " von MaklerPoint",
                FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL, Color.black)));
    } else {
        doc.add(new Paragraph(footer, FontFactory.getFont(FontFactory.TIMES, 10, Font.NORMAL, Color.black)));
    }

    doc.close();
}

From source file:demo.dwr.simple.UploadDownload.java

License:Apache License

/**
 * Generates a PDF file with the given text
 * http://itext.ugent.be/itext-in-action/
 * @return A PDF file as a byte array/*from   w ww . j ava  2 s .  c om*/
 */
public FileTransfer downloadPdfFile(String contents) throws Exception {
    if (contents == null || contents.length() == 0) {
        contents = "[BLANK]";
    }

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, buffer);

    // ?itext-asian
    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    // ?WINDOW c:\windows\Fonts\xxx.ttf
    // ?classpath: /src/main/resources/fonts/simsong.ttf

    Font fontChinese = new Font(bfChinese, 12, Font.NORMAL);

    document.addCreator("DWR.war using iText");
    document.open();
    document.add(new Paragraph(contents, fontChinese));
    document.close();

    return new FileTransfer("example.pdf", "application/pdf", buffer.toByteArray());
}

From source file:es.uniovi.asw.personalletter.PDFTextWritter.java

/**
 * Metadata del documento.//from w w  w .  j a  v a  2s  . 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");
}