Skip to main content
Version: API v2 Preview

LineBuilder

Kind: class
Module/package: com.pdfdancer.client.rest
SDK: com.pdfdancer.client:pdfdancer-client-java 2.0.0

Fluent builder for adding a straight line to a PDF page.

Coordinate system: origin is at the bottom-left of the page, X to the right, Y upwards. All distances are in points (1 point = 1/72 inch). The line is added as a one-segment Path with STROKE painting.

Styling options:

color(Color) — stroke color (RGBA). Alpha < 255 yields semi-transparency. lineWidth(double) — stroke width in points. Width 0 produces a device-dependent hairline in PDF; use a small positive value (e.g., 0.25) for a thin but consistent line. dash(double...) and dashWithPhase(double, double...) — dash pattern and phase, in user space units.

Defaults: black stroke with a width of 1 point.

Thread-safety: instances are not thread-safe. Intended usage is single-threaded, typically as part of a fluent chain per line.

Declaration

public class com.pdfdancer.client.rest.LineBuilder

Members

constructor

public com.pdfdancer.client.rest.LineBuilder(com.pdfdancer.client.rest.PDFDancer, int)

Creates a builder bound to a specific page.

add

public boolean add()

Finalizes the line and adds it to the PDF as a single-segment Path.

Validation: both from(double, double) and to(double, double) must be specified or an IllegalArgumentException is thrown.

Effect: constructs a Path containing one Line segment with the configured stroke color, width, and optional dash settings, positioned on the specified page.

color

public com.pdfdancer.client.rest.LineBuilder color(com.pdfdancer.common.model.Color)

Sets the stroke color.

Uses RGBA; alpha < 255 yields semi-transparent strokes, depending on the renderer. If not set, a backend default is used (typically black).

dash

public com.pdfdancer.client.rest.LineBuilder dash(double...)

Sets a dash pattern for the stroke with zero phase (no offset).

The pattern is interpreted as alternating on/off lengths in user space units, e.g., (3, 2) = 3pt on, 2pt off, (10, 5, 2, 5) = dash-dot-like. Null or empty pattern means a solid line. Values should be non-negative and the pattern should not be all zeros.

dashWithPhase

public com.pdfdancer.client.rest.LineBuilder dashWithPhase(double, double...)

Sets a dash pattern with an explicit phase (offset) into the pattern.

Phase is the distance into the pattern at which stroking begins. For a pattern (10, 5) and phase=5, the first dash is shortened by 5.

from

public com.pdfdancer.client.rest.LineBuilder from(double, double)

Sets the start point of the line in page coordinates.

Units are points (1/72 inch). Origin at bottom-left.

lineWidth

public com.pdfdancer.client.rest.LineBuilder lineWidth(double)

Sets the stroke width in points.

A width of 0 produces a device-dependent hairline per PDF spec. For a thin but consistent line, use a small positive value like 0.25.

to

public com.pdfdancer.client.rest.LineBuilder to(double, double)

Sets the end point of the line in page coordinates.

Units are points (1/72 inch). Origin at bottom-left.

View source at 9c04036fe114