pdfme.parser

class pdfme.parser.PDFObject(id_, obj=None)

Bases: object

A class that represents a PDF object.

This object has a pdfme.parser.PDFRef id attribute representing the id of this object inside the PDF document, and acts as a dict, so the user can update any property of this PDF object like you would do with a dict.

Parameters
  • id (PDFRef) – The id of this object inside the PDF document.

  • obj (dict, optional) – the dict representing the PDF object.

class pdfme.parser.PDFRef(id_)

Bases: int

An int representing the id of a PDF object.

This is a regular int that has an additional property called ref with a representation of this object, to be referenced elsewhere in the PDF document.

property ref
Returns

bytes with a representation of this object, to be referenced elsewhere in the PDF document.

Return type

bytes

pdfme.parser.parse_obj(obj)

Function to convert a python object to a bytes object representing the corresponding PDF object.

Parameters

float, (obj (PDFObject, PDFRef, dict, list, tuple, set, bytes, bool, int,) – str): the object to be converted to a PDF object.

Returns

bytes representing the corresponding PDF object.

Return type

bytes

pdfme.parser.parse_dict(obj)

Function to convert a python dict to a bytes object representing the corresponding PDF Dictionary.

Parameters

obj (dict) – the dict to be converted to a PDF Dictionary.

Returns

bytes representing the corresponding PDF Dictionary.

Return type

bytes

pdfme.parser.parse_list(obj)

Function to convert a python iterable to a bytes object representing the corresponding PDF Array.

Parameters

obj (iterable) – the iterable to be converted to a PDF Array.

Returns

bytes representing the corresponding PDF Array.

Return type

bytes

pdfme.parser.parse_stream(obj)

Function to convert a dict representing a PDF Stream object to a bytes object.

A dict representing a PDF stream should have a '__stream__ key containing the stream bytes. You don’t have to include Length key in the dict, as it is calculated by us. The value of '__stream__' key must be of type bytes or a dict whose values are of type bytes. If you include a Filter key, a encoding is automatically done in the stream (see pdfme.encoders.encode_stream() function for supported encoders). If the contents of the stream are already encoded using the filter in Filter key, you can skip the encoding process by including the __skip_filter__ key.

Parameters

obj (dict) – the dict representing a PDF stream.

Returns

bytes representing the corresponding PDF Stream.

Return type

bytes