Documentation
¶
Overview ¶
Package pdftest builds minimal synthetic PDF files for tests, in the spirit of net/http/httptest. The helpers reproduce structural patterns seen in real-world PDFs — Form XObjects, composite fonts, ToUnicode CMaps, segmented content streams (this file); Flate streams, PDF 1.5 cross-reference streams, object streams, and hybrid-reference files (xref.go); and standard-handler-encrypted files (crypt.go) — from entirely synthetic content.
Index ¶
- func Build(rootID int, objs ...string) []byte
- func BuildEncrypted(rootID int, spec EncryptSpec, objs ...string) []byte
- func BuildHybrid(rootID int, objs ...string) []byte
- func BuildObjStm(rootID int, packed []int, objs ...string) []byte
- func BuildXrefStream(rootID int, objs ...string) []byte
- func CIDFont(w string) string
- func Catalog(pagesID int) string
- func Flate(dict, content string) string
- func Helvetica() string
- func Hex2(codes ...int) string
- func Page(parentID, contentsID int, resources string) string
- func PageContentsArray(parentID int, resources string, contentsIDs ...int) string
- func Pages(kidIDs ...int) string
- func Stream(dict, content string) string
- func StreamWithLength(dict, content string, length int) string
- func ToUnicodeCMap(body string) string
- func Type0Font(descendantID, toUnicodeID int) string
- type EncryptSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build assembles a PDF from numbered objects: objs[i] becomes object i+1. rootID is the /Root (catalog) object number.
func BuildEncrypted ¶ added in v0.2.0
func BuildEncrypted(rootID int, spec EncryptSpec, objs ...string) []byte
BuildEncrypted assembles an encrypted classic-xref PDF. objs[i] becomes object i+1; stream bodies are encrypted with the per-object key. The /Encrypt dictionary is added as an extra object. Fixtures must not contain literal strings outside streams (the builder does not rewrite them). rootID is the catalog.
func BuildHybrid ¶ added in v0.2.0
BuildHybrid assembles a hybrid-reference file: a classic xref table plus a /XRefStm pointing at a supplementary xref stream that alone locates the last object. A reader ignoring /XRefStm loses that object.
func BuildObjStm ¶ added in v0.2.0
BuildObjStm assembles a PDF that packs the objects named in `packed` (1-based object numbers) into one object stream, with an xref stream referencing them by type-2 entries. Objects not listed in `packed` remain direct. Stream objects cannot be packed.
func BuildXrefStream ¶ added in v0.2.0
BuildXrefStream assembles a PDF whose cross-reference data is a PDF 1.5 xref stream (no classic table). objs[i] becomes object i+1; the xref stream is appended as the final object. rootID is the catalog.
func Flate ¶ added in v0.2.0
Flate renders a stream object whose body is zlib-compressed, emitting /Filter /FlateDecode and the correct /Length.
func Helvetica ¶
func Helvetica() string
Helvetica renders a standard-14 simple font object (WinAnsi).
func Hex2 ¶
Hex2 renders 2-byte character codes as a PDF hex string, e.g. Hex2(1, 2) → "<00010002>".
func PageContentsArray ¶
PageContentsArray renders a page whose /Contents is an array of streams forming one logical content stream (tokens may straddle boundaries).
func StreamWithLength ¶ added in v0.2.0
StreamWithLength renders a stream object with an explicit (possibly wrong) /Length, for exercising length recovery.
func ToUnicodeCMap ¶
ToUnicodeCMap renders a ToUnicode CMap stream object. Entries go inside the bfchar/bfrange sections, e.g. "<0001> <0048>".