public class JRPdfExporter extends JRAbstractExporter<PdfReportConfiguration,PdfExporterConfiguration,OutputStreamExporterOutput,JRPdfExporterContext>
JRPdfExporter
class in JasperReports is
one of the best exporters. The output it produces is almost of the same quality as that
produced by the JRGraphics2DExporter
,
which is always the reference.
The JRPdfExporter
implementation uses iText,
which is a specialized PDF-generating library. PDF is a binary document format that allows
absolute positioning of the elements inside a page, so the existing PDF exporter does not
have the limitations of a grid exporter.
It also works very well in batch mode because it allows concatenation of multiple
documents within the same PDF file, even if the files have different page sizes.
pdfFontName
, pdfEncoding
and isPdfEmbedded
.
Even though these three attributes are still supported in JRXML and
the API, we recommend making the PDF font mappings at export time using font
extensions.
When exporting documents to PDF, for each combination of the three fontName
,
isBold
, and isItalic
font attributes, there must be an equivalent
combination of the PDF-related font attributes pdfFontName
, pdfEncoding
and isPdfEmbedded
.
Equivalent combination means one that causes the text elements to be rendered exactly
the same (or at least as closely as possible) in PDF and the built-in Graphics2D
exporter, which is the reference.
In some cases, there is no font file available to use with the pdfFontName attribute in
order to render bold and italic text exactly like the Graphics2D exporter renders it in
AWT. Those fonts might only have a normal style variant and no variants for bold and
italic. In such cases, the PDF exporter (the iText library, to be more precise) is able to
simulate those styles by applying transformations to the normal font glyphs. The
JRPdfExporter
internally acquires the needed PDF
font based on the font extension mechanism (see the getFont(Map, Locale, boolean)
method.
jasperPrint.getName()
property. However, users can turn on and off
the creation of those bookmarks by turning on or off the
isCreatingBatchModeBookmarks()
exporter configuration setting. The exporter does not create such bookmarks by default.
PdfExporterConfiguration
):
PdfExporterConfiguration
):
Since version 1.5, the PDF format supports compression. By default, the PDF exporter in
JasperReports does not create compressed PDF documents, but this feature can be turned
on using the isCompressed()
exporter configuration setting. Note that because compressed PDFs
are available only since PDF version 1.5, the PDF version of the resulting document is
set to 1.5 automatically if compression is turned on.
isForceLineBreakPolicy()
exporter configuration setting to true. Note that this feature is not turned on by default, because it affects the
exporter performance. This default behavior that applies in the absence of the mentioned
export parameter can be controlled using the
net.sf.jasperreports.export.pdf.force.linebreak.policy
configuration
property
getPdfJavaScript()
configuration setting, which retrieve the Acrobat JavaScript source code.
Note that Acrobat JavaScript is a programming language based on JavaScript. More
details about this can be found in the iText documentation.
PdfExporterConfiguration
class. They are all listed following:
getMetadataAuthor()
getMetadataCreator()
getMetadataKeywords()
getMetadataSubject()
getMetadataTitle()
isForceSvgShapes()
flag is used to force the rendering of SVG images using shapes on the PDF Graphics2D
context. This allows fonts to be rendered as shapes, thus avoiding any font mapping issues that
might cause Unicode text to not show up properly; however, it has the disadvantage of producing
larger PDF files.
By default, the flag is set to true, mainly due to backward-compatibility reasons. To
reduce PDF file size for documents containing SVG images such as charts, this flag
should be set to false. However, in such a case, the accuracy of the text content
rendered by the SVG element in PDF depends on the correct PDF font information being
available in the SVG implementation itself.
In JasperReports, SVG elements are rendered using
Renderable
implementations,
which are most likely subclasses of the JRAbstractSvgRenderer
class. SVG renderer implementations should be concerned only with
implementing the
public void render(JasperReportsContext jasperReportsContext, Graphics2D grx, Rectangle2D rectangle)
method, which should contain all the code
required for rendering the SVG on a Graphics2D context. Correct PDF font information
means that the java.awt.Font
objects used to draw text on the Graphics2D
context should have PDF-related text attributes embedded so that when rendered on a PDF
Graphics2D
context, the exporter can make use of them. Embedding PDF-related text
attributes into the SVG means using the following text attributes when creating
java.awt.Font
to render text in the SVG renderer implementation:
The built-in chart component in JasperReports hides this complexity of dealing with
fonts in a SVG renderer by exposing to the end user the usual three PDF-specific font
attributes (pdfFontName
, pdfEncoding
, and isPdfEmbedded
)
to be set along with the normal font attributes every time a font setting is made for the chart
title, subtitle, chart legend, or axis. This feature can be controlled system-wide using the
net.sf.jasperreports.export.pdf.force.svg.shapes
configuration property.
The isForceSvgShapes()
export configuration setting overrides the configuration property value, if present.
isTagged()
configuration flagnet.sf.jasperreports.export.pdf.tagged
configuration property.getTagLanguage()
configuration setting to retrieve the language as a java.lang.String
value;net.sf.jasperreports.export.pdf.tag.language
configuration property
globally or at report levelhyperlinkTooltipExpression
property of the image element in JRXML.
For more information about tagged PDF documents in JasperReports,
please consult the JRPdfExporterTagHelper
class.PdfExporterConfiguration
,
PdfReportConfiguration
,
JRTextAttribute.IS_PDF_EMBEDDED
,
JRTextAttribute.PDF_ENCODING
,
JRTextAttribute.PDF_FONT_NAME
Modifier and Type | Class and Description |
---|---|
protected static class |
JRPdfExporter.Bookmark |
protected static class |
JRPdfExporter.BookmarkStack |
protected class |
JRPdfExporter.ExporterContext |
JRAbstractExporter.BaseExporterContext, JRAbstractExporter.PageRange
Modifier and Type | Field and Description |
---|---|
protected int |
crtDocumentPageNumber |
protected Document |
document |
static java.lang.String |
EXCEPTION_MESSAGE_KEY_DOCUMENT_ERROR |
static java.lang.String |
EXCEPTION_MESSAGE_KEY_FONT_LOADING_ERROR |
static java.lang.String |
EXCEPTION_MESSAGE_KEY_REPORT_GENERATION_ERROR |
protected static boolean |
fontsRegistered |
protected Document |
imageTesterDocument |
protected PdfContentByte |
imageTesterPdfContentByte |
protected static java.lang.String |
JR_PAGE_ANCHOR_PREFIX |
protected java.util.Map<Renderable,Image> |
loadedImagesMap |
protected PrintPageFormat |
pageFormat |
static java.lang.String |
PDF_EXPORTER_KEY
The exporter key, as used in
GenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String) . |
static java.lang.String |
PDF_EXPORTER_PROPERTIES_PREFIX |
static java.lang.String |
PDF_FONT_DIRS_PREFIX
Prefix of properties that specify font directories for the PDF exporter.
|
static java.lang.String |
PDF_FONT_FILES_PREFIX
Prefix of properties that specify font files for the PDF exporter.
|
protected PdfContentByte |
pdfContentByte |
protected PdfWriter |
pdfWriter |
protected int |
permissions |
static java.lang.String |
PROPERTY_IGNORE_HYPERLINK
Deprecated.
Replaced by
PdfReportConfiguration.PROPERTY_IGNORE_HYPERLINK . |
protected Image |
pxImage |
protected int |
reportIndex |
protected JRPdfExporterTagHelper |
tagHelper |
allSelector, crtCompositeConfiguration, crtCompositeItemConfiguration, crtItem, dateFormatCache, EXCEPTION_MESSAGE_KEY_END_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_INVALID_IMAGE_NAME, EXCEPTION_MESSAGE_KEY_INVALID_ZOOM_RATIO, EXCEPTION_MESSAGE_KEY_MIXED_CALLS_NOT_ALLOWED, EXCEPTION_MESSAGE_KEY_OUTPUT_WRITER_ERROR, EXCEPTION_MESSAGE_KEY_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_START_PAGE_INDEX_OUT_OF_RANGE, exporterConfiguration, exporterContext, exporterInput, exporterOutput, filter, itemConfiguration, jasperPrint, jasperReportsContext, noBackcolorSelector, noneSelector, numberFormatCache, parameters, propertiesUtil, PROPERTY_DEFAULT_FILTER_FACTORY, PROPERTY_SUFFIX_DEFAULT_FILTER_FACTORY, styledTextUtil, textValueClasses
Constructor and Description |
---|
JRPdfExporter() |
JRPdfExporter(JasperReportsContext jasperReportsContext) |
Modifier and Type | Method and Description |
---|---|
protected void |
addBookmark(int level,
java.lang.String title,
int x,
int y) |
protected void |
ensureOutput() |
protected void |
exportBottomPen(JRPen leftPen,
JRPen bottomPen,
JRPen rightPen,
JRPrintElement element) |
protected void |
exportBox(JRLineBox box,
JRPrintElement element) |
protected void |
exportElements(java.util.Collection<JRPrintElement> elements) |
protected void |
exportEllipse(JRPrintEllipse ellipse) |
void |
exportFrame(JRPrintFrame frame) |
protected void |
exportGenericElement(JRGenericPrintElement element) |
void |
exportImage(JRPrintImage printImage) |
protected void |
exportLeftPen(JRPen topPen,
JRPen leftPen,
JRPen bottomPen,
JRPrintElement element) |
protected void |
exportLine(JRPrintLine line) |
protected void |
exportPage(JRPrintPage page) |
protected void |
exportPen(JRPen pen,
JRPrintElement element) |
protected void |
exportRectangle(JRPrintRectangle rectangle) |
void |
exportReport()
Performs the export.
|
protected void |
exportReportToStream(java.io.OutputStream os) |
protected void |
exportRightPen(JRPen topPen,
JRPen bottomPen,
JRPen rightPen,
JRPrintElement element) |
void |
exportText(JRPrintText text) |
protected void |
exportTopPen(JRPen topPen,
JRPen leftPen,
JRPen rightPen,
JRPrintElement element) |
protected Chunk |
getChunk(java.util.Map<java.text.AttributedCharacterIterator.Attribute,java.lang.Object> attributes,
java.lang.String text,
java.util.Locale locale) |
protected java.lang.Class<PdfExporterConfiguration> |
getConfigurationInterface() |
protected PrintPageFormat |
getCurrentPageFormat() |
java.lang.String |
getExporterKey() |
java.lang.String |
getExporterPropertiesPrefix()
Returns the properties prefix for the current exporter.
|
protected Font |
getFont(java.util.Map<java.text.AttributedCharacterIterator.Attribute,java.lang.Object> attributes,
java.util.Locale locale,
boolean setFontLines)
Creates a PDF font.
|
static int |
getIntegerPermissions(java.lang.String permissions) |
protected java.lang.Class<PdfReportConfiguration> |
getItemConfigurationInterface() |
protected int |
getOffsetX()
Returns the X axis offset used for element export.
|
protected int |
getOffsetY()
Returns the Y axis offset used for element export.
|
protected Phrase |
getPhrase(java.text.AttributedString as,
java.lang.String text,
JRPrintText textElement) |
protected Image |
getPxImage() |
protected boolean |
hasStrikethrough(java.util.Map<java.text.AttributedCharacterIterator.Attribute,java.lang.Object> textAttributes) |
protected boolean |
hasUnderline(java.util.Map<java.text.AttributedCharacterIterator.Attribute,java.lang.Object> textAttributes) |
protected void |
initBookmarks(java.util.List<ExporterInputItem> items) |
protected void |
initExport() |
protected void |
initReport() |
protected static void |
registerFonts() |
protected void |
setAnchor(Chunk chunk,
JRPrintAnchor anchor,
JRPrintElement element) |
protected void |
setHyperlinkInfo(Chunk chunk,
JRPrintHyperlink link) |
protected void |
setPageSize(JRPrintPage page) |
protected void |
writePageAnchor(int pageIndex) |
createFilter, defaultParseNumber, ensureInput, ensureJasperReportsContext, getBooleanCellValue, getCurrentConfiguration, getCurrentItemConfiguration, getCurrentJasperPrint, getCustomHandler, getDateCellValue, getDateFormat, getExporterContext, getExporterInput, getExporterOutput, getHyperlinkProducer, getJasperReportsContext, getLocale, getNumberCellValue, getNumberFormat, getPageRange, getParameter, getParameters, getPropertiesUtil, getReportContext, getStyledText, getStyledText, getTextFormatFactoryClass, getTextLocale, getTextTimeZone, getTextValue, getTextValueString, insideFrame, reset, resetClassLoader, resetExportContext, restoreElementOffsets, setClassLoader, setConfiguration, setConfiguration, setCurrentExporterInputItem, setExporterInput, setExporterOutput, setFrameElementsOffset, setJasperPrint, setJasperReportsContext, setOffset, setOffset, setParameter, setParameters, setReportContext
public static final java.lang.String PDF_EXPORTER_PROPERTIES_PREFIX
public static final java.lang.String EXCEPTION_MESSAGE_KEY_DOCUMENT_ERROR
public static final java.lang.String EXCEPTION_MESSAGE_KEY_FONT_LOADING_ERROR
public static final java.lang.String EXCEPTION_MESSAGE_KEY_REPORT_GENERATION_ERROR
public static final java.lang.String PROPERTY_IGNORE_HYPERLINK
PdfReportConfiguration.PROPERTY_IGNORE_HYPERLINK
.public static final java.lang.String PDF_FONT_FILES_PREFIX
public static final java.lang.String PDF_FONT_DIRS_PREFIX
public static final java.lang.String PDF_EXPORTER_KEY
GenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)
.protected static final java.lang.String JR_PAGE_ANCHOR_PREFIX
protected static boolean fontsRegistered
protected Document document
protected PdfContentByte pdfContentByte
protected PdfWriter pdfWriter
protected Document imageTesterDocument
protected PdfContentByte imageTesterPdfContentByte
protected JRPdfExporterTagHelper tagHelper
protected int reportIndex
protected PrintPageFormat pageFormat
protected int crtDocumentPageNumber
protected int permissions
protected java.util.Map<Renderable,Image> loadedImagesMap
protected Image pxImage
public JRPdfExporter()
JRPdfExporter(JasperReportsContext)
public JRPdfExporter(JasperReportsContext jasperReportsContext)
protected java.lang.Class<PdfExporterConfiguration> getConfigurationInterface()
protected java.lang.Class<PdfReportConfiguration> getItemConfigurationInterface()
protected void ensureOutput()
protected Image getPxImage()
public void exportReport() throws JRException
Exporter
exportReport
in interface Exporter<ExporterInput,PdfReportConfiguration,PdfExporterConfiguration,OutputStreamExporterOutput>
exportReport
in class JRAbstractExporter<PdfReportConfiguration,PdfExporterConfiguration,OutputStreamExporterOutput,JRPdfExporterContext>
JRException
protected void initExport()
protected void initReport()
protected void exportReportToStream(java.io.OutputStream os) throws JRException
JRException
protected void writePageAnchor(int pageIndex) throws DocumentException
DocumentException
protected void setPageSize(JRPrintPage page) throws JRException, DocumentException, java.io.IOException
JRException
DocumentException
java.io.IOException
protected void exportPage(JRPrintPage page) throws JRException, DocumentException, java.io.IOException
JRException
DocumentException
java.io.IOException
protected void exportElements(java.util.Collection<JRPrintElement> elements) throws DocumentException, java.io.IOException, JRException
DocumentException
java.io.IOException
JRException
protected void exportLine(JRPrintLine line)
protected void exportRectangle(JRPrintRectangle rectangle)
protected void exportEllipse(JRPrintEllipse ellipse)
public void exportImage(JRPrintImage printImage) throws DocumentException, java.io.IOException, JRException
DocumentException
java.io.IOException
JRException
protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link)
protected Phrase getPhrase(java.text.AttributedString as, java.lang.String text, JRPrintText textElement)
protected Chunk getChunk(java.util.Map<java.text.AttributedCharacterIterator.Attribute,java.lang.Object> attributes, java.lang.String text, java.util.Locale locale)
protected boolean hasUnderline(java.util.Map<java.text.AttributedCharacterIterator.Attribute,java.lang.Object> textAttributes)
protected boolean hasStrikethrough(java.util.Map<java.text.AttributedCharacterIterator.Attribute,java.lang.Object> textAttributes)
protected Font getFont(java.util.Map<java.text.AttributedCharacterIterator.Attribute,java.lang.Object> attributes, java.util.Locale locale, boolean setFontLines)
attributes
- the text attributes of the fontlocale
- the locale for which to create the fontsetFontLines
- whether to set underline and strikethrough as font stylepublic void exportText(JRPrintText text) throws DocumentException
DocumentException
protected void exportBox(JRLineBox box, JRPrintElement element)
protected void exportPen(JRPen pen, JRPrintElement element)
protected void exportTopPen(JRPen topPen, JRPen leftPen, JRPen rightPen, JRPrintElement element)
protected void exportLeftPen(JRPen topPen, JRPen leftPen, JRPen bottomPen, JRPrintElement element)
protected void exportBottomPen(JRPen leftPen, JRPen bottomPen, JRPen rightPen, JRPrintElement element)
protected void exportRightPen(JRPen topPen, JRPen bottomPen, JRPen rightPen, JRPrintElement element)
protected static void registerFonts()
protected void initBookmarks(java.util.List<ExporterInputItem> items)
protected void addBookmark(int level, java.lang.String title, int x, int y)
protected void setAnchor(Chunk chunk, JRPrintAnchor anchor, JRPrintElement element)
public void exportFrame(JRPrintFrame frame) throws DocumentException, java.io.IOException, JRException
DocumentException
java.io.IOException
JRException
protected PrintPageFormat getCurrentPageFormat()
protected int getOffsetX()
JRAbstractExporter
getOffsetX
in class JRAbstractExporter<PdfReportConfiguration,PdfExporterConfiguration,OutputStreamExporterOutput,JRPdfExporterContext>
protected int getOffsetY()
JRAbstractExporter
getOffsetY
in class JRAbstractExporter<PdfReportConfiguration,PdfExporterConfiguration,OutputStreamExporterOutput,JRPdfExporterContext>
protected void exportGenericElement(JRGenericPrintElement element)
public java.lang.String getExporterKey()
public java.lang.String getExporterPropertiesPrefix()
JRAbstractExporter
getExporterPropertiesPrefix
in class JRAbstractExporter<PdfReportConfiguration,PdfExporterConfiguration,OutputStreamExporterOutput,JRPdfExporterContext>
public static int getIntegerPermissions(java.lang.String permissions)
© 2001-2014 TIBCO Software Inc. www.jaspersoft.com