PDF Serializer Reference¶
- class pdfnaut.cos.serializer.PdfSerializer[source]¶
Bases:
objectA serializer that is able to produce a valid PDF document.
- Parameters:
eol (bytes, optional) – The end of line sequence to use when serializing. One of CR, LF, or CRLF. Defaults to CRLF.
- content¶
The buffer containing the serialized content to be written.
- generate_xref_section(rows: list[tuple[int, FreeXRefEntry | InUseXRefEntry | CompressedXRefEntry]]) list[PdfXRefSubsection][source]¶
Generates a cross-reference section from a list of
rows.Each row consists of a two-element tuple containing the object number of the XRef entry and the entry itself. The object numbers will determine the amount of subsections created and the entries within them.
The output is a list of XRef subsections that can be then serialized by either
write_standard_xref_section()orwrite_compressed_xref_section().
- write_compressed_xref_section(section: PdfXRefSection) int[source]¶
Appends a compressed XRef stream (see ISO 32000-2:2020 § 7.5.8 “Cross-Reference Streams”) from
section(to use as part of the extent) to the document.Returns the
startxrefoffset that should be written to the document.
- write_header(version: str, *, with_binary_marker: bool = True) None[source]¶
Appends the PDF file header to the document (see § 7.5.2, “File Header”).
- write_object(reference: PdfReference | tuple[int, int], contents: bool | int | float | bytes | PdfArray | PdfDictionary | PdfHexString | PdfName | PdfReference | PdfNull | PdfStream) int[source]¶
Appends an indirect object to the document.
- write_standard_xref_section(subsections: list[PdfXRefSubsection]) int[source]¶
Appends a standard XRef section (see ISO 32000-2:2020 § 7.5.4 “Cross-Reference Table”) to the document. Returns the
startxrefoffset that should be written to the document.
- write_trailer(trailer: PdfDictionary | None = None, startxref: int | None = None) None[source]¶
Appends a standard
trailerto the document (see ISO 32000-2:2020 § 7.5.5 “File Trailer”) alongside thestartxrefoffset.Both arguments are optional, indicating their presence in the appended output. If the XRef section written previously was an XRef stream, the trailer has already been written and should be
None.