Documentation
¶
Overview ¶
Code generated by gen-metrics -- DO NOT EDIT.
Package pdf provides methods for reading, creating, and updating PDF files.
Index ¶
- Variables
- func ArrayPaths(arrayPath Path, array Array) iter.Seq[Path]
- func DictPaths(dictPath Path, dict Dict) iter.Seq[Path]
- func EncodeHexString(by []byte) string
- func EncodeName(n Name) string
- func EncodeString(s string) string
- func FontMetrics(font string, fontSize float64) (habove, hbelow float64)
- func MeasureText(s, font string, size float64) (width, habove, hbelow float64)
- type Array
- type Box
- type Cell
- type Circle
- type Cross
- type Dict
- type Importer
- type Line
- type Matrix
- type Name
- type Object
- type PDF
- func (pdf *PDF) AddPage(mediaBox Rectangle) (err error)
- func (pdf *PDF) AddPageContent(pagenum int, content string) (err error)
- func (pdf *PDF) AddPageResource(pagenum int, resType, resName Name, resource Object) (err error)
- func (pdf *PDF) Append(p Path, value Object) (err error)
- func (p *PDF) CreateObject(obj Object) (ref Reference)
- func (p *PDF) Fetch(r Reference) (obj Object, err error)
- func (pdf *PDF) Get(p Path) (object Object)
- func (pdf *PDF) GetArray(p Path) (v Array, err error)
- func (pdf *PDF) GetBool(p Path) (v bool, err error)
- func (pdf *PDF) GetDict(p Path) (v Dict, err error)
- func (pdf *PDF) GetInt(p Path) (v int, err error)
- func (pdf *PDF) GetName(p Path) (v Name, err error)
- func (pdf *PDF) GetReal(p Path) (v float64, err error)
- func (pdf *PDF) GetRectangle(p Path) (v Rectangle, err error)
- func (pdf *PDF) GetReference(p Path) (v Reference, err error)
- func (pdf *PDF) GetStream(p Path) (v Stream, err error)
- func (pdf *PDF) GetString(p Path) (v string, err error)
- func (pdf *PDF) ImportPDF(otherPDF *PDF) (err error)
- func (pdf *PDF) NewImporter(otherPDF *PDF) (imp *Importer, err error)
- func (pdf *PDF) NumPages() (count int, err error)
- func (pdf *PDF) PagePath(pagenum int) (p Path, err error)
- func (pdf *PDF) Set(p Path, value Object) (err error)
- func (p *PDF) UpdateObject(ref Reference, obj Object)
- func (p *PDF) Write() (err error)
- type Path
- type Point
- type Reader
- type Rectangle
- type Reference
- type Stream
- type Table
- type Text
Constants ¶
This section is empty.
Variables ¶
var ErrDoesntFit = errors.New("text does not fit in bounding box")
ErrDoesntFit is the error returned by Draw if the text doesn't fit in its Rectangle. The text was still drawn, either overflowing or clipped to the Rectangle depending on the Clip setting.
var ErrIllegalChar = errors.New("text contains invalid character")
ErrIllegalChar is the error returned by Draw if the text contains a character that cannot be rendered. The text was still drawn but the offending character(s) were omitted.
var ErrNoSuchPage = errors.New("no such page number")
ErrNoSuchPage indicates a reference to a page number that does not exist in the PDF.
var USLetterPortrait = Rectangle{0, 0, 612, 792}
USLetterPortrait is the most common mediaBox parameter to AddPage.
Functions ¶
func ArrayPaths ¶
ArrayPaths returns an iterator of paths to the elements of an array.
func EncodeHexString ¶
func EncodeName ¶
func EncodeString ¶
func FontMetrics ¶
FontMetrics returns the maximum height above the baseline and below the baseline at the specified font size. A 0,0 return indicates an unknown font.
func MeasureText ¶
MeasureText returns the metrics of the specified string in the specified font at the specified size: specifically, the width, the height above the baseline, and the height below the baseline. The string must not contain control characters, and must be in UTF-8 encoding. Characters that are not recognized (i.e., not in Windows-1252 encoding) are ignored. The function returns zeros if the font is not known.
Types ¶
type Box ¶
type Box struct {
// Rectangle gives the size and location of the box. Required.
Rectangle Rectangle
// Page gives the page number to draw on. Default is 1.
Page int
// Fill gives the fill color for the box, as an array of three or four
// bytes (R, G, B, and maybe A). Default is no fill.
Fill []byte
// Stroke gives the stroke color for the box, as an array of three or
// four bytes (R, G, B, and maybe A). Default is no stroke.
Stroke []byte
// StrokeWidth gives the stroke width for the box (meaningful only if
// Stroke is specified). Default is 1pt.
StrokeWidth float64
}
Box is a structure containing all of the parameters for drawing a box. To draw a box, create a Box structure and call its Draw method.
type Cell ¶
type Cell struct {
// Row is the row number of the cell. For cells that span rows,
// it is the topmost row that the cell spans. Rows are numbered from 0
// starting at the top of the table.
Row int
// Col is the column number of the cell. For cells that span columns,
// it is the leftmost column that the cell spans. Cells are numbered
// from 0 starting at the left of the table.
Col int
// RowSpan is the number of rows the cell spans (default 1).
RowSpan int
// ColSpan is the number of columns the cell spans (default 1).
ColSpan int
// Fill is the background color of the cell, if any.
Fill []byte
// Text is the text to place in the cell. Note that the Page,
// Rectangle, MinFontSize, and Wrap will be overridden by Table.Draw.
Text *Text
}
Cell is a structure defining the parameters for a single cell in a Table.
type Circle ¶
type Circle struct {
// Center gives the center point of the circle. Required.
Center Point
// Radius gives the radius of the circle. Required.
Radius float64
// Page gives the page number to draw on. Default is 1.
Page int
// Fill gives the fill color for the circle, as an array of three or
// four bytes (R, G, B, and maybe A). Default is no fill.
Fill []byte
// Stroke gives the stroke color for the circle, as an array of three or
// four bytes (R, G, B, and maybe A). Default is no stroke.
Stroke []byte
}
Circle is a structure containing all of the parameters for drawing a circle. To draw a circle, create a Circle structure and call its Draw method.
type Cross ¶
type Cross struct {
// Rectangle gives the size and location of the cross. Required.
Rectangle Rectangle
// Page gives the page number to draw on. Default is 1.
Page int
// LineWidth gives the line width. Default is 1 point.
LineWidth float64
// Stroke gives the stroke color for the lines, as an array of three or
// four bytes (R, G, B, and maybe A). Default is black.
Stroke []byte
}
Cross is a structure containing all of the parameters for drawing a cross (i.e., two perpendicular lines crossing a rectangular area). To draw a cross, create a Cross structure and call its Draw method.
type Importer ¶ added in v2.1.2
type Importer struct {
// contains filtered or unexported fields
}
func (*Importer) ImportPage ¶ added in v2.1.2
type Line ¶
type Line struct {
// P1 and P2 give the endpoints of the line. Required.
P1, P2 Point
// Page gives the page number to draw on. Default is 1.
Page int
// Stroke gives the stroke color for the line, as an array of three or
// four bytes (R, G, B, and maybe A). Default is solid black.
Stroke []byte
// Width gives the line width. Default is 1pt.
Width float64
}
Line is a structure containing all of the parameters for drawing a line. To draw a line, create a Line structure and call its Draw method.
type Matrix ¶
type Matrix struct{ A, B, C, D, E, F float64 }
A Matrix specifies a coordinate transformation matrix. Following PDF standard, the matrix
┌a b 0┐ │c d 0│ └e f 1┘
is represented as the array [a b c d e f].
func (Matrix) PreMultiply ¶
type Object ¶
type Object any
An Object is an object as defined by the PDF specification. While an Object is defined as "any", it will in fact be one of the following:
- nil (a null object)
- bool
- int
- float64
- string
- []byte (a hex string)
- Name
- Array
- Dict
- Stream
- Reference
type PDF ¶
A PDF is a reference to a PDF file.
func New ¶
func New(wh io.WriteSeeker) (pdf *PDF)
New creates a new PDF file. After objects are added to it, Write must be called on it.
func (*PDF) AddPageContent ¶
AddPageContent adds content to the specified page.
func (*PDF) AddPageResource ¶
AddPageResource adds a resource to a page.
func (*PDF) Append ¶
Append appends the specified value to the Array at the specified path. It marks the nearest ancestor object as dirty.
func (*PDF) CreateObject ¶
CreateObject creates a new object with the specified content, and returns a reference to it. The new content will be written if Write is called.
func (*PDF) Get ¶
Get returns the object at the specified Path. If the file structure isn't consistent with the path, the object returned is an error.
func (*PDF) GetReal ¶
GetReal is like Get but asserts that the result is a float64 (or an int, which is converted to float64).
func (*PDF) GetRectangle ¶
GetRectangle is like Get but asserts that the result is a Rectangle (i.e., an Array of four numbers).
func (*PDF) GetReference ¶
GetReference is like Get but asserts that the result is a Reference.
func (*PDF) GetString ¶
GetString is like Get but asserts that the result is a string (or a []byte, which is converted to string).
func (*PDF) ImportPDF ¶
ImportPDF imports all of the pages from the specified other PDF into the receiver PDF. The imported page content is overlaid onto the existing content of each corresponding page; new pages are added as needed.
func (*PDF) NewImporter ¶ added in v2.1.2
NewImporter creates a new Importer object, which can be used to import pages from another PDF into this one by calling its ImportPage method.
func (*PDF) PagePath ¶
PagePath returns the path to the page dictionary for the specified page number (starting from 1).
func (*PDF) Set ¶
Set sets the value at the specified path to the specified value. It marks the nearest ancestor object as dirty.
func (*PDF) UpdateObject ¶
UpdateObject registers new content for the object with the specified reference. The new content will be written if Write is called.
type Path ¶
type Path string
A Path represents a path to an object in a PDF, navigating from the PDF's trailer dictionary. It looks like a file system path, with "/" representing the trailer dictionary and subsequent components of the path being either Dict keys, Stream.Dict keys, or Array indices. So, for example, /Root/Pages/Kids/0/Content might be the path to the content stream of the first page of the PDF. Indirect object references are not represented in the path.
type Rectangle ¶
type Rectangle struct{ LLX, LLY, URX, URY float64 }
A Rectangle specifies a rectangle, in terms of its lower left and upper right coordinates, in points.
func RectangleRT ¶
RectangleRT returns a Rectangle specified with X, Y, Right, and Top.
func RectangleWH ¶
RectangleWH returns a Rectangle specified with X, Y, Width, and Height.
type Stream ¶
A Stream is a Dict followed by a block of arbitrary data. Note that when retrieved from the pdfstruct library, stream data has been decompressed and decoded.
func (*Stream) Decompress ¶
Decompress removes any compression and/or encoding from the stream data. Some encoding methods need to know the size (in bytes) of a "row" in the data for decoding, so that is a parameter.
type Table ¶
type Table struct {
// Page is the page number onto which to draw the table. Default 1.
Page int
// Rectangle is the page area into which to draw the table. The table
// is vertically aligned to the top of the rectangle and horizontally
// centered in it. After a call to Draw, Rectangle reflects the actual
// rectangle used.
Rectangle Rectangle
// TableBorderWidth is the width of the border drawn around the table.
TableBorderWidth float64
// TableBorderStroke is the color of the border drawn around the table.
TableBorderStroke []byte
// CellPadX is the padding on the left and right side of each cell.
CellPadX float64
// CellPadY is the padding on the top and bottom of each cell.
CellPadY float64
// CellBorderWidth is the width of the border drawn around each cell of
// the table.
CellBorderWidth float64
// CellBorderStroke is the color of the border drawn around each cell of
// the table.
CellBorderStroke []byte
// Align specifies the alignment of the table within the Rectangle. It
// contains up to two letters: "t", "m", or "b" to specify top, middle,
// or bottom vertical alignment, and "l", "c", or "r" to specify left,
// center, or right horizontal alignment. The default is "tc".
Align string
// contains filtered or unexported fields
}
Table is a structure containing the parameters for drawing a table. To draw a table, create a Table structure, call its Cell method repeatedly for each cell in it, and then call its Draw method.
func (*Table) Cell ¶
Cell adds a cell to the table. Cells may be added in any order. Note that cells with rowSpan != 1 are ignored in row height calculations and cells with colSpan != 1 are ignored in column width calculations.
func (*Table) ColumnWidths ¶
ColumnWidths returns the column widths. These can be passed to SetColumnWidths of a different table to align layouts. Call this before calling Draw.
func (*Table) Draw ¶
Draw draws a table. The table Rectangle is left encapsulating the space used by the table. If the table doesn't fit on the page, nothing is drawn and ErrDoesntFit is returned.
func (*Table) InsertRow ¶ added in v2.1.0
InsertRow inserts an empty row at the specified row number. In other words, any existing Cells with a row number >= the specified number have their row number incremented.
func (*Table) SetColumnWidths ¶
SetColumnWidths sets the column widths. Call this before calling Cell.
type Text ¶
type Text struct {
// String is the string to be drawn. Required. The string should be
// encoded in UTF-8 as normal; however, only characters in the Windows
// 1252 character set (a superset of ISO 8859-1) will actually be
// rendered.
String string
// Rectangle is the page area into which to draw the string. Required.
Rectangle Rectangle
// Page is the page number onto which to draw the string. Default 1.
Page int
// Baseline, if nonzero, is the Y-coordinate of the baseline for the
// first line of text. This overrides any alignment specified in Align
// or VAlign.
Baseline float64
// Font is the name of font in which the string should be drawn. It
// must be either "Courier", "Helvetica", or "Times-Roman". Default is
// "Helvetica".
Font string
// FontSize is the starting and maximum size of the font with which the
// string should be drawn. Default 12.0.
FontSize float64
// MinFontSize is the minimum size of the font with which the string
// should be drawn. Defaults to FontSize. If less than FontSize, text
// will be shrunk to fit within the Rectangle, but no smaller than
// MinFontSize.
MinFontSize float64
// LineHeight is the distance between lines in a multi-line text block
// (either String contains newlines or Wrap is enabled and String gets
// wrapped). Specified as a multiple of the font size, default 1.0.
LineHeight float64
// Color is the color in which the text should be drawn, as a slice of
// three byte values, one each for red, green, and blue. Default is
// black (i.e., 0, 0, 0).
Color []byte
// Align specifies the alignment of the text within the rectangle. It
// contains up to two letters, one specifying the vertical alignment and
// the other specifying the horizontal alignment. The order of the two
// does not matter.
//
// The vertical alignment characters are T, M, F, B, t, m, f, and b.
// These stand for top, middle, first-middle, and bottom respectively.
// The lowercase versions align based on the actual text (i.e., what
// ascenders and descenders are actually used); the uppercase versions
// align based on the font bounding box (i.e., assuming full ascenders
// and descenders even if the text being rendered doesn't use them).
// M/m differs from F/f only for multi-line text: M/m centers the whole
// block and F/f centers the first line. If no vertical alignment
// character is specified, the default is F. Note that an nonzero value
// of Baseline overrides any vertical alignment character.
//
// The horizontal alignment characters are l, c, and r, for left,
// center, and right. If no horizontal alignment character is
// specified, the default is l.
Align string
// HAlign indicates how the text should be aligned horizontally.
// Allowed values are "left" (the default), "center", and "right".
// Deprecated: use Align instead.
HAlign string
// VAlign indicates how the text hsould be aligned vertically. Allowed
// values are "top", "center", "bottom", and "baseline" (the default).
// "baseline" means to arrange for the baseline of the first line of
// text to be at Baseline, shifting that up as needed to make the text
// fit in Rectangle. Deprecated: use Align instead.
VAlign string
// Wrap indicates that text should be wrapped to fit in the Rectangle.
Wrap bool
// Clip indicates that text should be clipped to the Rectangle. If
// false, text that doesn't fit in the Rectangle is allowed to extend
// past its boundaries.
Clip bool
// contains filtered or unexported fields
}
Text is a structure containing all of the parameters for drawing a text string. To draw a text string, create a Text structure and call its Draw method.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pdfform reads and writes the fillable form fields in a PDF.
|
Package pdfform reads and writes the fillable form fields in a PDF. |
|
gen-metrics generates metrics.go from the files in github:Hopding/standard-fonts, which it assumes is checked out at ../standard-fonts.
|
gen-metrics generates metrics.go from the files in github:Hopding/standard-fonts, which it assumes is checked out at ../standard-fonts. |
|
pdfinspect dumps one or more objects from a PDF file.
|
pdfinspect dumps one or more objects from a PDF file. |