Helpers for converting between PDF coordinate systems.
PDF uses the bottom-left corner as its native origin. PaperForge can also expose a top-left origin, which is often easier for document layout.
Supported origins:
:bottom_left:top_left
Summary
Functions
Converts the Y coordinate of a rectangular element into PDF coordinates.
Converts two Y coordinates used by a line.
Converts a point Y coordinate into PDF coordinates.
Returns whether the provided origin is supported.
Validates and returns an origin.
Types
Functions
Converts the Y coordinate of a rectangular element into PDF coordinates.
This should be used for elements whose Y coordinate represents the top or bottom edge of a box, such as:
- rectangles;
- images;
- text boxes;
- other elements with a known height.
When the origin is :top_left, the element height is subtracted so
the box appears below the provided Y coordinate.
Examples
PaperForge.Coordinates.box_y(
842,
72,
100,
:top_left
)
#=> 670
PaperForge.Coordinates.box_y(
842,
72,
100,
:bottom_left
)
#=> 72
Converts two Y coordinates used by a line.
Example
PaperForge.Coordinates.line_y(
842,
72,
120,
:top_left
)
#=> {770, 722}
Converts a point Y coordinate into PDF coordinates.
For :bottom_left, the value is returned unchanged.
For :top_left, the value is measured from the top edge of the page.
Examples
PaperForge.Coordinates.point_y(
842,
72,
:top_left
)
#=> 770
PaperForge.Coordinates.point_y(
842,
72,
:bottom_left
)
#=> 72
Returns whether the provided origin is supported.
Validates and returns an origin.
Raises ArgumentError for unsupported values.