Search in sources :

Example 26 with DocumentException

use of com.lowagie.text.DocumentException in project vcell by virtualcell.

the class ITextWriter method writeMathModel.

public void writeMathModel(MathModel mathModel, FileOutputStream fos, PageFormat pageFormat, PublishPreferences preferences) throws Exception {
    if (mathModel == null || fos == null || pageFormat == null || preferences == null) {
        throw new IllegalArgumentException("One or more null params while publishing MathModel.");
    }
    try {
        createDocument(pageFormat);
        createDocWriter(fos);
        // Add metadata before you open the document...
        String name = mathModel.getName().trim();
        String userName = "Unknown";
        if (mathModel.getVersion() != null) {
            userName = mathModel.getVersion().getOwner().getName();
        }
        document.addTitle(name + "[owned by " + userName + "]");
        document.addCreator("Virtual Cell");
        document.addCreationDate();
        // writeWatermark(document, pageFormat);
        writeHeaderFooter("MathModel: " + name);
        document.open();
        // 
        int chapterNum = 1;
        Section introSection = null;
        if (preferences.includeMathDesc()) {
            MathDescription mathDesc = mathModel.getMathDescription();
            Chapter mathDescChapter = new Chapter("Math Description", chapterNum++);
            introSection = mathDescChapter.addSection("General Info", mathDescChapter.numberDepth() + 1);
            writeMetadata(introSection, name, mathModel.getDescription(), userName, "MathModel");
            writeMathDescAsText(mathDescChapter, mathDesc);
            document.add(mathDescChapter);
        }
        if (preferences.includeSim()) {
            // unlike biomodels, simulations are chapters, not chapter sections.
            Simulation[] sims = mathModel.getSimulations();
            if (sims != null) {
                Chapter simChapter = new Chapter("Simulations", chapterNum++);
                if (introSection == null) {
                    introSection = simChapter.addSection("General Info", simChapter.numberDepth() + 1);
                    writeMetadata(introSection, name, mathModel.getDescription(), userName, "MathModel");
                }
                for (int i = 0; i < sims.length; i++) {
                    writeSimulation(simChapter, sims[i]);
                }
                document.add(simChapter);
            } else {
                System.err.println("Bad Request: No simulations to publish for Mathmodel: " + name);
            }
        }
        if (preferences.includeGeom()) {
            // unlike biomodels, geometry is a chapter, not a chapter section.
            Geometry geom = mathModel.getMathDescription().getGeometry();
            if (geom != null) {
                Chapter geomChapter = new Chapter("Geometry", chapterNum++);
                if (introSection == null) {
                    introSection = geomChapter.addSection("General Info", geomChapter.numberDepth() + 1);
                    writeMetadata(introSection, name, mathModel.getDescription(), userName, "MathModel");
                }
                writeGeom(geomChapter, geom, null);
                document.add(geomChapter);
            } else {
                System.err.println("Bad Request: No geometry to publish for Mathmodel: " + name);
            }
        }
        document.close();
    } catch (DocumentException e) {
        System.err.println("Unable to publish MathModel.");
        e.printStackTrace();
        throw e;
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) MathDescription(cbit.vcell.math.MathDescription) DocumentException(com.lowagie.text.DocumentException) Chapter(com.lowagie.text.Chapter) Section(com.lowagie.text.Section)

Example 27 with DocumentException

use of com.lowagie.text.DocumentException in project drools by kiegroup.

the class DroolsDocsBuilder method writePDF.

public void writePDF(OutputStream out) {
    // TODO: Use i18n!
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, out);
        HeaderFooter footer = DroolsDocsComponentFactory.createFooter(packageData.getName());
        document.setFooter(footer);
        document.addTitle(packageData.getName().toUpperCase());
        document.open();
        // First page, documentation info.
        DroolsDocsComponentFactory.createFirstPage(document, currentDate, packageData);
        document.newPage();
        // List index of the rules
        document.add(new Phrase("Table of Contents"));
        document.add(DroolsDocsComponentFactory.createContents(packageData.getRules()));
        document.newPage();
        for (DrlRuleParser ruleData : packageData.getRules()) {
            DroolsDocsComponentFactory.newRulePage(document, packageData.getName(), ruleData);
        }
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }
    document.close();
}
Also used : DocumentException(com.lowagie.text.DocumentException) HeaderFooter(com.lowagie.text.HeaderFooter) Phrase(com.lowagie.text.Phrase) Document(com.lowagie.text.Document) DrlRuleParser(org.drools.verifier.misc.DrlRuleParser)

Example 28 with DocumentException

use of com.lowagie.text.DocumentException 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 29 with DocumentException

use of com.lowagie.text.DocumentException 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 30 with DocumentException

use of com.lowagie.text.DocumentException 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)

Aggregations

DocumentException (com.lowagie.text.DocumentException)34 Document (com.lowagie.text.Document)19 IOException (java.io.IOException)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 Paragraph (com.lowagie.text.Paragraph)12 Color (java.awt.Color)9 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)7 PdfReader (com.lowagie.text.pdf.PdfReader)7 ByteBuffer (java.nio.ByteBuffer)6 Delegator (org.apache.ofbiz.entity.Delegator)6 Chunk (com.lowagie.text.Chunk)5 Phrase (com.lowagie.text.Phrase)5 Section (com.lowagie.text.Section)5 PdfObject (com.lowagie.text.pdf.PdfObject)5 PdfWriter (com.lowagie.text.pdf.PdfWriter)5 GeneralException (org.apache.ofbiz.base.util.GeneralException)5 ExpressionException (cbit.vcell.parser.ExpressionException)4 AcroFields (com.lowagie.text.pdf.AcroFields)4 PdfStamper (com.lowagie.text.pdf.PdfStamper)4 File (java.io.File)4