Search in sources :

Example 31 with Document

use of com.lowagie.text.Document in project OpenClinica by OpenClinica.

the class DownloadDiscrepancyNote method serializeToPDF.

private void serializeToPDF(EntityBean bean, OutputStream stream) {
    ServletOutputStream servletStream = (ServletOutputStream) stream;
    DiscrepancyNoteBean discNBean = (DiscrepancyNoteBean) bean;
    StringBuilder writer = new StringBuilder();
    writer.append(serializeToString(discNBean, false, 0));
    Document pdfDoc = new Document();
    try {
        PdfWriter.getInstance(pdfDoc, servletStream);
        pdfDoc.open();
        pdfDoc.add(new Paragraph(writer.toString()));
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    pdfDoc.close();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) DocumentException(com.lowagie.text.DocumentException) Document(com.lowagie.text.Document) Paragraph(com.lowagie.text.Paragraph)

Example 32 with Document

use of com.lowagie.text.Document in project OpenClinica by OpenClinica.

the class DownloadDiscrepancyNote method serializeListToPDF.

public void serializeListToPDF(String content, OutputStream stream) {
    ServletOutputStream servletStream = (ServletOutputStream) stream;
    Document pdfDoc = new Document();
    try {
        PdfWriter.getInstance(pdfDoc, servletStream);
        pdfDoc.open();
        pdfDoc.add(new Paragraph(content));
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    pdfDoc.close();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) DocumentException(com.lowagie.text.DocumentException) Document(com.lowagie.text.Document) Paragraph(com.lowagie.text.Paragraph)

Example 33 with Document

use of com.lowagie.text.Document in project boxmaker by rahulbot.

the class Renderer method openDoc.

/**
 * Create the document to write to (needed before any rendering can happen).
 * @param widthMm	the width of the document in millimeters
 * @param heightMm	the height of the document in millimeters
 * @param fileName  the name of the file to save
 * @throws FileNotFoundException
 * @throws DocumentException
 */
private void openDoc(float widthMm, float heightMm, String fileName) throws FileNotFoundException, DocumentException {
    float docWidth = widthMm * DPI * INCH_PER_MM;
    float docHeight = heightMm * DPI * INCH_PER_MM;
    // System.out.println("doc = "+docWidth+" x "+docHeight);
    doc = new Document(new Rectangle(docWidth, docHeight));
    docPdfWriter = PdfWriter.getInstance(doc, new FileOutputStream(filePath));
    String appNameVersion = BoxMakerConstants.APP_NAME + " " + BoxMakerConstants.VERSION;
    doc.addAuthor(appNameVersion);
    doc.open();
    doc.add(new Paragraph("Produced by " + BoxMakerConstants.APP_NAME + " " + BoxMakerConstants.VERSION + "\n" + "  on " + new Date() + "\n" + BoxMakerConstants.WEBSITE_URL));
}
Also used : FileOutputStream(java.io.FileOutputStream) Rectangle(com.lowagie.text.Rectangle) Document(com.lowagie.text.Document) Date(java.util.Date) Paragraph(com.lowagie.text.Paragraph)

Example 34 with Document

use of com.lowagie.text.Document in project spring-framework by spring-projects.

the class AbstractPdfView method renderMergedOutputModel.

@Override
protected final void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    // IE workaround: write into byte array first.
    ByteArrayOutputStream baos = createTemporaryOutputStream();
    // Apply preferences and build metadata.
    Document document = newDocument();
    PdfWriter writer = newWriter(document, baos);
    prepareWriter(model, writer, request);
    buildPdfMetadata(model, document, request);
    // Build PDF document.
    document.open();
    buildPdfDocument(model, document, writer, request, response);
    document.close();
    // Flush to HTTP response.
    writeToResponse(response, baos);
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.lowagie.text.Document)

Example 35 with Document

use of com.lowagie.text.Document in project dhis2-core by dhis2.

the class GridUtils method toPdf.

/**
 * Writes a PDF representation of the given list of Grids to the given
 * OutputStream.
 */
public static void toPdf(List<Grid> grids, OutputStream out) {
    if (hasNonEmptyGrid(grids)) {
        Document document = openDocument(out);
        for (Grid grid : grids) {
            toPdfInternal(grid, document, 40F);
        }
        addPdfTimestamp(document, false);
        closeDocument(document);
    }
}
Also used : Grid(org.hisp.dhis.common.Grid) PDFUtils.addTableToDocument(org.hisp.dhis.system.util.PDFUtils.addTableToDocument) PDFUtils.openDocument(org.hisp.dhis.system.util.PDFUtils.openDocument) Document(com.lowagie.text.Document) PDFUtils.closeDocument(org.hisp.dhis.system.util.PDFUtils.closeDocument)

Aggregations

Document (com.lowagie.text.Document)36 DocumentException (com.lowagie.text.DocumentException)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 PdfWriter (com.lowagie.text.pdf.PdfWriter)13 Paragraph (com.lowagie.text.Paragraph)12 IOException (java.io.IOException)12 Rectangle (com.lowagie.text.Rectangle)10 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)9 FileOutputStream (java.io.FileOutputStream)9 Color (java.awt.Color)8 DefaultFontMapper (com.lowagie.text.pdf.DefaultFontMapper)6 PdfImportedPage (com.lowagie.text.pdf.PdfImportedPage)5 File (java.io.File)5 DocWriter (com.lowagie.text.DocWriter)4 Phrase (com.lowagie.text.Phrase)4 PdfPCell (com.lowagie.text.pdf.PdfPCell)4 PdfPTable (com.lowagie.text.pdf.PdfPTable)4 PdfReader (com.lowagie.text.pdf.PdfReader)4 Graphics2D (java.awt.Graphics2D)4 OutputStream (java.io.OutputStream)4