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;
}
}
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();
}
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();
}
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();
}
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();
}
Aggregations