API Reference

class pydyf.Object

Base class for PDF objects.

property compressible

Whether the object can be included in an object stream.

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)

Bases: Object, dict

PDF Dictionary object.

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

Bases: Object

PDF Stream object.

begin_marked_content(tag, property_list=None)

Begin marked-content sequence.

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)

color_space is deprecated, use set_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_marked_content()

End marked-content sequence.

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.

inline_image(width, height, color_space, bpc, raw_data)

Add an inline image.

Parameters:
  • width (int) – The width of the image.

  • height (int) – The height of the image.

  • colorspace (str) – The color space of the image, f.e. RGB, Gray.

  • bpc (int) – The bits per component. 1 for BW, 8 for grayscale.

  • raw_data – The raw pixel data.

line_to(x, y)

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

move_text_to(x, y)

Move text to next line at (x, y) distance from previous line.

move_to(x, y)

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

paint_shading(name)

Paint shape and color shading using shading dictionary name.

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_space(space, stroke=False)

Set the nonstroking color space.

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

set_color_special(name, stroke=False, *operands)

Set special color for nonstroking operations.

Set special 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_matrix(a, b, c, d, e, f)

Set 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.

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.

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

Set current text and text line 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.

set_text_rendering(mode)

Set text rendering mode.

set_text_rise(height)

Set text rise.

shading(name)

shading is deprecated, use paint_shading instead.

show_text(text)

Show text strings with individual glyph positioning.

show_text_string(text)

Show single text string.

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)

text_matrix is deprecated, use set_text_matrix instead.

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

transform is deprecated, use set_matrix instead.

class pydyf.String(string='')

Bases: Object

PDF String object.

class pydyf.Array(array=None)

Bases: Object, list

PDF Array object.

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, version=b'1.7', identifier=False, compress=False)

Write PDF to output.

Parameters:
  • output (binary file object) – Output stream.

  • version (bytes) – PDF version.

  • identifier (bytes or bool) – PDF file identifier. Default is False to include no identifier, can be set to True to generate an automatic identifier.

  • compress (bool) – whether the PDF uses a compressed object stream.

write_line(content, output)

Write line to output.

Parameters:
  • content (bytes) – Content to write.

  • output (binary file object) – Output stream.

xref_position

Position of the cross reference table.