Documentation ¶
Index ¶
- Variables
- func FloatToPoint(in float64) string
- func Serialize(item any) string
- type Annotation
- type Array
- type Dict
- type Face
- type Imagefile
- type Name
- type NameDest
- type Object
- type Objectnumber
- type Outline
- type PDF
- func (pw *PDF) AddPage(content *Object, page Objectnumber) *Page
- func (pw *PDF) Finish() error
- func (pw *PDF) LoadFace(filename string, idx int) (*Face, error)
- func (pw *PDF) LoadImageFile(filename string) (*Imagefile, error)
- func (pw *PDF) LoadImageFileWithBox(filename string, box string, pagenumber int) (*Imagefile, error)
- func (pw *PDF) NewFaceFromData(data []byte, idx int) (*Face, error)
- func (pw *PDF) NewObject() *Object
- func (pw *PDF) NewObjectWithNumber(objnum Objectnumber) *Object
- func (pw *PDF) NextObject() Objectnumber
- func (pw *PDF) Print(s string) error
- func (pw *PDF) Printf(format string, a ...any) error
- func (pw *PDF) Println(s string) error
- func (pw *PDF) Size() int64
- type Page
- type Pages
- type Separation
- type String
Constants ¶
This section is empty.
Variables ¶
var ( // Logger is initialized to write to io.Discard and the default log level is math.MaxInt, so it should never write anything. Logger *slog.Logger )
Functions ¶
func FloatToPoint ¶
FloatToPoint returns a string suitable as a PDF size value.
func Serialize ¶
Serialize returns a string representation of the item as it may appear in the PDF file. Arrays are written with square brackets, Dicts with double angle brackets, Strings (PDF strings) with parentheses or single angle brackets, depending on the contents and all other objects with their respective String() method.
Types ¶
type Annotation ¶
type Annotation struct { Subtype Name Action string Dictionary Dict Rect [4]float64 // x1, y1, x2, y2 }
An Annotation is a PDF element that is additional to the text, such as a hyperlink or a note.
type Dict ¶
Dict is a dictionary where each key begins with a slash (/). Each value can be a string, an array or another dictionary.
type Face ¶
type Face struct { FaceID int HarfbuzzFont *harfbuzz.Font UnitsPerEM int32 Cmap fonts.Cmap Filename string PostscriptName string // contains filtered or unexported fields }
Face represents a font structure with no specific size. To get the dimensions of a font, you need to create a Font object with a given size.
func (*Face) Codepoint ¶
Codepoint tries to find the code point for r. If none found, 0 is returned.
func (*Face) Codepoints ¶
Codepoints returns the internal code points for the runes.
func (*Face) InternalName ¶
InternalName returns a PDF usable name such as /F1
func (*Face) RegisterChar ¶
RegisterChar marks the codepoint as used on the page. For font subsetting.
func (*Face) RegisterChars ¶
RegisterChars marks the codepoints as used on the page. For font subsetting.
type Imagefile ¶
type Imagefile struct { Format string NumberOfPages int PageSizes map[int]map[string]map[string]float64 Filename string ScaleX float64 ScaleY float64 W int H int Box string PageNumber int // contains filtered or unexported fields }
Imagefile represents a physical image file. Images to be place in the PDF must be derived from the image.
func (*Imagefile) GetPDFBoxDimensions ¶
GetPDFBoxDimensions returns the dimensions for the given box. Box must be one of "/MediaBox", "/CropBox", "/BleedBox", "/TrimBox", "/ArtBox".
func (*Imagefile) InternalName ¶
InternalName returns a PDF usable name such as /F1
type Name ¶
type Name string
Name represents a PDF name such as Adobe Green. The String() method prepends a / (slash) to the name if not present.
type NameDest ¶
type NameDest struct { PageObjectnumber Objectnumber Name String X float64 Y float64 // contains filtered or unexported fields }
NameDest represents a named PDF destination. The origin of X and Y are in the top left corner and expressed in DTP points.
type Object ¶
type Object struct { ObjectNumber Objectnumber Data *bytes.Buffer Dictionary Dict Array []any Raw bool // Data holds everything between object number and endobj ForceStream bool // contains filtered or unexported fields }
Object has information about a specific PDF object
func (*Object) SetCompression ¶
SetCompression turns on stream compression if compresslevel > 0
type Objectnumber ¶
type Objectnumber int
Objectnumber represents a PDF object number
func (Objectnumber) Ref ¶
func (o Objectnumber) Ref() string
Ref returns a reference to the object number
func (Objectnumber) String ¶
func (o Objectnumber) String() string
String returns a reference to the object number
type Outline ¶
type Outline struct { Children []*Outline Title string Open bool Dest string // contains filtered or unexported fields }
Outline represents PDF bookmarks. To create outlines, you need to assign previously created Dest items to the outline. When Open is true, the PDF viewer shows the child outlines.
type PDF ¶
type PDF struct { Catalog Dict InfoDict Dict DefaultOffsetX float64 DefaultOffsetY float64 DefaultPageWidth float64 DefaultPageHeight float64 Colorspaces []*Separation NameDestinations map[String]*NameDest Outlines []*Outline Major uint Minor uint NoPages int // set when PDF is finished // contains filtered or unexported fields }
PDF is the central point of writing a PDF file.
func NewPDFWriter ¶
NewPDFWriter creates a PDF file for writing to file
func (*PDF) AddPage ¶
func (pw *PDF) AddPage(content *Object, page Objectnumber) *Page
AddPage adds a page to the PDF file. The content stream must a stream object (i.e. an object with data). Pass 0 for the page object number if you don't pre-allocate an object number for the page.
func (*PDF) LoadFace ¶
LoadFace loads a font from the disc. The index specifies the sub font to be loaded.
func (*PDF) LoadImageFile ¶
LoadImageFile loads an image from the disc. For PDF files it defaults to page 1 and the /MediaBox.
func (*PDF) LoadImageFileWithBox ¶
func (pw *PDF) LoadImageFileWithBox(filename string, box string, pagenumber int) (*Imagefile, error)
LoadImageFileWithBox loads an image from the disc with the given box and page number.
func (*PDF) NewFaceFromData ¶
NewFaceFromData returns a Face object which is a representation of a font file. The first parameter (id) should be the file name of the font, but can be any string. This is to prevent duplicate font loading.
func (*PDF) NewObject ¶
NewObject create a new PDF object and reserves an object number for it. The object is not written to the PDF until Save() is called.
func (*PDF) NewObjectWithNumber ¶
func (pw *PDF) NewObjectWithNumber(objnum Objectnumber) *Object
NewObjectWithNumber create a new PDF object and reserves an object number for it. The object is not written to the PDF until Save() is called.
func (*PDF) NextObject ¶
func (pw *PDF) NextObject() Objectnumber
NextObject returns the next free object number
type Page ¶
type Page struct { Objnum Objectnumber // The "/Page" object Annotations []Annotation Faces []*Face Images []*Imagefile Width float64 Height float64 OffsetX float64 OffsetY float64 Dict Dict // Additional dictionary entries such as "/Trimbox" // contains filtered or unexported fields }
Page contains information about a single page.
type Pages ¶
type Pages struct { Pages []*Page // contains filtered or unexported fields }
Pages is the parent page structure
type Separation ¶
type Separation struct { Obj Objectnumber ID string Name string ICCProfile Objectnumber C float64 M float64 Y float64 K float64 }
Separation represents a spot color