Class Container
A group of drawable elements that are moved, rotated and scaled together: shapes, text, images, annotations, stamps and nested containers.
What a container is good at: it takes anything that implements IDrawable, so a group can hold an Image, a Table, a chart, a barcode, a link or another annotation, and each element keeps everything it can do. Each element also tags itself in a PDF/UA document, so a TextLine in a container is a paragraph of its own and an Image is a figure with its alternate description. Laying a group out once and placing it, rotated or scaled, is what it is for; elements that have no rotation of their own get one this way.
What it costs: the elements are drawn into the page on every DrawOn, so a container on 100 pages writes its drawing 100 times over.
Use a Stamp instead for content that repeats on many pages -- a header, a footer, a logo, a watermark -- which is written once as a form XObject and placed with a few bytes. Of a 200 by 50 point box with two lines of text, a container writes 367 bytes into every page and a stamp 83, so the stamp is the smaller of the two from the fourth page on: over 100 pages it saves 12,855 bytes of a 104,530 byte file, and over 500 pages 66,052 of 275,553. On one page the stamp is the larger, since its XObject costs about 300 bytes of its own, and it draws only paths and text in an embedded font.
Please see Example_42 and Example_31.
public class Container : IDrawable
- Inheritance
-
Container
- Implements
- Inherited Members
Constructors
Container(float, float)
Creates a new container with the specified width and height. The container is initialized with:
- Rotation set to 0 degrees
- Scaling factors set to 1.0 for both axes
- An empty list of drawable elements
public Container(float width, float height)
Parameters
Methods
Add(IDrawable)
Adds a drawable element to this container.
public Container Add(IDrawable element)
Parameters
elementIDrawableThe element to add.
Returns
- Container
this Container object.
DrawOn(Page)
Draws this container and its child elements onto the page.
public float[] DrawOn(Page page)
Parameters
Returns
- float[]
An array containing the bottom-right position of the container.
Exceptions
- Exception
Thrown if drawing fails.
GetRotationCenter()
Returns the center of this container, which it rotates around.
public float[] GetRotationCenter()
Returns
- float[]
ScaleBy(float)
Sets a uniform scaling factor for both X and Y axes.
public Container ScaleBy(float factor)
Parameters
factorfloatThe scaling factor to apply.
Returns
ScaleBy(float, float)
Sets non-uniform scaling factors for the X and Y axes.
public Container ScaleBy(float sx, float sy)
Parameters
Returns
SetBorderColor(int)
Sets the 0xRRGGBB color of the border around this container. Color.transparent leaves it unchanged.
public Container SetBorderColor(int borderColor)
Parameters
borderColorint
Returns
SetBorderColor(float[])
Sets the color of the border around this container.
public Container SetBorderColor(float[] rgbColor)
Parameters
rgbColorfloat[]the color as red, green and blue components from 0.0 to 1.0.
Returns
- Container
this Container object.
SetLocation(float, float)
Sets the location of the container on the page.
public Container SetLocation(float x, float y)
Parameters
Returns
SetRotation(float)
Rotates this container around its center: clockwise for a positive angle, as every rotation in PDFjet turns, and counterclockwise for a negative angle.
public Container SetRotation(float degrees)
Parameters
degreesfloatThe rotation angle in degrees.