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