PdfCanvas
Mojo struct 🡭
PdfCanvas
@memory_only
struct PdfCanvasA PDF document built from DrawTarget calls, one page at a time; see the module docstring for what each becomes. to_bytes produces the file, write_pdf writes it.
Fields
- width (
Int) - height (
Int)
Implemented traits
AnyType, Deinitable, DrawTarget, Movable
Methods
__init__
fn def __init__(out self, width: Int, height: Int)A document with one empty page of width x height points.
Args:
- width (
Int): Page width in points. - height (
Int): Page height in points. - self (
Self)
Returns:
Self
Raises:
new_page
fn def new_page(mut self, width: Int = Int(-1), height: Int = Int(-1))Finish the current page and start another, of the same size unless width and height say otherwise. Open clips and an open annotated group are closed on the page they belong to; the transform, blend mode and color space carry over, as they are drawing state rather than page state.
Args:
- self (
Self) - width (
Int): The new page’s width in points, or -1 for the same. - height (
Int): The new page’s height in points, or -1 for the same.
page_count
fn def page_count(self) -> IntHow many pages the document has, the current one included.
Args:
- self (
Self)
Returns:
Int
save
fn def save(mut self)Push the transform, blend mode, color space and clip depth for restore to put back, as Canvas.save does.
Args:
- self (
Self)
restore
fn def restore(mut self)Pop the state save pushed, closing every clip pushed since. A no-op with nothing saved.
Args:
- self (
Self)
translate
fn def translate(mut self, tx: Float64, ty: Float64)Move the origin by (tx, ty) in the current user space.
Args:
- self (
Self) - tx (
Float64) - ty (
Float64)
rotate
fn def rotate(mut self, angle: Float64)Rotate later drawing by angle radians about the origin.
Args:
- self (
Self) - angle (
Float64)
scale
fn def scale(mut self, sx: Float64, sy: Float64)Scale later drawing by (sx, sy) about the origin.
Args:
- self (
Self) - sx (
Float64) - sy (
Float64)
transform
fn def transform(mut self, matrix: Matrix2D)Apply matrix ahead of the current transform.
Args:
- self (
Self) - matrix (
Matrix2D)
set_transform
fn def set_transform(mut self, matrix: Matrix2D)Replace the current transform with matrix.
Args:
- self (
Self) - matrix (
Matrix2D)
reset_transform
fn def reset_transform(mut self)Back to the identity.
Args:
- self (
Self)
current_transform
fn def current_transform(self) -> Matrix2DThe transform later drawing goes through.
Args:
- self (
Self)
Returns:
Matrix2D
has_transform
fn def has_transform(self) -> BoolWhether the current transform is not the identity.
Args:
- self (
Self)
Returns:
Bool
set_blend_mode
fn def set_blend_mode(mut self, mode: BlendMode)Set the blend mode later elements carry as an ExtGState /BM. The Porter-Duff operators have no PDF equivalent and draw source-over.
Args:
- self (
Self) - mode (
BlendMode): The blend mode later elements carry.
blend_mode
fn def blend_mode(self) -> BlendModeThe blend mode later elements carry.
Args:
- self (
Self)
Returns:
BlendMode
set_color_space
fn def set_color_space(mut self, space: ColorSpace)Recorded for color_space and save/restore; PDF has no linear-light compositing to ask for, so it changes nothing drawn.
Args:
- self (
Self) - space (
ColorSpace): The color space, kept but not applied.
color_space
fn def color_space(self) -> ColorSpaceThe color space last set.
Args:
- self (
Self)
Returns:
ColorSpace
set_title
fn def set_title(mut self, title: String)The document’s /Title, in its /Info dictionary.
Args:
- self (
Self) - title (
String): Document title.
set_author
fn def set_author(mut self, author: String)The document’s /Author, in its /Info dictionary.
Args:
- self (
Self) - author (
String): Document author.
fill_rect
fn def fill_rect(mut self, x: Int, y: Int, width: Int, height: Int, color: Color)A filled rectangle (re f).
Args:
- self (
Self) - x (
Int): Left edge. - y (
Int): Top edge. - width (
Int): Width. - height (
Int): Height. - color (
Color): Fill color.
fn def fill_rect(mut self, x: Float64, y: Float64, width: Float64, height: Float64, color: Color)A filled rectangle at a geometric position.
Args:
- self (
Self) - x (
Float64): Left edge. - y (
Float64): Top edge. - width (
Float64): Width. - height (
Float64): Height. - color (
Color): Fill color.
draw_line_aa
fn def draw_line_aa(mut self, x0: Int, y0: Int, x1: Int, y1: Int, color: Color, width: Float64 = 1, dashes: List[Float64] = List(), dash_offset: Float64 = 0, cap: LineCap = LineCap.ROUND, join: LineJoin = LineJoin.ROUND, miter_limit: Float64 = 4)A stroked line segment.
Args:
- self (
Self) - x0 (
Int): Start x. - y0 (
Int): Start y. - x1 (
Int): End x. - y1 (
Int): End y. - color (
Color): Stroke color. - width (
Float64): Stroke width. - dashes (
List[Float64]): On/off lengths; empty for solid. - dash_offset (
Float64): Distance into the dash pattern to start. - cap (
LineCap): Line cap. - join (
LineJoin): Line join (unused on a single segment). - miter_limit (
Float64): Miter limit.
fn def draw_line_aa(mut self, x0: Float64, y0: Float64, x1: Float64, y1: Float64, color: Color, width: Float64 = 1, dashes: List[Float64] = List(), dash_offset: Float64 = 0, cap: LineCap = LineCap.ROUND, join: LineJoin = LineJoin.ROUND, miter_limit: Float64 = 4)A stroked line segment at geometric endpoints.
Args:
- self (
Self) - x0 (
Float64): Start x. - y0 (
Float64): Start y. - x1 (
Float64): End x. - y1 (
Float64): End y. - color (
Color): Stroke color. - width (
Float64): Stroke width. - dashes (
List[Float64]): On/off lengths; empty for solid. - dash_offset (
Float64): Distance into the dash pattern to start. - cap (
LineCap): Line cap. - join (
LineJoin): Line join (unused on a single segment). - miter_limit (
Float64): Miter limit.
fill_circles_aa
fn def fill_circles_aa(mut self, centers: List[FPoint], radius: Float64, color: Color)DrawTarget’s batched disks. This backend emits a filled path per marker whichever entry point is used, so the batch is the loop and the output is unchanged by construction.
Args:
- self (
Self) - centers (
List[FPoint]): Sub-pixel centre of each marker, in draw order. - radius (
Float64): Radius shared by every marker, in pixels. - color (
Color): Fill color shared by every marker.
Raises:
fn def fill_circles_aa(mut self, centers: List[FPoint], radius: Float64, colors: List[Color])fill_circles_aa with a color per marker.
Args:
- self (
Self) - centers (
List[FPoint]): Sub-pixel centre of each marker, in draw order. - radius (
Float64): Radius shared by every marker, in pixels. - colors (
List[Color]): One color per centre, same length ascenters.
Raises:
Error: If colors is not the same length as centers.
fill_mesh
fn def fill_mesh(mut self, points: List[FPoint], faces: List[Int], colors: List[Color])DrawTarget’s mesh: one path per face. Viewers seam adjacent anti-aliased fills as the raster backend did, so an opaque face is filled and stroked together (B) in its own color at width 0, which PDF defines as the thinnest line the device can draw. A translucent face is filled only, for the reason SvgCanvas.fill_mesh gives.
Args:
- self (
Self) - points (
List[FPoint]): The vertices, in user space. - faces (
List[Int]): Index triples intopoints, in draw order. - colors (
List[Color]): One color per triangle.
Raises:
Error: faces is not whole triples, an index is out of
range, or colors is not one per triangle.
fill_mesh_shaded
fn def fill_mesh_shaded(mut self, points: List[FPoint], faces: List[Int], vertex_colors: List[Color])DrawTarget’s smooth-shaded mesh, as PDF has it natively: a Type 4 shading, a free-form Gouraud triangle mesh, painted with sh. Each vertex is a flag byte, two 32-bit coordinates over the mesh’s own bounding box and three color bytes, so the viewer interpolates exactly the corners this was given. The shading has no alpha per vertex; a translucent mesh takes the mean of its vertices’ alpha as a constant.
Args:
- self (
Self) - points (
List[FPoint]): The vertices, in user space. - faces (
List[Int]): Index triples intopoints, in draw order. - vertex_colors (
List[Color]): One color per vertex.
Raises:
Error: faces is not whole triples, an index is out of
range, or vertex_colors is not one per vertex.
fill_circle_aa
fn def fill_circle_aa(mut self, cx: Int, cy: Int, radius: Int, color: Color)A filled circle.
Args:
- self (
Self) - cx (
Int): Center x. - cy (
Int): Center y. - radius (
Int): Radius. - color (
Color): Fill color.
fn def fill_circle_aa(mut self, cx: Float64, cy: Float64, radius: Float64, color: Color)A filled circle at a geometric center.
Args:
- self (
Self) - cx (
Float64): Center x. - cy (
Float64): Center y. - radius (
Float64): Radius. - color (
Color): Fill color.
fill_ellipses_aa
fn def fill_ellipses_aa(mut self, centers: List[FPoint], rx: Float64, ry: Float64, color: Color)DrawTarget’s batched ellipses. This backend emits a filled path per marker whichever entry point is used, so the batch is the loop and the output is unchanged by construction.
Args:
- self (
Self) - centers (
List[FPoint]): Sub-pixel centre of each marker, in draw order. - rx (
Float64): Horizontal radius shared by every marker, in pixels. - ry (
Float64): Vertical radius shared by every marker, in pixels. - color (
Color): Fill color shared by every marker.
Raises:
fn def fill_ellipses_aa(mut self, centers: List[FPoint], rx: Float64, ry: Float64, colors: List[Color])fill_ellipses_aa with a color per marker.
Args:
- self (
Self) - centers (
List[FPoint]): Sub-pixel centre of each marker, in draw order. - rx (
Float64): Horizontal radius shared by every marker, in pixels. - ry (
Float64): Vertical radius shared by every marker, in pixels. - colors (
List[Color]): One color per centre, same length ascenters.
Raises:
Error: If colors is not the same length as centers.
draw_circle_aa
fn def draw_circle_aa(mut self, cx: Float64, cy: Float64, radius: Float64, color: Color, width: Float64 = 1)A stroked circle.
Args:
- self (
Self) - cx (
Float64): Center x. - cy (
Float64): Center y. - radius (
Float64): Radius. - color (
Color): Stroke color. - width (
Float64): Stroke width.
fill_ellipse_aa
fn def fill_ellipse_aa(mut self, cx: Int, cy: Int, rx: Int, ry: Int, color: Color)A filled ellipse.
Args:
- self (
Self) - cx (
Int): Center x. - cy (
Int): Center y. - rx (
Int): Horizontal radius. - ry (
Int): Vertical radius. - color (
Color): Fill color.
fn def fill_ellipse_aa(mut self, cx: Float64, cy: Float64, rx: Float64, ry: Float64, color: Color)A filled ellipse at a geometric center.
Args:
- self (
Self) - cx (
Float64): Center x. - cy (
Float64): Center y. - rx (
Float64): Horizontal radius. - ry (
Float64): Vertical radius. - color (
Color): Fill color.
draw_ellipse_aa
fn def draw_ellipse_aa(mut self, cx: Int, cy: Int, rx: Int, ry: Int, color: Color)A stroked ellipse, one unit wide.
Args:
- self (
Self) - cx (
Int): Center x. - cy (
Int): Center y. - rx (
Int): Horizontal radius. - ry (
Int): Vertical radius. - color (
Color): Stroke color.
fn def draw_ellipse_aa(mut self, cx: Float64, cy: Float64, rx: Float64, ry: Float64, color: Color, width: Float64 = 1)A stroked ellipse.
Args:
- self (
Self) - cx (
Float64): Center x. - cy (
Float64): Center y. - rx (
Float64): Horizontal radius. - ry (
Float64): Vertical radius. - color (
Color): Stroke color. - width (
Float64): Stroke width.
fill_arc_aa
fn def fill_arc_aa(mut self, cx: Float64, cy: Float64, radius: Float64, start_angle: Float64, end_angle: Float64, color: Color)A filled pie wedge from start_angle to end_angle.
Args:
- self (
Self) - cx (
Float64): Center x. - cy (
Float64): Center y. - radius (
Float64): Radius. - start_angle (
Float64): Start angle, radians. - end_angle (
Float64): End angle, radians. - color (
Color): Fill color.
fill_arcs_aa
fn def fill_arcs_aa(mut self, centers: List[FPoint], radius: Float64, start_angle: Float64, end_angle: Float64, color: Color)DrawTarget’s batched wedges. This backend emits one element per wedge whichever entry point is used, so the batch is the loop and the output is unchanged by construction.
Args:
- self (
Self) - centers (
List[FPoint]): Sub-pixel centre of each wedge, in draw order. - radius (
Float64): Radius shared by every wedge, in pixels. - start_angle (
Float64): Start of the sweep, radians, shared. - end_angle (
Float64): End of the sweep, radians, shared. - color (
Color): Fill color shared by every wedge.
Raises:
fn def fill_arcs_aa(mut self, centers: List[FPoint], radius: Float64, start_angle: Float64, end_angle: Float64, colors: List[Color])fill_arcs_aa with a color per wedge.
Args:
- self (
Self) - centers (
List[FPoint]): Sub-pixel centre of each wedge, in draw order. - radius (
Float64): Radius shared by every wedge, in pixels. - start_angle (
Float64): Start of the sweep, radians, shared. - end_angle (
Float64): End of the sweep, radians, shared. - colors (
List[Color]): One color per centre, same length ascenters.
Raises:
Error: If colors is not the same length as centers.
fill_ring_sector_aa
fn def fill_ring_sector_aa(mut self, cx: Float64, cy: Float64, inner_radius: Float64, outer_radius: Float64, start_angle: Float64, end_angle: Float64, color: Color)A filled annular sector (donut segment).
Args:
- self (
Self) - cx (
Float64): Center x. - cy (
Float64): Center y. - inner_radius (
Float64): Inner radius. - outer_radius (
Float64): Outer radius. - start_angle (
Float64): Start angle, radians. - end_angle (
Float64): End angle, radians. - color (
Color): Fill color.
stroke_path_aa
fn def stroke_path_aa(mut self, path: Path, color: Color, width: Float64 = 1, dashes: List[Float64] = List(), dash_offset: Float64 = 0, cap: LineCap = LineCap.ROUND, join: LineJoin = LineJoin.ROUND, miter_limit: Float64 = 4)Stroke path.
Args:
- self (
Self) - path (
Path): Path to stroke. - color (
Color): Stroke color. - width (
Float64): Stroke width. - dashes (
List[Float64]): On/off lengths; empty for solid. - dash_offset (
Float64): Distance into the dash pattern to start. - cap (
LineCap): Line cap. - join (
LineJoin): Line join. - miter_limit (
Float64): Miter limit.
fill_path_aa
fn def fill_path_aa(mut self, path: Path, color: Color, fill_rule: FillRule = FillRule.EVEN_ODD)Fill path under fill_rule.
Args:
- self (
Self) - path (
Path): Path to fill. - color (
Color): Fill color. - fill_rule (
FillRule): EVEN_ODD (f*) or NONZERO (f).
fill_rect_gradient
fn def fill_rect_gradient(mut self, x: Int, y: Int, width: Int, height: Int, gradient: LinearGradient)A rectangle filled with an axial shading.
Args:
- self (
Self) - x (
Int): Left edge. - y (
Int): Top edge. - width (
Int): Width. - height (
Int): Height. - gradient (
LinearGradient): The linear gradient, in page coordinates.
fn def fill_rect_gradient(mut self, x: Float64, y: Float64, width: Float64, height: Float64, gradient: LinearGradient)A rectangle at a geometric position filled with an axial shading; a one-stop ramp fills solid with that color.
Args:
- self (
Self) - x (
Float64): Left edge. - y (
Float64): Top edge. - width (
Float64): Width. - height (
Float64): Height. - gradient (
LinearGradient): The linear gradient, in page coordinates.
fill_rect_radial_gradient
fn def fill_rect_radial_gradient(mut self, x: Int, y: Int, width: Int, height: Int, gradient: RadialGradient)A rectangle filled with a radial shading. Not on DrawTarget; call once a caller knows it holds a PdfCanvas.
Args:
- self (
Self) - x (
Int): Left edge. - y (
Int): Top edge. - width (
Int): Width. - height (
Int): Height. - gradient (
RadialGradient): The radial gradient, in page coordinates.
fill_path_gradient_aa
fn def fill_path_gradient_aa(mut self, path: Path, gradient: LinearGradient, fill_rule: FillRule = FillRule.EVEN_ODD)path filled with an axial shading, clipped under fill_rule. Not on DrawTarget.
Args:
- self (
Self) - path (
Path): Path to fill. - gradient (
LinearGradient): The linear gradient, in page coordinates. - fill_rule (
FillRule): Clip rule for the path.
fill_path_radial_gradient_aa
fn def fill_path_radial_gradient_aa(mut self, path: Path, gradient: RadialGradient, fill_rule: FillRule = FillRule.EVEN_ODD)path filled with a radial shading, clipped under fill_rule. Not on DrawTarget.
Args:
- self (
Self) - path (
Path): Path to fill. - gradient (
RadialGradient): The radial gradient, in page coordinates. - fill_rule (
FillRule): Clip rule for the path.
push_clip
fn def push_clip(mut self, x: Int, y: Int, width: Int, height: Int)Clip later drawing to a rectangle, intersected with any active clip, until pop_clip. Under a transform the rectangle is in the transformed space, as the other backends have it.
DrawTarget’s clip, and the reason this does not raise: an
affine map takes a rectangle to a parallelogram, whose four
corners are written directly rather than built as a Path
first. The Path was the only thing here that could raise,
and it never did for a rectangle.
Args:
- self (
Self) - x (
Int): Left edge. - y (
Int): Top edge. - width (
Int): Width. - height (
Int): Height.
pop_clip
fn def pop_clip(mut self)End the innermost clip. A no-op with none active.
Args:
- self (
Self)
push_clip_path
fn def push_clip_path(mut self, path: Path, fill_rule: FillRule = FillRule.EVEN_ODD)Clip later drawing to path under fill_rule, until pop_clip_path.
Args:
- self (
Self) - path (
Path): Clip outline. - fill_rule (
FillRule): Which regions of the outline count as inside.
Raises:
Error: path is malformed under the transform (a segment
before any move).
pop_clip_path
fn def pop_clip_path(mut self)End the innermost clip path; the same stack as pop_clip.
Args:
- self (
Self)
draw_text
fn def draw_text(mut self, x: Float64, y: Float64, text: String, color: Color, size: Float64, family: String = "Sans", slant: FontSlant = FontSlant.NORMAL, weight: FontWeight = FontWeight.NORMAL, rotation: Float64 = 0, align: TextAlign = TextAlign.LEFT)Draw text as real, selectable text in an embedded subset of the font, laid out exactly as the raster draw_text lays it out (shaping, kerning, line breaking, alignment, rotation about the anchor). The overload below, with a cache, is the DrawTarget form; this one is the same call without it.
What is embedded is the font file this machine resolved, subset
and reserialized, so a document with text in it depends on which
build of a family the machine had installed. Two machines whose
packaging of one family differs produce documents of different
lengths from the same calls – the glyphs are the same, which is
why raster output matches, and the embedded bytes are not.
SvgCanvas names the family and embeds nothing, so it does not
have this dependency. A byte-level gate on PDF output is
therefore a gate on the font installation as well; on one
machine with one font file the output is byte-identical run to
run. See canvas/vector/pdf_font.mojo.
Args:
- self (
Self) - x (
Float64): Anchor x – baseline left end for LEFT alignment. - y (
Float64): Anchor y – baseline. - text (
String): Text to draw, “\n”-separated lines. - color (
Color): Fill color. - size (
Float64): Font size in points. - family (
String): Font family name or generic alias. - slant (
FontSlant): Requested upright/italic/oblique style. - weight (
FontWeight): Requested normal/bold weight. - rotation (
Float64): Radians, rotating the block around the anchor. - align (
TextAlign): Horizontal alignment of each line.
Raises:
Error: No font could be resolved for family.
fn def draw_text(mut self, x: Float64, y: Float64, text: String, color: Color, size: Float64, family: String = "Sans", slant: FontSlant = FontSlant.NORMAL, weight: FontWeight = FontWeight.NORMAL, rotation: Float64 = 0, align: TextAlign = TextAlign.LEFT, *, mut cache: FontCache)The DrawTarget form of draw_text: the same call with a cache, which the document does not read. It keeps its own FontCache, because the font subset it embeds is built from the faces that cache resolved and has to outlive any one call; resolving through a caller’s cache instead would tie the document’s fonts to an object it does not own.
Args:
- self (
Self) - x (
Float64): Anchor x – baseline left end for LEFT alignment. - y (
Float64): Anchor y – baseline. - text (
String): Text to draw, “\n”-separated lines. - color (
Color): Fill color. - size (
Float64): Font size in points. - family (
String): Font family name or generic alias. - slant (
FontSlant): Requested upright/italic/oblique style. - weight (
FontWeight): Requested normal/bold weight. - rotation (
Float64): Radians, rotating the block around the anchor. - align (
TextAlign): Horizontal alignment of each line. - cache (
FontCache): Unused here; see above.
Raises:
Error: No font could be resolved for family.
draw_text_runs
fn def draw_text_runs(mut self, x: Float64, y: Float64, runs: List[TextRun], color: Color, family: String = "Sans", weight: FontWeight = FontWeight.NORMAL, rotation: Float64 = 0, align: TextAlign = TextAlign.LEFT, *, mut cache: FontCache)The DrawTarget form: draw_text once per run, each at the anchor canvas.text.render.text_run_anchors computes for it. One text object per run, in reading order, which is also the order a viewer selects them in; the runs’ spaces are in the runs. cache is unused, as in draw_text.
Args:
- self (
Self) - x (
Float64): Anchor x, sub-pixel. - y (
Float64): Anchor y, the label’s baseline. - runs (
List[TextRun]): The label’s runs, in reading order. - color (
Color): Fill color. - family (
String): Font family name or generic alias. - weight (
FontWeight): Normal or bold. - rotation (
Float64): Radians about the anchor. - align (
TextAlign): Horizontal alignment of the whole label. - cache (
FontCache): Unused here; seedraw_text.
Raises:
Error: No font could be resolved for family.
stroke_text
fn def stroke_text(mut self, x: Float64, y: Float64, text: String, color: Color, size: Float64, width: Float64 = 1, family: String = "Sans", slant: FontSlant = FontSlant.NORMAL, weight: FontWeight = FontWeight.NORMAL, rotation: Float64 = 0, align: TextAlign = TextAlign.LEFT, join: LineJoin = LineJoin.ROUND, miter_limit: Float64 = 4)Outline text rather than fill it (text render mode 1); see draw_text.
Args:
- self (
Self) - x (
Float64): Anchor x. - y (
Float64): Anchor y – baseline. - text (
String): Text to outline. - color (
Color): Stroke color. - size (
Float64): Font size in points. - width (
Float64): Stroke width. - family (
String): Font family name or generic alias. - slant (
FontSlant): Requested upright/italic/oblique style. - weight (
FontWeight): Requested normal/bold weight. - rotation (
Float64): Radians, rotating the block around the anchor. - align (
TextAlign): Horizontal alignment of each line. - join (
LineJoin): Line join. - miter_limit (
Float64): Miter limit.
Raises:
Error: No font could be resolved for family.
text_outline
fn def text_outline(mut self, x: Float64, y: Float64, text: String, size: Float64, family: String = "Sans", slant: FontSlant = FontSlant.NORMAL, weight: FontWeight = FontWeight.NORMAL, rotation: Float64 = 0, align: TextAlign = TextAlign.LEFT) -> Pathtext’s outline as a Path, through this document’s font cache: canvas.text.text_path for a caller that wants glyphs as shapes (to clip with, or to fill with a gradient) rather than as text.
Args:
- self (
Self) - x (
Float64): Anchor x. - y (
Float64): Anchor y – baseline. - text (
String): Text to outline. - size (
Float64): Font size in points. - family (
String): Font family name or generic alias. - slant (
FontSlant): Requested upright/italic/oblique style. - weight (
FontWeight): Requested normal/bold weight. - rotation (
Float64): Radians, rotating the block around the anchor. - align (
TextAlign): Horizontal alignment of each line.
Returns:
Path: The outline, filled correctly under FillRule.NONZERO.
Raises:
Error: No font could be resolved for family.
draw_image
fn def draw_image(mut self, image: Canvas, x: Float64, y: Float64, width: Float64 = 0, height: Float64 = 0)Draw image with its top-left at (x, y), scaled to width x height points (its own pixel size when 0), as an image XObject; a pixel that is not opaque gives the image a soft mask. DrawTarget’s image primitive, and the draw_canvas of this backend.
Args:
- self (
Self) - image (
Canvas): The pixels to draw. Unchanged. - x (
Float64): Left edge. - y (
Float64): Top edge. - width (
Float64): Drawn width in points, or 0 forimage.width. - height (
Float64): Drawn height in points, or 0 forimage.height.
begin_batch
fn def begin_batch(mut self)Nothing to defer: every element goes into the content stream in order as it is drawn. Here so a caller generic over DrawTarget can batch for the raster backend; see Canvas.begin_batch.
Args:
- self (
Self)
end_batch
fn def end_batch(mut self)The other half of begin_batch, also nothing.
Args:
- self (
Self)
begin_annotated_group
fn def begin_annotated_group(mut self, title: String)Open a marked-content sequence labeled title (/Span << /Alt (title) >> BDC), closed by end_annotated_group. Groups do not nest.
Args:
- self (
Self) - title (
String): Human-readable label; parentheses and backslashes are escaped here.
end_annotated_group
fn def end_annotated_group(mut self)Close the open marked-content sequence, if any.
Args:
- self (
Self)
content
fn def content(self) -> StringThe current page’s content stream operators as written so far, without the flip that opens the stream in the file: what a test reads to see what a call became.
Args:
- self (
Self)
Returns:
String
to_bytes
fn def to_bytes(mut self, compress: Bool = True) -> List[UInt8]The complete PDF file: catalog, page tree, the embedded fonts, the images, each page with its content stream, and the /Info dictionary when a title or author was set. Building it marks nothing on the document; the same call can be made again.
Args:
- self (
Self) - compress (
Bool): Flate-compress the streams (the default); False leaves the content readable and the fonts as they are.
Returns:
List[UInt8]: The file’s bytes.
Raises:
Error: Never in practice; the compressor’s signature.