public abstract class AbstractPdfView extends AbstractView
Note: Internet Explorer requires a ".pdf" extension, as it doesn't always respect the declared content type.
AbstractPdfStamperView
DEFAULT_CONTENT_TYPE
logger
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
Constructor and Description |
---|
AbstractPdfView()
This constructor sets the appropriate content type "application/pdf".
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
buildPdfDocument(java.util.Map<java.lang.String,java.lang.Object> model,
Document document,
PdfWriter writer,
HttpServletRequest request,
HttpServletResponse response)
Subclasses must implement this method to build an iText PDF document,
given the model.
|
protected void |
buildPdfMetadata(java.util.Map<java.lang.String,java.lang.Object> model,
Document document,
HttpServletRequest request)
Populate the iText Document's meta fields (author, title, etc.).
|
protected boolean |
generatesDownloadContent()
Return whether this view generates download content
(typically binary content like PDF or Excel files).
|
protected int |
getViewerPreferences()
Return the viewer preferences for the PDF file.
|
protected Document |
newDocument()
Create a new document to hold the PDF contents.
|
protected PdfWriter |
newWriter(Document document,
java.io.OutputStream os)
Create a new PdfWriter for the given iText Document.
|
protected void |
prepareWriter(java.util.Map<java.lang.String,java.lang.Object> model,
PdfWriter writer,
HttpServletRequest request)
Prepare the given PdfWriter.
|
protected void |
renderMergedOutputModel(java.util.Map<java.lang.String,java.lang.Object> model,
HttpServletRequest request,
HttpServletResponse response)
Subclasses must implement this method to actually render the view.
|
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposePathVariables, setRequestContextAttribute, setResponseContentType, toString, writeToResponse
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
public AbstractPdfView()
protected boolean generatesDownloadContent()
AbstractView
The default implementation returns false
. Subclasses are
encouraged to return true
here if they know that they are
generating download content that requires temporary caching on the
client side, typically via the response OutputStream.
generatesDownloadContent
in class AbstractView
AbstractView.prepareResponse(HttpServletRequest, HttpServletResponse)
,
javax.servlet.http.HttpServletResponse#getOutputStream()
protected final void renderMergedOutputModel(java.util.Map<java.lang.String,java.lang.Object> model, HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception
AbstractView
The first step will be preparing the request: In the JSP case, this would mean setting model objects as request attributes. The second step will be the actual rendering of the view, for example including the JSP via a RequestDispatcher.
renderMergedOutputModel
in class AbstractView
model
- combined output Map (never null
),
with dynamic values taking precedence over static attributesrequest
- current HTTP requestresponse
- current HTTP responsejava.lang.Exception
- if rendering failedprotected Document newDocument()
By default returns an A4 document, but the subclass can specify any Document, possibly parameterized via bean properties defined on the View.
com.lowagie.text.Document#Document(com.lowagie.text.Rectangle)
protected PdfWriter newWriter(Document document, java.io.OutputStream os) throws DocumentException
document
- the iText Document to create a writer foros
- the OutputStream to write toDocumentException
- if thrown during writer creationprotected void prepareWriter(java.util.Map<java.lang.String,java.lang.Object> model, PdfWriter writer, HttpServletRequest request) throws DocumentException
Document.open()
.
Useful for registering a page event listener, for example.
The default implementation sets the viewer preferences as returned
by this class's getViewerPreferences()
method.
model
- the model, in case meta information must be populated from itwriter
- the PdfWriter to preparerequest
- in case we need locale etc. Shouldn't look at attributes.DocumentException
- if thrown during writer preparationcom.lowagie.text.Document#open()
,
com.lowagie.text.pdf.PdfWriter#setPageEvent
,
com.lowagie.text.pdf.PdfWriter#setViewerPreferences
,
getViewerPreferences()
protected int getViewerPreferences()
By default returns AllowPrinting
and
PageLayoutSinglePage
, but can be subclassed.
The subclass can either have fixed preferences or retrieve
them from bean properties defined on the View.
com.lowagie.text.pdf.PdfWriter#AllowPrinting
,
com.lowagie.text.pdf.PdfWriter#PageLayoutSinglePage
protected void buildPdfMetadata(java.util.Map<java.lang.String,java.lang.Object> model, Document document, HttpServletRequest request)
document.open()
.model
- the model, in case meta information must be populated from itdocument
- the iText document being populatedrequest
- in case we need locale etc. Shouldn't look at attributes.com.lowagie.text.Document#addTitle
,
com.lowagie.text.Document#addSubject
,
com.lowagie.text.Document#addKeywords
,
com.lowagie.text.Document#addAuthor
,
com.lowagie.text.Document#addCreator
,
com.lowagie.text.Document#addProducer
,
com.lowagie.text.Document#addCreationDate
,
com.lowagie.text.Document#addHeader
protected abstract void buildPdfDocument(java.util.Map<java.lang.String,java.lang.Object> model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception
Document.open()
and
Document.close()
calls.
Note that the passed-in HTTP response is just supposed to be used for setting cookies or other HTTP headers. The built PDF document itself will automatically get written to the response after this method returns.
model
- the model Mapdocument
- the iText Document to add elements towriter
- the PdfWriter to userequest
- in case we need locale etc. Shouldn't look at attributes.response
- in case we need to set cookies. Shouldn't write to it.java.lang.Exception
- any exception that occured during document buildingcom.lowagie.text.Document#open()
,
com.lowagie.text.Document#close()