Documentation ¶
Overview ¶
Package pdf provides a PDF writer type to generate PDF files. Create a new PDF writer by assigning pdf.NewPDF(paperSize) to a variable. Then call property setters and methods to render the document. Finally, call WriteFile(filename) to save the file, or use Bytes() to get the PDF document as an array of bytes.
Index ¶
- Variables
- type PDF
- func (p *PDF) AddPage() *PDF
- func (p *PDF) Bytes() []byte
- func (p *PDF) Clean() *PDF
- func (p *PDF) Color() color.RGBA
- func (p *PDF) Compression() bool
- func (p *PDF) CurrentPage() int
- func (p *PDF) DocAuthor() string
- func (p *PDF) DocCreator() string
- func (p *PDF) DocKeywords() string
- func (p *PDF) DocSubject() string
- func (p *PDF) DocTitle() string
- func (p *PDF) DrawBox(x, y, width, height float64, optFill ...bool) *PDF
- func (p *PDF) DrawCircle(x, y, radius float64, optFill ...bool) *PDF
- func (p *PDF) DrawEllipse(x, y, xRadius, yRadius float64, optFill ...bool) *PDF
- func (p *PDF) DrawImage(x, y, height float64, fileNameOrBytes interface{}, backColor ...string) *PDF
- func (p *PDF) DrawLine(x1, y1, x2, y2 float64) *PDF
- func (p *PDF) DrawText(s string) *PDF
- func (p *PDF) DrawTextAlignedToBox(x, y, width, height float64, align, text string) *PDF
- func (p *PDF) DrawTextAt(x, y float64, text string) *PDF
- func (p *PDF) DrawTextInBox(x, y, width, height float64, align, text string) *PDF
- func (p *PDF) DrawUnitGrid() *PDF
- func (*PDF) ErrorInfo(err error) (ret struct{ ... })
- func (p *PDF) Errors() []error
- func (p *PDF) FillBox(x, y, width, height float64) *PDF
- func (p *PDF) FillCircle(x, y, radius float64) *PDF
- func (p *PDF) FillEllipse(x, y, xRadius, yRadius float64) *PDF
- func (p *PDF) FontName() string
- func (p *PDF) FontSize() float64
- func (p *PDF) HorizontalScaling() uint16
- func (p *PDF) LineWidth() float64
- func (p *PDF) NextLine() *PDF
- func (p *PDF) PageCount() int
- func (p *PDF) PageHeight() float64
- func (p *PDF) PageWidth() float64
- func (p *PDF) PullError() error
- func (p *PDF) Reset() *PDF
- func (p *PDF) SaveFile(filename string) error
- func (p *PDF) SetColor(nameOrHTMLColor string) *PDF
- func (p *PDF) SetColorRGB(r, g, b byte) *PDF
- func (p *PDF) SetColumnWidths(widths ...float64) *PDF
- func (p *PDF) SetCompression(val bool) *PDF
- func (p *PDF) SetCurrentPage(pageNo int) *PDF
- func (p *PDF) SetDocAuthor(s string) *PDF
- func (p *PDF) SetDocCreator(s string) *PDF
- func (p *PDF) SetDocKeywords(s string) *PDF
- func (p *PDF) SetDocSubject(s string) *PDF
- func (p *PDF) SetDocTitle(s string) *PDF
- func (p *PDF) SetFont(name string, points float64) *PDF
- func (p *PDF) SetFontName(name string) *PDF
- func (p *PDF) SetFontSize(points float64) *PDF
- func (p *PDF) SetHorizontalScaling(percent uint16) *PDF
- func (p *PDF) SetLineWidth(points float64) *PDF
- func (p *PDF) SetUnits(units string) *PDF
- func (p *PDF) SetX(x float64) *PDF
- func (p *PDF) SetXY(x, y float64) *PDF
- func (p *PDF) SetY(y float64) *PDF
- func (p *PDF) TextWidth(s string) float64
- func (p *PDF) ToColor(nameOrHTMLColor string) (color.RGBA, error)
- func (p *PDF) ToPoints(numberAndUnit string) (float64, error)
- func (p *PDF) ToUnits(points float64) float64
- func (p *PDF) Units() string
- func (p *PDF) WrapTextLines(width float64, text string) (ret []string)
- func (p *PDF) X() float64
- func (p *PDF) Y() float64
Constants ¶
This section is empty.
Variables ¶
var PDFColorNames = map[string]color.RGBA{} // PDFColorNames /* 145 elements not displayed */
PDFColorNames maps web (X11) color names to values. From https://en.wikipedia.org/wiki/X11_color_names
Functions ¶
This section is empty.
Types ¶
type PDF ¶
type PDF struct { // contains filtered or unexported fields } // PDF
PDF is the main structure representing a PDF document.
func NewPDF ¶
NewPDF creates and initializes a new PDF object. Specify paperSize as: A, B, C series (e.g. "A4") or "LETTER", "LEGAL", "LEDGER", or "TABLOID" To specify a landscape orientation, add "-L" suffix e.g. "A4-L". You can also specify custom paper sizes using "width unit x height unit", for example "20 cm x 20 cm" or even "15cm x 10inch", etc.
func (*PDF) Bytes ¶
Bytes generates the PDF document from various page and auxiliary objects and returns it in an array of bytes, identical to the content of a PDF file. This method is where you'll find the core structure of a PDF document.
func (*PDF) Compression ¶
Compression returns the current compression mode. If it is true, all PDF content will be compressed when the PDF is generated. If false, most PDF content (excluding images) will be in plain text, which is useful for debugging or to study PDF commands.
func (*PDF) CurrentPage ¶
CurrentPage returns the current page's number, starting from 1.
func (*PDF) DocCreator ¶
DocCreator returns the optional 'document creator' metadata property.
func (*PDF) DocKeywords ¶
DocKeywords returns the optional 'document keywords' metadata property.
func (*PDF) DocSubject ¶
DocSubject returns the optional 'document subject' metadata property.
func (*PDF) DrawBox ¶
DrawBox draws a rectangle of the specified width and height, with the top-left corner starting at point (x, y). To fill the rectangle, pass true in the optional optFill.
func (*PDF) DrawCircle ¶
DrawCircle draws a circle of radius r centered on (x, y), by drawing 4 Bézier curves (PDF has no circle primitive) To fill the circle, pass true in the optional optFill.
func (*PDF) DrawEllipse ¶
DrawEllipse draws an ellipse centered on (x, y), with horizontal radius xRadius and vertical radius yRadius by drawing 4 Bézier curves (PDF has no ellipse primitive). To fill the ellipse, pass true in the optional optFill.
func (*PDF) DrawImage ¶
func (p *PDF) DrawImage(x, y, height float64, fileNameOrBytes interface{}, backColor ...string) *PDF
DrawImage draws a PNG image. x, y, height specify the position and height of the image. Width is scaled to match the image's aspect ratio. fileNameOrBytes is either a string specifying a file name, or a byte slice with PNG image data.
func (*PDF) DrawTextAlignedToBox ¶
DrawTextAlignedToBox draws 'text' within a rectangle specified by 'x', 'y', 'width' and 'height'. If 'align' is blank, the text is center-aligned both vertically and horizontally. Specify 'L' or 'R' to align the text left or right, and 'T' or 'B' to align the text to the top or bottom of the box.
func (*PDF) DrawTextAt ¶
DrawTextAt draws text at the specified point (x, y).
func (*PDF) DrawTextInBox ¶
DrawTextInBox draws word-wrapped text within a rectangle specified by 'x', 'y', 'width' and 'height'. If 'align' is blank, the text is center-aligned both vertically and horizontally. Specify 'L' or 'R' to align the text left or right, and 'T' or 'B' to align the text to the top or bottom of the box.
func (*PDF) DrawUnitGrid ¶
DrawUnitGrid draws a light-gray grid demarcated in the current measurement unit. The grid fills the entire page. It helps with item positioning.
func (*PDF) FillCircle ¶
FillCircle fills a circle of radius r centered on (x, y), by drawing 4 Bézier curves (PDF has no circle primitive)
func (*PDF) FillEllipse ¶
FillEllipse fills a Ellipse of radius r centered on (x, y), by drawing 4 Bézier curves (PDF has no ellipse primitive)
func (*PDF) HorizontalScaling ¶
HorizontalScaling returns the current horizontal scaling in percent.
func (*PDF) NextLine ¶
NextLine advances the text writing position to the next line. I.e. the Y increases by the height of the font and the X-coordinate is reset to zero.
func (*PDF) PageHeight ¶
PageHeight returns the height of the current page in selected units.
func (*PDF) SetColor ¶
SetColor sets the current color using a web/X11 color name (e.g. "HONEY DEW") or HTML color value such as "#191970" for midnight blue (#RRGGBB). The current color is used for subsequent text and line drawing and fills. If the name is unknown or invalid, sets color to black.
func (*PDF) SetColorRGB ¶
SetColorRGB sets the current color using red, green and blue values. The current color is used for subsequent text/line drawing and fills.
func (*PDF) SetColumnWidths ¶
SetColumnWidths creates column positions (tab stops) along the X-axis. To remove all column positions, call this method without any argument.
func (*PDF) SetCompression ¶
SetCompression sets the compression mode used to generate the PDF. If set to true, all PDF steams will be compressed when the PDF is generated. If false, most content (excluding images) will be in plain text, which is useful for debugging or to study PDF commands.
func (*PDF) SetCurrentPage ¶
SetCurrentPage opens the specified page. Page numbers start from 1.
func (*PDF) SetDocAuthor ¶
SetDocAuthor sets the optional 'document author' metadata property.
func (*PDF) SetDocCreator ¶
SetDocCreator sets the optional 'document creator' metadata property.
func (*PDF) SetDocKeywords ¶
SetDocKeywords sets the optional 'document keywords' metadata property.
func (*PDF) SetDocSubject ¶
SetDocSubject sets the optional 'document subject' metadata property.
func (*PDF) SetDocTitle ¶
SetDocTitle sets the optional 'document title' metadata property.
func (*PDF) SetFont ¶
SetFont changes the current font name and size in points. For the font name, use one of the standard font names, e.g. 'Helvetica'. This font will be used for subsequent text drawing.
func (*PDF) SetFontName ¶
SetFontName changes the current font, while using the same font size as the previous font. Use one of the standard font names, such as 'Helvetica'.
func (*PDF) SetFontSize ¶
SetFontSize changes the current font size in points, without changing the currently-selected font typeface.
func (*PDF) SetHorizontalScaling ¶
SetHorizontalScaling changes the horizontal scaling in percent. For example, 200 will stretch text to double its normal width.
func (*PDF) SetLineWidth ¶
SetLineWidth changes the line width in points.
func (*PDF) SetUnits ¶
SetUnits changes the current measurement units: mm cm " in inch inches tw twip twips pt point points (can be in any case)
func (*PDF) ToColor ¶
ToColor returns an RGBA color value from a web/X11 color name (e.g. "HONEY DEW") or HTML color value such as "#191970" If the name or code is unknown or invalid, returns zero value (black).
func (*PDF) ToPoints ¶
ToPoints converts a string composed of a number and unit to points. For example '1 cm' or '1cm' becomes 28.346 points. Recognised units: mm cm " in inch inches tw twip twips pt point points
func (*PDF) Units ¶
Units returns the currently selected measurement units. E.g.: mm cm " in inch inches tw twip twips pt point points
func (*PDF) WrapTextLines ¶
WrapTextLines splits a string into multiple lines so that the text fits in the specified width. The text is wrapped on word boundaries. Newline characters ("\r" and "\n") also cause text to be split. You can find out the number of lines needed to wrap some text by checking the length of the returned array.