API Reference

class pydyf.Object

Base class for PDF objects.

property data

Data contained in the object. Shall be defined in each subclass.

free

Indicate if an object is used ('n'), or has been deleted and therefore is free ('f').

generation

Version number of the object, non-negative.

property indirect

Indirect representation of an object.

number

Number of the object.

offset

Position in the PDF of the object.

property reference

Object identifier.

class pydyf.Dictionary(values=None)

PDF Dictionary object.

Inherits from Object and Python dict.

class pydyf.Stream(stream=None, extra=None, compress=False)

PDF Stream object.

Inherits from Object.

begin_text()

Begin a text object.

clip(even_odd=False)

Modify current clipping path by intersecting it with current path.

Use the nonzero winding number rule to determine which regions lie inside the clipping path by default.

Use the even-odd rule if even_odd set to True.

close()

Close current subpath.

Append a straight line segment from the current point to the starting point of the subpath.

color_space(space, stroke=False)

Set the nonstroking color space.

If stroke is set to True, set the stroking color space instead.

compress

Compress the stream data if set to True. Default is False.

curve_end_to(x1, y1, x3, y3)

Add cubic Bézier curve to current path

The curve shall extend to (x3, y3) using (x1, y1)` and (x3, y3) as the Bézier control points.

curve_start_to(x2, y2, x3, y3)

Add cubic Bézier curve to current path

The curve shall extend to (x3, y3) using the current point and (x2, y2) as the Bézier control points.

curve_to(x1, y1, x2, y2, x3, y3)

Add cubic Bézier curve to current path.

The curve shall extend from (x3, y3) using (x1, y1) and (x2, y2) as the Bézier control points.

property data

Data contained in the object. Shall be defined in each subclass.

draw_x_object(reference)

Draw object given by reference.

end()

End path without filling or stroking.

end_text()

End text object.

extra

Metadata containing at least the length of the Stream.

fill(even_odd=False)

Fill path using nonzero winding rule.

Use even-odd rule if even_odd is set to True.

fill_and_stroke(even_odd=False)

Fill and stroke path usign nonzero winding rule.

Use even-odd rule if even_odd is set to True.

fill_stroke_and_close(even_odd=False)

Fill, stroke and close path using nonzero winding rule.

Use even-odd rule if even_odd is set to True.

line_to(x, y)

Add line from current point to point (x, y).

move_to(x, y)

Begin new subpath by moving current point to (x, y).

pop_state()

Restore graphic state.

push_state()

Save graphic state.

rectangle(x, y, width, height)

Add rectangle to current path as complete subpath.

(x, y) is the lower-left corner and width and height the dimensions.

set_color_rgb(r, g, b, stroke=False)

Set RGB color for nonstroking operations.

Set RGB color for stroking operations instead if stroke is set to True.

set_color_special(name, stroke=False)

Set color for nonstroking operations.

Set color for stroking operation if stroke is set to True.

set_dash(dash_array, dash_phase)

Set dash line pattern.

Parameters
  • dash_array (iterable) – Dash pattern.

  • dash_phase (int) – Start of dash phase.

set_font_size(font, size)

Set font name and size.

set_line_cap(line_cap)

Set line cap style.

set_line_join(line_join)

Set line join style.

set_line_width(width)

Set line width.

set_miter_limit(miter_limit)

Set miter limit.

set_state(state_name)

Set specified parameters in graphic state.

Parameters

state_name – Name of the graphic state.

shading(name)

Paint shape and color shading using shading dictionary name.

show_text(text)

Show text.

stream

Python array of data composing stream.

stroke()

Stroke path.

stroke_and_close()

Stroke and close path.

text_matrix(a, b, c, d, e, f)

Set text matrix and text line matrix.

Parameters
  • a (int or float) – Top left number in the matrix.

  • b (int or float) – Top middle number in the matrix.

  • c (int or float) – Middle left number in the matrix.

  • d (int or float) – Middle middle number in the matrix.

  • e (int or float) – Bottom left number in the matrix.

  • f (int or float) – Bottom middle number in the matrix.

transform(a, b, c, d, e, f)

Modify current transformation matrix.

Parameters
  • a (int or float) – Top left number in the matrix.

  • b (int or float) – Top middle number in the matrix.

  • c (int or float) – Middle left number in the matrix.

  • d (int or float) – Middle middle number in the matrix.

  • e (int or float) – Bottom left number in the matrix.

  • f (int or float) – Bottom middle number in the matrix.

class pydyf.String(string='')

PDF String object.

Inherits from Object.

class pydyf.Array(array=None)

PDF Array object.

Inherits from Object and Python list.

class pydyf.PDF

PDF document.

add_object(object_)

Add object to the PDF.

add_page(page)

Add page to the PDF.

Parameters

page (Dictionary) – New page.

catalog

PDF Dictionary containing references to the other objects.

current_position

Current position in the PDF.

info

PDF Dictionary containing the PDF’s metadata.

objects

Python list containing the PDF’s objects.

pages

PDF Dictionary containing the PDF’s pages.

write(output=<_io.BufferedWriter name='<stdout>'>)

Write PDF to output.

Parameters

output (file object) – Output stream, sys.stdout by default.

write_body(output)

Write all non-free PDF objects to output.

write_cross_reference_table(output)

Write cross reference table to output.

write_header(output)

Write PDF header to output.

write_line(content, output)

Write line to output.

Parameters
write_object(object_, output)

Write object to output.

write_trailer(output)

Write trailer to output.

xref_position

Position of the cross reference table.