Search in sources :

Example 11 with Document

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

the class DownloadDiscrepancyNote method serializeListToPDF.

public void serializeListToPDF(List<DiscrepancyNoteBean> listOfBeans, OutputStream stream, String studyIdentifier) {
    ServletOutputStream servletStream = (ServletOutputStream) stream;
    Document pdfDoc = new Document();
    try {
        PdfWriter.getInstance(pdfDoc, servletStream);
        pdfDoc.open();
        //Create header for the study identifier or name
        if (studyIdentifier != null) {
            HeaderFooter header = new HeaderFooter(new Phrase("Study Identifier: " + studyIdentifier + " pg."), true);
            header.setAlignment(Element.ALIGN_CENTER);
            Paragraph para = new Paragraph("Study Identifier: " + studyIdentifier, new Font(Font.HELVETICA, 18, Font.BOLD, new Color(0, 0, 0)));
            para.setAlignment(Element.ALIGN_CENTER);
            pdfDoc.setHeader(header);
            pdfDoc.add(para);
        }
        for (DiscrepancyNoteBean discNoteBean : listOfBeans) {
            pdfDoc.add(this.createTableFromBean(discNoteBean));
            pdfDoc.add(new Paragraph("\n"));
        }
    //pdfDoc.add(new Paragraph(content));
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    pdfDoc.close();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) Color(java.awt.Color) DocumentException(com.lowagie.text.DocumentException) HeaderFooter(com.lowagie.text.HeaderFooter) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph)

Example 12 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 13 with Document

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

the class DownloadDiscrepancyNote method serializeThreadsToPDF.

public void serializeThreadsToPDF(List<DiscrepancyNoteThread> listOfThreads, OutputStream stream, String studyIdentifier) {
    ServletOutputStream servletStream = (ServletOutputStream) stream;
    Document pdfDoc = new Document();
    try {
        PdfWriter.getInstance(pdfDoc, servletStream);
        pdfDoc.open();
        //Create header for the study identifier or name
        if (studyIdentifier != null) {
            HeaderFooter header = new HeaderFooter(new Phrase("Study Identifier: " + studyIdentifier + " pg."), true);
            header.setAlignment(Element.ALIGN_CENTER);
            Paragraph para = new Paragraph("Study Identifier: " + studyIdentifier, new Font(Font.HELVETICA, 18, Font.BOLD, new Color(0, 0, 0)));
            para.setAlignment(Element.ALIGN_CENTER);
            pdfDoc.setHeader(header);
            pdfDoc.add(para);
        }
        for (DiscrepancyNoteThread discNoteThread : listOfThreads) {
            pdfDoc.add(this.createTableThreadHeader(discNoteThread));
            //Just the parent of the thread?  discNoteThread.getLinkedNoteList()
            for (DiscrepancyNoteBean discNoteBean : discNoteThread.getLinkedNoteList()) {
                //DiscrepancyNoteBean discNoteBean = discNoteThread.getLinkedNoteList().getFirst();
                if (discNoteBean.getParentDnId() > 0) {
                    pdfDoc.add(this.createTableFromBean(discNoteBean));
                    pdfDoc.add(new Paragraph("\n"));
                }
            }
        }
    //pdfDoc.add(new Paragraph(content));
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    pdfDoc.close();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) Color(java.awt.Color) DocumentException(com.lowagie.text.DocumentException) HeaderFooter(com.lowagie.text.HeaderFooter) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph) DiscrepancyNoteThread(org.akaza.openclinica.service.DiscrepancyNoteThread)

Example 14 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 15 with Document

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

the class PDFUtils method openDocument.

/**
     * Creates a document.
     *
     * @param outputStream The output stream to write the document content.
     * @param pageSize     the page size.
     * @return A Document.
     */
public static Document openDocument(OutputStream outputStream, Rectangle pageSize) {
    try {
        Document document = new Document(pageSize);
        PdfWriter.getInstance(document, outputStream);
        document.open();
        return document;
    } catch (DocumentException ex) {
        throw new RuntimeException("Failed to open PDF document", ex);
    }
}
Also used : DocumentException(com.lowagie.text.DocumentException) Document(com.lowagie.text.Document)

Aggregations

Document (com.lowagie.text.Document)16 DocumentException (com.lowagie.text.DocumentException)8 Paragraph (com.lowagie.text.Paragraph)8 PdfWriter (com.lowagie.text.pdf.PdfWriter)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ServletOutputStream (javax.servlet.ServletOutputStream)5 Font (com.lowagie.text.Font)3 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)3 Color (java.awt.Color)3 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)3 HeaderFooter (com.lowagie.text.HeaderFooter)2 Phrase (com.lowagie.text.Phrase)2 DefaultFontMapper (com.lowagie.text.pdf.DefaultFontMapper)2 PdfTemplate (com.lowagie.text.pdf.PdfTemplate)2 Rectangle2D (java.awt.geom.Rectangle2D)2 FileOutputStream (java.io.FileOutputStream)2 Date (java.util.Date)2 PdfFormFontSettings (org.hisp.dhis.dxf2.pdfform.PdfFormFontSettings)2 PDFUtils.addTableToDocument (org.hisp.dhis.system.util.PDFUtils.addTableToDocument)2 PDFUtils.closeDocument (org.hisp.dhis.system.util.PDFUtils.closeDocument)2