pyhanko.pdf_utils.content module¶
- class pyhanko.pdf_utils.content.ResourceType(value)¶
Bases:
enum.EnumEnum listing resources that can be used as keys in a resource dictionary.
See ISO 32000-1, § 7.8.3 Table 34.
- EXT_G_STATE = '/ExtGState'¶
External graphics state specifications. See ISO 32000-1, § 8.4.5.
- COLOR_SPACE = '/ColorSpace'¶
Colour space definitions. See ISO 32000-1, § 8.6.
- PATTERN = '/Pattern'¶
Pattern definitions. See ISO 32000-1, § 8.7.
- SHADING = '/Shading'¶
Shading definitions. See ISO 32000-1, § 8.7.4.3.
- XOBJECT = '/XObject'¶
External object definitions (images and form XObjects). See ISO 32000-1, § 8.8.
- FONT = '/Font'¶
Font specifications. See ISO 32000-1, § 9.
- PROPERTIES = '/Properties'¶
Marked content properties. See ISO 32000-1, § 14.6.2.
- exception pyhanko.pdf_utils.content.ResourceManagementError¶
Bases:
ValueErrorUsed to signal problems with resource dictionaries.
- class pyhanko.pdf_utils.content.PdfResources¶
Bases:
objectRepresentation of a PDF resource dictionary.
This class implements
__getitem__()withResourceTypekeys for dynamic access to its attributes. To merge two instances ofPdfResourcesinto one another, the class overrides__iadd__(), so you can write.res1 += res2
Note: Merging two resource dictionaries with conflicting resource names will produce a
ResourceManagementError.Note: This class is currently only used for new resource dictionaries.
- as_pdf_object() pyhanko.pdf_utils.generic.DictionaryObject¶
Render this instance of
PdfResourcesto an actual resource dictionary.
- class pyhanko.pdf_utils.content.PdfContent(resources: Optional[pyhanko.pdf_utils.content.PdfResources] = None, box: Optional[pyhanko.pdf_utils.layout.BoxConstraints] = None, writer=None)¶
Bases:
objectAbstract representation of part of a PDF content stream.
Warning
Whether
PdfContentinstances can be reused or not is left up to the subclasses.- writer = None¶
The
__init__()method comes with an optionalwriterparameter that can be used to let subclasses register external resources with the writer by themselves.It can also be set after the fact by calling
set_writer().
- set_resource(category: pyhanko.pdf_utils.content.ResourceType, name: pyhanko.pdf_utils.generic.NameObject, value: pyhanko.pdf_utils.generic.PdfObject)¶
Set a value in the resource dictionary associated with this content fragment.
- Parameters
category – The resource category to which the resource belongs.
name – The resource’s (internal) name.
value – The resource’s value.
- import_resources(resources: pyhanko.pdf_utils.content.PdfResources)¶
Import resources from another resource dictionary.
- Parameters
resources – An instance of
PdfResources.- Raises
ResourceManagementError – Raised when there is a resource name conflict.
- property resources: pyhanko.pdf_utils.content.PdfResources¶
- Returns
The
PdfResourcesinstance associated with this content fragment.
- render() bytes¶
Compile the content to graphics operators.
- as_form_xobject() pyhanko.pdf_utils.generic.StreamObject¶
Render the object to a form XObject to be referenced by another content stream. See ISO 32000-1, § 8.8.
Note: Even if
writeris set, the resulting form XObject will not be registered. This is left up to the caller.- Returns
A
StreamObjectinstance representing the resulting form XObject.
- set_writer(writer)¶
Override the currently registered writer object.
- Parameters
writer – An instance of
BasePdfFileWriter.
- class pyhanko.pdf_utils.content.RawContent(data: bytes, resources: Optional[pyhanko.pdf_utils.content.PdfResources] = None, box: Optional[pyhanko.pdf_utils.layout.BoxConstraints] = None)¶
Bases:
pyhanko.pdf_utils.content.PdfContentRaw byte sequence to be used as PDF content.
- render() bytes¶
Compile the content to graphics operators.
- class pyhanko.pdf_utils.content.ImportedPdfPage(file_name, page_ix=0)¶
Bases:
pyhanko.pdf_utils.content.PdfContentImport a page from another PDF file (lazily)
- render() bytes¶
Compile the content to graphics operators.