| Method from org.jfree.report.modules.output.pageable.pdf.PDFOutputTarget Detail: |
public void beginPage(PhysicalPage format) {
if (isOpen() == false)
{
throw new IllegalStateException("Target " + hashCode() + " is not open");
}
try
{
setPaint(ElementDefaultStyleSheet.DEFAULT_PAINT);
setStroke(ShapeElement.DEFAULT_STROKE);
setFont(ElementDefaultStyleSheet.DEFAULT_FONT_DEFINITION);
}
catch (OutputTargetException oe)
{
Log.error("Should not happen", oe);
}
this.writer.getDirectContent().saveState();
this.currentPageFormat = format.getPageFormat();
}
Signals that a page is being started. Stores the state of the target to
make it possible to restore the complete outputtarget. |
public void close() {
this.getDocument().close();
this.fontSupport.close();
this.pdfDocument = null;
this.writer = null;
}
|
public void configure(ReportConfiguration config) {
updateProperty(SECURITY_OWNERPASSWORD, config);
updateProperty(SECURITY_USERPASSWORD, config);
updateProperty(AUTHOR, config);
updateProperty(ENCODING, config);
updateProperty(PDF_VERSION, config);
updateBooleanProperty(EMBED_FONTS, config);
updateBooleanProperty(SECURITY_ALLOW_ASSEMBLY, config);
updateBooleanProperty(SECURITY_ALLOW_COPY, config);
updateBooleanProperty(SECURITY_ALLOW_DEGRADED_PRINTING, config);
updateBooleanProperty(SECURITY_ALLOW_FILLIN, config);
updateBooleanProperty(SECURITY_ALLOW_MODIFY_ANNOTATIONS, config);
updateBooleanProperty(SECURITY_ALLOW_MODIFY_CONTENTS, config);
updateBooleanProperty(SECURITY_ALLOW_PRINTING, config);
updateBooleanProperty(SECURITY_ALLOW_SCREENREADERS, config);
updateBooleanProperty(SECURITY_OWNERPASSWORD, config);
updateBooleanProperty(SECURITY_USERPASSWORD, config);
// encryption needs more info: < undefined > < none > < 40 > < 128 >.
updateProperty(SECURITY_ENCRYPTION, config);
}
Configures the output target. |
public OutputTarget createDummyWriter() {
return new DummyOutputTarget(this);
}
Creates an output target that mimics a real output target, but produces no output.
This is used by the reporting engine when it makes its first pass through the report,
calculating page boundaries etc. The second pass will use a real output target. |
public SizeCalculator createTextSizeCalculator(FontDefinition font) throws OutputTargetException {
try
{
final BaseFontRecord record = fontSupport.createBaseFont
(font, font.getFontEncoding(getFontEncoding()),
(isEmbedFonts() || font.isEmbeddedFont()));
return new PDFSizeCalculator(record.getBaseFont(),
font.getFont().getSize2D());
}
catch (BaseFontCreateException bfce)
{
throw new OutputTargetException("The font definition was not successfull.", bfce);
}
}
Creates a 'size calculator' for the current state of the output target. The calculator
is used to calculate the string width and line height and later maybe more. |
public void drawDrawable(DrawableContainer drawable) {
// cant be done using Wmf, as Wmf does not support Unicode and Bitmaps... damn
// not yet implemented, needs WMF Converter ...
// only the drawable clippingbounds region will be drawn.
// the clipping is set to the clipping bounds of the drawable
// the clipping bounds are relative to the drawable dimension,
// they are not influenced by the drawables position on the page
// todo: Whats going on here?
// final Rectangle2D operationBounds = getOperationBounds();
// final Rectangle2D clipBounds = drawable.getClippingBounds();
//
// final Graphics2D target =
// writer.getDirectContent().createGraphics
// ((float) clipBounds.getWidth(), (float) clipBounds.getHeight());
// target.translate
// (operationBounds.getX() + clipBounds.getX(),
// operationBounds.getY() + clipBounds.getY());
// target.clip(new Rectangle2D.Float(0, 0,
// (float) clipBounds.getWidth(),
// (float) clipBounds.getHeight()));
//
// final Dimension2D drawableSize = drawable.getDrawableSize();
// final Rectangle2D drawBounds = new Rectangle2D.Float(0, 0,
// (float) drawableSize.getWidth(),
// (float) drawableSize.getHeight());
// drawable.getDrawable().draw(target, drawBounds);
// target.dispose();
final Rectangle2D bounds = getInternalOperationBounds();
final float x = (float) (bounds.getX());
final float y = (float) (bounds.getY());
final Rectangle2D clipBounds = drawable.getClippingBounds();
final Graphics2D target = writer.getDirectContent().createGraphics(
(float) clipBounds.getWidth() + x, (getPageHeight() - y));
target.translate(x, 0);
final Dimension2D drawableSize = drawable.getDrawableSize();
final Rectangle2D drawBounds = new Rectangle2D.Float(0, 0,
(float) drawableSize.getWidth(),
(float) drawableSize.getHeight());
drawable.getDrawable().draw(target, drawBounds);
target.dispose();
}
Draws a drawable relative to the current position. |
public void drawImage(ImageReference imageRef) throws OutputTargetException {
try
{
final Rectangle2D bounds = getInternalOperationBounds();
final Rectangle2D imageBounds = imageRef.getBoundsScaled();
final float x = (float) (bounds.getX());
final float y = (float) (bounds.getY());
final Image image = getImage(imageRef);
image.setAbsolutePosition(x, (float) (getPageHeight() - y - bounds.getHeight()));
image.scaleAbsolute((float) imageBounds.getWidth(),
(float) imageBounds.getHeight());
final PdfContentByte cb = this.writer.getDirectContent();
cb.rectangle((float) (imageBounds.getX() + x),
(float) (getPageHeight() - imageBounds.getY() - y - bounds.getHeight()),
(float) imageBounds.getWidth(),
(float) imageBounds.getHeight());
cb.clip();
cb.newPath();
cb.addImage(image);
cb.restoreState();
cb.saveState();
}
catch (BadElementException be)
{
throw new OutputTargetException("BadElementException", be);
}
catch (DocumentException de)
{
throw new OutputTargetException("DocumentException", de);
}
catch (MalformedURLException mf)
{
throw new OutputTargetException("Invalid URL in ImageReference", mf);
}
catch (IOException mf)
{
throw new OutputTargetException("URL Content could not be read", mf);
}
}
Draws an image from this ImageReference . The image is directly embedded into the
pdf file to provide the best scaling support. |
public void drawShape(Shape shape) {
final Rectangle2D bounds = getInternalOperationBounds();
final float ycorr = (float) bounds.getY();
final float xcorr = (float) bounds.getX();
final PathIterator pit = shape.getPathIterator(null);
final PdfContentByte cb = this.writer.getDirectContent();
cb.newPath();
cb.moveTo(xcorr, getCorrectedY(ycorr));
final float[] params = new float[6];
// How to apply this? This should be needed in fillShape
while (pit.isDone() == false)
{
final int cmd = pit.currentSegment(params);
params[1] = getCorrectedY(params[1] + ycorr);
params[3] = getCorrectedY(params[3] + ycorr);
params[5] = getCorrectedY(params[5] + ycorr);
params[0] = params[0] + xcorr;
params[2] = params[2] + xcorr;
params[4] = params[4] + xcorr;
switch (cmd)
{
case PathIterator.SEG_MOVETO:
{
cb.moveTo(params[0], params[1]);
break;
}
case PathIterator.SEG_LINETO:
{
cb.lineTo(params[0], params[1]);
break;
}
case PathIterator.SEG_CUBICTO:
{
cb.curveTo(params[0], params[1],
params[2], params[3],
params[4], params[5]);
break;
}
case PathIterator.SEG_QUADTO:
{
cb.curveTo(params[0], params[1],
params[2], params[3]);
break;
}
case PathIterator.SEG_CLOSE:
{
cb.closePath();
break;
}
default:
{
Log.warn("Unexpected path iterator type: " + cmd);
}
}
pit.next();
}
cb.stroke();
}
Draws a shape at the specified location. The shape is drawn using a PathIterator. All
Shapes are supported. Set a stroke and a paint before drawing. The shape is not filled. |
public void drawString(String text) {
final Rectangle2D bounds = getInternalOperationBounds();
final int fontSize = getFont().getFontSize();
final PdfContentByte cb = this.writer.getDirectContent();
cb.beginText();
cb.setFontAndSize(this.baseFont, fontSize);
final float y2 = (float) (bounds.getY() +
baseFont.getFontDescriptor(BaseFont.ASCENT, fontSize));
cb.showTextAligned(
PdfContentByte.ALIGN_LEFT,
text,
(float) bounds.getX(),
this.getPageHeight() - y2,
0);
cb.endText();
}
Draws the band onto the specified graphics device. The Text is printed on the
bottom of the elements bounds. |
public void endPage() throws OutputTargetException {
try
{
this.writer.getDirectContent().restoreState();
this.getDocument().newPage();
}
catch (Exception e)
{
throw new OutputTargetException("Failed to end page", e);
}
}
This method is called when the page is ended. |
public void fillShape(Shape shape) {
final Rectangle2D bounds = getInternalOperationBounds();
final float ycorr = (float) bounds.getY();
final float xcorr = (float) bounds.getX();
final PathIterator pit = shape.getPathIterator(null);
final PdfContentByte cb = this.writer.getDirectContent();
cb.newPath();
cb.moveTo(xcorr, getCorrectedY(ycorr));
final int windingRule = pit.getWindingRule();
final float[] params = new float[6];
// How to apply this? This should be needed in fillShape
while (pit.isDone() == false)
{
final int cmd = pit.currentSegment(params);
params[1] = getCorrectedY(params[1] + ycorr);
params[3] = getCorrectedY(params[3] + ycorr);
params[5] = getCorrectedY(params[5] + ycorr);
params[0] = params[0] + xcorr;
params[2] = params[2] + xcorr;
params[4] = params[4] + xcorr;
switch (cmd)
{
case PathIterator.SEG_MOVETO:
{
cb.moveTo(params[0], params[1]);
break;
}
case PathIterator.SEG_LINETO:
{
cb.lineTo(params[0], params[1]);
break;
}
case PathIterator.SEG_CUBICTO:
{
cb.curveTo(params[0], params[1],
params[2], params[3],
params[4], params[5]);
break;
}
case PathIterator.SEG_QUADTO:
{
cb.curveTo(params[0], params[1],
params[2], params[3]);
break;
}
case PathIterator.SEG_CLOSE:
{
cb.closePath();
break;
}
default:
{
Log.warn("Unexpected path iterator type: " + cmd);
}
}
pit.next();
}
if (windingRule == PathIterator.WIND_EVEN_ODD)
{
cb.eoFill();
}
else
{
cb.fill();
}
}
Draws a shape at the specified location. The shape is drawn using a PathIterator. All
Shapes are supported. Set a stroke and a paint before drawing. The shape is filled using
the current paint and no outline is drawn. |
public BaseFont getBaseFont() {
return baseFont;
}
Returns the iText BaseFont. |
public static String getDefaultPDFEncoding() {
return ReportConfiguration.getGlobalConfig().getConfigProperty
(PDFTARGET_ENCODING, PDFTARGET_ENCODING_DEFAULT);
}
Returns the PDF encoding property value. |
public FontDefinition getFont() {
return fontDefinition;
}
Returns the currently active AWT-Font. |
public Paint getPaint() {
return awtPaint;
}
Returns the currently set paint. |
public Stroke getStroke() {
return awtStroke;
}
Returns the current stroke. |
public static boolean isDefaultEmbedFonts() {
return ReportConfiguration.getGlobalConfig().getConfigProperty
(PDFTARGET_EMBED_FONTS, PDFTARGET_EMBED_FONTS_DEFAULT).equalsIgnoreCase("true");
}
Returns true, if the Graphics2D should use aliasing to render text. Defaults to false. |
public boolean isOpen() {
if (getDocument() == null)
{
return false;
}
return getDocument().isOpen();
}
Returns true if the output target is open, and false otherwise. |
public void open() throws OutputTargetException {
final PageFormat pageFormat = getLogicalPage().getPhysicalPageFormat();
final float urx = (float) pageFormat.getWidth();
final float ury = (float) pageFormat.getHeight();
final float marginLeft = (float) pageFormat.getImageableX();
final float marginRight =
(float) (pageFormat.getWidth()
- pageFormat.getImageableWidth()
- pageFormat.getImageableX());
final float marginTop = (float) pageFormat.getImageableY();
final float marginBottom =
(float) (pageFormat.getHeight()
- pageFormat.getImageableHeight()
- pageFormat.getImageableY());
final Rectangle pageSize = new Rectangle(urx, ury);
try
{
// if (pageFormat.getOrientation() == PageFormat.LANDSCAPE)
// {
// pageSize.rotate();
// }
// else if (pageFormat.getOrientation() == PageFormat.REVERSE_LANDSCAPE)
// {
// pageSize.rotate();
// pageSize.rotate();
// pageSize.rotate();
// }
//
setDocument(new Document(pageSize, marginLeft, marginRight, marginTop, marginBottom));
writer = PdfWriter.getInstance(getDocument(), out);
writer.setLinearPageMode();
final char version = getVersion(getProperty(PDF_VERSION, PDF_VERSION_DEFAULT));
writer.setPdfVersion(version);
final String encrypt = getProperty(SECURITY_ENCRYPTION);
if (encrypt != null)
{
if (encrypt.equals(SECURITY_ENCRYPTION_128BIT) == true
|| encrypt.equals(SECURITY_ENCRYPTION_40BIT) == true)
{
final String userpassword = getProperty(SECURITY_USERPASSWORD);
final String ownerpassword = getProperty(SECURITY_OWNERPASSWORD);
final byte[] userpasswordbytes = DocWriter.getISOBytes(userpassword);
byte[] ownerpasswordbytes = DocWriter.getISOBytes(ownerpassword);
if (ownerpasswordbytes == null)
{
ownerpasswordbytes = PDF_PASSWORD_PAD;
}
writer.setEncryption(userpasswordbytes, ownerpasswordbytes, getPermissions(),
encrypt.equals(SECURITY_ENCRYPTION_128BIT));
}
}
/**
* MetaData can be set when the writer is registered to the document.
*/
final String title = getProperty(TITLE);
final String author = getProperty(AUTHOR);
if (title != null)
{
getDocument().addTitle(title);
}
if (author != null)
{
getDocument().addAuthor(author);
}
getDocument().addCreator(CREATOR);
getDocument().addCreationDate();
getDocument().open();
//writer.getDirectContent().beginTransaction();
}
catch (Exception e)
{
throw new OutputTargetException("Opening Document failed.", e);
}
}
|
public static void setDefaultEmbedFonts(boolean embed) {
ReportConfiguration.getGlobalConfig().setConfigProperty
(PDFTARGET_EMBED_FONTS, String.valueOf(embed));
}
set to true, if the PDFOutputTarget should embed all fonts. |
public static void setDefaultPDFEncoding(String pdfTargetEncoding) {
ReportConfiguration.getGlobalConfig().setConfigProperty
(PDFTARGET_ENCODING, pdfTargetEncoding);
}
Sets the PDF encoding property value. |
public void setFont(FontDefinition font) throws OutputTargetException {
if (font == null)
{
throw new NullPointerException();
}
// do nothing if this font is already set
if (baseFont != null && fontDefinition != null && fontDefinition.equals(font))
{
return; // no need to do anything ...
}
this.fontDefinition = font;
try
{
// Log.debug("Embed: " + isEmbedFonts() + " vs. " + font.isEmbeddedFont());
this.baseFont = fontSupport.createBaseFont(font, font.getFontEncoding(getFontEncoding()),
(isEmbedFonts() || font.isEmbeddedFont())).getBaseFont();
if (baseFont == null)
{
throw new OutputTargetException("The font definition was not successfull.");
}
}
catch (BaseFontCreateException bfce)
{
throw new OutputTargetException("The font definition was not successfull.", bfce);
}
}
Sets the current font. The font is mapped to pdf specific fonts if possible.
If no basefont could be created, an OutputTargetException is thrown. |
public void setFontEncoding(String encoding) {
if (encoding == null)
{
throw new NullPointerException();
}
setProperty(ENCODING, encoding);
}
Defines the text encoding used in this output target.
- The Unicode encoding with horizontal writing is "Identity-H"
- The Unicode encoding with vertical writing is "Identity-V"
- "Cp1250"
- "Cp1252" is also known as WinAnsi
- "Cp1257"
- "MacRoman"
|
public void setOperationBounds(Rectangle2D bounds) {
super.setOperationBounds(bounds);
internalOperationBounds
= new Rectangle2D.Float((float) (bounds.getX() + currentPageFormat.getImageableX()),
(float) (bounds.getY() + currentPageFormat.getImageableY()),
(float) bounds.getWidth(), (float) bounds.getHeight());
}
Sets the operation bounds. |
public void setPaint(Paint paint) throws OutputTargetException {
if (paint == null)
{
throw new NullPointerException();
}
if (paint instanceof Color == false)
{
throw new OutputTargetException("Unsupported paint type, currently only color is supported");
}
// If this paint is already set, do nothing
if (awtPaint != null && awtPaint.equals(paint))
{
return;
}
this.awtPaint = paint;
final PdfContentByte cb = this.writer.getDirectContent();
cb.setColorStroke((Color) paint);
cb.setColorFill((Color) paint);
}
Sets the paint. If the paint could not be converted into a pdf object, an OutputTargetException
is thrown. This implementation currently supports java.awt.Color as the only valid paint. |
public void setStroke(Stroke stroke) throws OutputTargetException {
if (stroke == null)
{
throw new NullPointerException();
}
if (stroke instanceof BasicStroke == false)
{
throw new OutputTargetException("Unable to handle this stroke type");
}
// If this stroke is already set, do nothing
if (awtStroke != null && awtStroke.equals(stroke))
{
return;
}
this.awtStroke = stroke;
final BasicStroke bstroke = (BasicStroke) stroke;
final PdfContentByte cb = this.writer.getDirectContent();
cb.setLineWidth(bstroke.getLineWidth());
}
Defines the stroke used to draw shapes. If the stroke is of an invalid type, an
OutputTargetException is thrown. Currently only BasicStroke is supported. |