pdfbdf

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Overview

Package pdfbdf writes BDF documents as PDF files, for what a PDF is there for: printing, filing, sending to those who have no viewer of BDF.

The instructions of the objects (docs/spec.md §7) become the operators of content streams, in the same order: paths, transforms, clips, lines and dashes, alpha and blend modes (the graphics state parameters ca, CA and BM), linear and radial gradients (axial and radial shadings; conic ones as a mesh of triangles), image patterns (tiling patterns), groups (transparency group forms) and soft masks (the SMask of the state a group is drawn with). Text stays text: the fonts of the document are embedded with the glyphs in use (the fonts of the system, for fonts referred to by name), as CID fonts with the characters of their codes, so that the text of the file is searched and copied; a font that may not be embedded, or that a PDF cannot hold, is drawn as the outlines of its glyphs under the text they stand for. JPEG images are stored as they are, other bitmaps as their pixels, SVG images as pictures of them. Links are link annotations, and the metadata that of the file.

The pages of fixed and flow views are the pages of the file. A view of scroll strips is one long page, and a sheet one page of its tiles; they are written when the document has no pages. The layers that pages share (the masters of slides) are written once.

A PDF has no shadows: the shadow of a shape is a picture of it (the shape drawn by raster/imagebdf at 300 dpi and blurred as that renderer blurs it), put under the shape, which stays vectors.

What a PDF has no counterpart for is left out with a warning: FILTER, the composite operations of Canvas that are not blend modes (drawn as source-over), CLEAR_RECT in a group, AVIF images. Text is laid out as the image renderer lays it out (raster/imagebdf): not shaped, and with the fonts of the machine for the text of fonts referred to by name.

Options.Tagged writes a tagged PDF: the structure that the MARK instructions of the document tell (headings, paragraphs, lists, tables, figures with their alternative texts, links, the language of the text) as the structure tree of the file, with the content of the pages marked by what it is of, and what is no content of the document (page headers and footers, masters, backgrounds, shadows) as artifacts. Options.PDFA makes the file a PDF/A file of part 2 or 3, of the level b, u or a: with an output intent of sRGB, what PDF/A does not have written another way, and, at level a, tagged. The files are checked with veraPDF.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPages = errors.New("pdfbdf: the document has no pages")

ErrNoPages is returned for a document without anything to write.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Views are the ids of the views to write, in the order of the
	// document. nil writes the views of pages (fixed and flow); when the
	// document has none, all its views.
	Views []string
	// SkipRoles are the roles of the layers that are left out (bdf.RoleMaster,
	// bdf.RoleBackground …): for printing on paper that has them already.
	SkipRoles []string
	// FontFS holds fonts searched before FontDirs, for the text of fonts
	// referred to by name and for characters an embedded font lacks.
	FontFS fs.FS
	// FontDirs are searched for fonts before the system font directories.
	FontDirs []string
	// NoSystemFonts restricts font lookup to FontFS and FontDirs.
	NoSystemFonts bool
	// IgnoreFSType embeds fonts of the system whose OS/2 fsType forbids
	// embedding, and leaves glyphs out of fonts whose fsType forbids
	// subsetting. Without it the text of such fonts is drawn as outlines,
	// or the fonts are embedded whole. Set it only when you hold the rights.
	IgnoreFSType bool
	// NoCompression writes the streams of the file as they are (for
	// reading them; the file is several times larger).
	NoCompression bool
	// CompressionLevel is the level of the deflate of the streams, 1 to 9
	// (0: 6).
	CompressionLevel int
	// Tagged writes a tagged PDF: the structure of the document (its
	// headings, paragraphs, lists, tables and figures with their
	// alternative texts, as the MARKs of its objects tell them) as the
	// structure tree of the file, with the content of the pages marked as
	// that of its elements, and the rest as artifacts. Screen readers and
	// the tools that take the text of a file out go by it.
	Tagged bool
	// Pages selects the pages written, by their zero-based number among
	// the pages the file has without it, in that order; numbers past
	// them are left out. nil writes all of them. For a printer that
	// takes no page-ranges.
	Pages []int
	// PDFA makes the file a PDF/A file, of the part and the level named:
	// "2b" (it shows the same in any reader), "2u" (and its text is
	// Unicode), "2a" (and it is tagged: Tagged is set), or "3b", "3u" and
	// "3a", the same of part 3. "" writes a PDF that names no standard.
	PDFA string
	// Sign signs the file (PAdES): nil writes a file without a signature.
	// The file is then made in memory before it is written.
	Sign *Signature
}

Options controls the writing of a file.

type Result

type Result struct {
	Pages int
	// Fonts is the number of fonts embedded.
	Fonts    int
	Warnings []string
}

Result tells what was written.

func Write

func Write(w io.Writer, doc *bdf.Document, opts *Options) (res *Result, err error)

Write writes a document as a PDF file.

type Signature added in v0.2.0

type Signature struct {
	// Key signs, and Chain is its certificate followed by those of the
	// chain to the root.
	Key   crypto.Signer
	Chain []*x509.Certificate
	// Field is the name of a picture of the document whose box the
	// signature shows on: that of a signature field of a form (form,
	// tag.InputSignature), which a reader shows as the field of the
	// signature. "" makes a signature that shows on no page.
	Field string
	// Name, Reason, Location and Contact are what the signature
	// dictionary says of the signer.
	Name, Reason, Location, Contact string
	// Time is the time the signature says (/M; the clock when zero).
	Time time.Time
	// TSA is the URL of a time-stamp authority (RFC 3161), and Client the
	// client that asks it (nil: http.DefaultClient).
	TSA    string
	Client *http.Client
	// Certify makes the signature the certification of the file (DocMDP),
	// with the changes that it permits after it: 1 none, 2 filling in
	// forms and signing, 3 those and annotations. 0 is an approval
	// signature.
	Certify int
}

Signature signs a file as PAdES (ETSI EN 319 142-1) does: a signature field whose signature is a CMS signature of the bytes of the file around it (/SubFilter /ETSI.CAdES.detached), the baseline B-B, or B-T with a time-stamp of a TSA. Readers of PDF files (Acrobat …) check it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL