paddlefish

Types

A PDF document.

pub opaque type Document

An image to be drawn on a page.

pub opaque type Image

Errors that can occur when creating an image.

pub type ImageError {
  UnsupportedImageFormat(filetype: String)
  UnknownImageFormat
}

Constructors

  • UnsupportedImageFormat(filetype: String)

    The image format is recognised but not supported.

  • UnknownImageFormat

    The image format is not recognised.

A single page in a PDF document.

pub opaque type Page

Dimensions of a page in points, where one point is 0.353mm.

pub type PageSize {
  PageSize(width: Float, height: Float)
}

Constructors

  • PageSize(width: Float, height: Float)

An open path made up of lines. This can be drawn as is, or closed to form a shape which can have a fill.

pub opaque type Path

A rectangle to be drawn on a page.

pub opaque type Rectangle

A shape made from one or more closed paths.

pub opaque type Shape

A piece of text to be drawn on a page.

pub opaque type Text

Values

pub fn add_image(page: Page, image: Image) -> Page

Add an image to the page.

pub fn add_page(document: Document, page: Page) -> Document

Append a page to the document.

Examples

new_document()
|> add_page(new_page())
pub fn add_path(page: Page, path: Path) -> Page

Add a path to the page.

pub fn add_rectangle(page: Page, rectangle: Rectangle) -> Page

Add a rectangle to the page.

pub fn add_shape(page: Page, shape: Shape) -> Page

Add a shape to the page.

pub fn add_text(page: Page, text: Text) -> Page

Add a text element to the page.

Examples

new_page()
|> add_text(text("Hello, world!", x: 72.0, y: 750.0))
pub fn author(document: Document, author: String) -> Document

Set the name of the person who created the document content.

pub fn compound_shape(paths: List(Path)) -> Shape

Create a compound shape from multiple paths.

The paths’ stroke colours and line widths are not inherited. Use shape_stroke_colour and shape_line_width to set them on the shape.

pub fn created_at(
  document: Document,
  time: timestamp.Timestamp,
) -> Document

Set the date and time when the document was created.

pub fn creator(document: Document, creator: String) -> Document

Set the name of the application that created the original content.

pub fn default_font(document: Document, font: String) -> Document

Set the default font for text in the document.

This font is used when text is added without specifying a font.

pub fn default_page_size(
  document: Document,
  size: PageSize,
) -> Document

Set the default page size for the document.

pub fn default_text_colour(
  document: Document,
  colour: colour.Colour,
) -> Document

Set the default text colour for the document.

This colour is used when text is added without specifying a colour.

pub fn default_text_size(
  document: Document,
  size: Float,
) -> Document

Set the default text size for the document in points.

This size is used when text is added without specifying a size.

pub fn font(text: Text, font: String) -> Text

Set the font for a text element.

The font must be the name of one of the 14 standard PDF fonts.

  • Courier,
  • Courier-Bold,
  • Courier-Oblique,
  • Courier-BoldOblique
  • Helvetica,
  • Helvetica-Bold,
  • Helvetica-Oblique,
  • Helvetica-BoldOblique
  • Times-Roman,
  • Times-Bold,
  • Times-Italic,
  • Times-BoldItalic
  • Symbol
  • ZapfDingbats
pub fn image(data: BitArray) -> Result(Image, ImageError)

Create an image from JPEG data.

Currently only JPEG images are supported. Returns an error if the data is not valid JPEG.

pub fn image_height(image: Image, height: Float) -> Image

Set the rendered height of an image.

If only height is set, the width scales proportionally to preserve the aspect ratio.

pub fn image_position(
  image: Image,
  x x: Float,
  y y: Float,
) -> Image

Set the position of an image on the page.

The position is from the bottom-left of the page.

pub fn image_width(image: Image, width: Float) -> Image

Set the rendered width of an image.

If only width is set, the height scales proportionally to preserve the aspect ratio.

pub fn keywords(document: Document, keywords: String) -> Document

Set keywords associated with the document, typically comma-separated.

pub fn landscape(size: PageSize) -> PageSize

Convert a page size to landscape orientation.

The larger dimension becomes the width.

pub fn line(path: Path, x x: Float, y y: Float) -> Path

Add a line to the path.

pub fn modified_at(
  document: Document,
  time: timestamp.Timestamp,
) -> Document

Set the date and time when the document was last modified.

pub fn new_document() -> Document

Create a new document.

pub fn new_page() -> Page

Create a new blank page.

pub fn page_size(page: Page, size: PageSize) -> Page

Set the size of a page.

pub fn path(x x: Float, y y: Float) -> Path

Create a new path starting at the given point.

pub fn path_line_width(path: Path, width: Float) -> Path

Set the line width for a path in points.

pub fn path_stroke_colour(
  path: Path,
  colour: colour.Colour,
) -> Path

Set the stroke colour for a path.

pub fn portrait(size: PageSize) -> PageSize

Convert a page size to portrait orientation.

The smaller dimension becomes the width.

pub fn producer(document: Document, producer: String) -> Document

Set the name of the application that produced the PDF.

pub fn rectangle(
  x x: Float,
  y y: Float,
  width width: Float,
  height height: Float,
) -> Rectangle

Create a new rectangle at the given position with the given dimensions.

The position is specified in points from the bottom-left corner of the page. The rectangle will be invisible until a fill or stroke colour is set.

pub fn rectangle_fill_colour(
  rectangle: Rectangle,
  colour: colour.Colour,
) -> Rectangle

Set the fill colour for a rectangle.

pub fn rectangle_line_width(
  rectangle: Rectangle,
  width: Float,
) -> Rectangle

Set the line width for a rectangle’s stroke in points.

pub fn rectangle_stroke_colour(
  rectangle: Rectangle,
  colour: colour.Colour,
) -> Rectangle

Set the stroke colour for a rectangle.

pub fn render(document: Document) -> BitArray

Render the document to a PDF file as a bit array.

The resulting bytes can be written directly to a file.

Examples

new_document()
|> title("My Document")
|> add_page(
  new_page()
  |> add_text(text("Hello!", x: 72.0, y: 750.0)),
)
|> render
pub fn shape(path: Path) -> Shape

Close a path to create a shape.

The path’s stroke colour and line width are not inherited. Use shape_stroke_colour and shape_line_width to set them on the shape.

pub fn shape_fill_colour(
  shape: Shape,
  colour: colour.Colour,
) -> Shape

Set the fill colour for a shape.

pub fn shape_line_width(shape: Shape, width: Float) -> Shape

Set the line width for a shape in points.

pub fn shape_stroke_colour(
  shape: Shape,
  colour: colour.Colour,
) -> Shape

Set the stroke colour for a shape.

pub const size_a3: PageSize

An A3 page size, as specified by ISO 216.

pub const size_a4: PageSize

An A4 page size, as specified by ISO 216.

pub const size_a5: PageSize

An A5 page size, as specified by ISO 216.

pub const size_usa_legal: PageSize

The “legal” size, according to the American paper sizes standard.

pub const size_usa_letter: PageSize

The “letter” size, according to the American paper sizes standard.

pub fn subject(document: Document, subject: String) -> Document

Set the subject of the document.

pub fn text(content: String, x x: Float, y y: Float) -> Text

Create a new text element at the given position.

The position is specified in points from the bottom-left corner of the page.

Examples

text("Hello, world!", x: 72.0, y: 750.0)
|> font("Times-Roman")
|> text_size(14.0)
pub fn text_colour(text: Text, colour: colour.Colour) -> Text

Set the colour for a text element.

pub fn text_size(text: Text, size: Float) -> Text

Set the size for a text element in points.

pub fn title(document: Document, title: String) -> Document

Set the title of the document.

Search Document