use of com.lowagie.text.Document in project dhis2-core by dhis2.
the class GridUtils method toPdf.
/**
* Writes a PDF representation of the given Grid to the given OutputStream.
*/
public static void toPdf(Grid grid, OutputStream out) {
if (isNonEmptyGrid(grid)) {
Document document = openDocument(out);
toPdfInternal(grid, document, 0F);
addPdfTimestamp(document, true);
closeDocument(document);
}
}
use of com.lowagie.text.Document in project dhis2-core by dhis2.
the class PdfFormController method getFormPdfProgramStage.
//--------------------------------------------------------------------------
// Program Stage
//--------------------------------------------------------------------------
@RequestMapping(value = "/programStage/{programStageUid}", method = RequestMethod.GET)
public void getFormPdfProgramStage(@PathVariable String programStageUid, HttpServletRequest request, HttpServletResponse response, OutputStream out) throws Exception {
Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
PdfFormFontSettings pdfFormFontSettings = new PdfFormFontSettings();
PdfDataEntryFormUtil.setDefaultFooterOnDocument(document, request.getServerName(), pdfFormFontSettings.getFont(PdfFormFontSettings.FONTTYPE_FOOTER));
pdfDataEntryFormService.generatePDFDataEntryForm(document, writer, programStageUid, PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE, PdfDataEntryFormUtil.getDefaultPageSize(PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE), pdfFormFontSettings, i18nManager.getI18nFormat());
String fileName = programStageService.getProgramStage(programStageUid).getName() + " " + DateUtils.getMediumDateString() + ".pdf";
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.NO_CACHE, fileName, true);
response.setContentLength(baos.size());
baos.writeTo(out);
}
use of com.lowagie.text.Document in project dhis2-core by dhis2.
the class PdfFormController method getFormPdfDataSet.
//--------------------------------------------------------------------------
// DataSet
//--------------------------------------------------------------------------
@RequestMapping(value = "/dataSet/{dataSetUid}", method = RequestMethod.GET)
public void getFormPdfDataSet(@PathVariable String dataSetUid, HttpServletRequest request, HttpServletResponse response, OutputStream out) throws Exception {
Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
PdfFormFontSettings pdfFormFontSettings = new PdfFormFontSettings();
PdfDataEntryFormUtil.setDefaultFooterOnDocument(document, request.getServerName(), pdfFormFontSettings.getFont(PdfFormFontSettings.FONTTYPE_FOOTER));
pdfDataEntryFormService.generatePDFDataEntryForm(document, writer, dataSetUid, PdfDataEntryFormUtil.DATATYPE_DATASET, PdfDataEntryFormUtil.getDefaultPageSize(PdfDataEntryFormUtil.DATATYPE_DATASET), pdfFormFontSettings, i18nManager.getI18nFormat());
String fileName = dataSetService.getDataSet(dataSetUid).getName() + " " + DateUtils.getMediumDateString() + ".pdf";
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.NO_CACHE, fileName, true);
response.setContentLength(baos.size());
baos.writeTo(out);
}
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));
}
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);
}
Aggregations