Search in sources :

Example 6 with Document

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);
    }
}
Also used : PDFUtils.addTableToDocument(org.hisp.dhis.system.util.PDFUtils.addTableToDocument) PDFUtils.openDocument(org.hisp.dhis.system.util.PDFUtils.openDocument) Document(com.lowagie.text.Document) PDFUtils.closeDocument(org.hisp.dhis.system.util.PDFUtils.closeDocument)

Example 7 with 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);
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.lowagie.text.Document) PdfFormFontSettings(org.hisp.dhis.dxf2.pdfform.PdfFormFontSettings) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with Document

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);
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.lowagie.text.Document) PdfFormFontSettings(org.hisp.dhis.dxf2.pdfform.PdfFormFontSettings) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Document

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));
}
Also used : FileOutputStream(java.io.FileOutputStream) Rectangle(com.lowagie.text.Rectangle) Document(com.lowagie.text.Document) Date(java.util.Date) Paragraph(com.lowagie.text.Paragraph)

Example 10 with Document

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);
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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