PaperForge.Writer (PaperForge v1.2.0)

Copy Markdown View Source

Serializes a PaperForge.Document into a valid PDF binary.

The writer is responsible for:

  • writing the PDF header;
  • serializing indirect objects;
  • calculating byte offsets;
  • generating the cross-reference table;
  • generating the trailer;
  • writing startxref and the EOF marker.

Summary

Functions

Converts a document into a complete PDF binary.

Writes a document incrementally and atomically to a filesystem path.

Functions

to_binary(document)

@spec to_binary(PaperForge.Document.t()) :: binary()

Converts a document into a complete PDF binary.

Example

binary =
  PaperForge.Writer.to_binary(document)

File.write!(
  "document.pdf",
  binary
)

write_to_file(document, path)

@spec write_to_file(PaperForge.Document.t(), Path.t()) ::
  :ok | {:error, File.posix() | term()}

Writes a document incrementally and atomically to a filesystem path.

PDF objects are serialized one at a time to a temporary file in the target directory. The completed file is renamed into place only after the xref and trailer have been written successfully.