Documentation ¶
Overview ¶
Package creator is used for quickly generating pages and content with a simple interface. It is built on top of the model package to provide access to the most common operations such as creating text and image reports and manipulating existing pages.
Index ¶
- Variables
- type Block
- func (blk *Block) AddAnnotation(annotation *model.PdfAnnotation)
- func (blk *Block) Angle() float64
- func (blk *Block) Draw(d Drawable) error
- func (blk *Block) DrawWithContext(d Drawable, ctx DrawContext) error
- func (blk *Block) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (blk *Block) GetMargins() (float64, float64, float64, float64)
- func (blk *Block) Height() float64
- func (blk *Block) RotatedSize() (float64, float64)
- func (blk *Block) Scale(sx, sy float64)
- func (blk *Block) ScaleToHeight(h float64)
- func (blk *Block) ScaleToWidth(w float64)
- func (blk *Block) SetAngle(angleDeg float64)
- func (blk *Block) SetMargins(left, right, top, bottom float64)
- func (blk *Block) SetPos(x, y float64)
- func (blk *Block) Width() float64
- type CellBorderSide
- type CellBorderStyle
- type CellHorizontalAlignment
- type CellVerticalAlignment
- type Chapter
- func (chap *Chapter) Add(d Drawable) error
- func (chap *Chapter) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (chap *Chapter) GetHeading() *Paragraph
- func (chap *Chapter) GetMargins() (float64, float64, float64, float64)
- func (chap *Chapter) NewSubchapter(title string) *Chapter
- func (chap *Chapter) SetIncludeInTOC(includeInTOC bool)
- func (chap *Chapter) SetMargins(left, right, top, bottom float64)
- func (chap *Chapter) SetShowNumbering(show bool)
- type Color
- type Creator
- func (c *Creator) AddPage(page *model.PdfPage) error
- func (c *Creator) Context() DrawContext
- func (c *Creator) CreateFrontPage(genFrontPageFunc func(args FrontpageFunctionArgs))
- func (c *Creator) CreateTableOfContents(genTOCFunc func(toc *TOC) error)
- func (c *Creator) Draw(d Drawable) error
- func (c *Creator) DrawFooter(drawFooterFunc func(footer *Block, args FooterFunctionArgs))
- func (c *Creator) DrawHeader(drawHeaderFunc func(header *Block, args HeaderFunctionArgs))
- func (c *Creator) EnableFontSubsetting(font *model.PdfFont)
- func (c *Creator) Finalize() error
- func (c *Creator) GetOptimizer() model.Optimizer
- func (c *Creator) Height() float64
- func (c *Creator) MoveDown(dy float64)
- func (c *Creator) MoveRight(dx float64)
- func (c *Creator) MoveTo(x, y float64)
- func (c *Creator) MoveX(x float64)
- func (c *Creator) MoveY(y float64)
- func (c *Creator) NewChapter(title string) *Chapter
- func (c *Creator) NewCurve(x1, y1, cx, cy, x2, y2 float64) *Curve
- func (c *Creator) NewDivision() *Division
- func (c *Creator) NewEllipse(xc, yc, width, height float64) *Ellipse
- func (c *Creator) NewFilledCurve() *FilledCurve
- func (c *Creator) NewImage(img *model.Image) (*Image, error)
- func (c *Creator) NewImageFromData(data []byte) (*Image, error)
- func (c *Creator) NewImageFromFile(path string) (*Image, error)
- func (c *Creator) NewImageFromGoImage(goimg goimage.Image) (*Image, error)
- func (c *Creator) NewInvoice() *Invoice
- func (c *Creator) NewLine(x1, y1, x2, y2 float64) *Line
- func (c *Creator) NewList() *List
- func (c *Creator) NewPage() *model.PdfPage
- func (c *Creator) NewPageBreak() *PageBreak
- func (c *Creator) NewParagraph(text string) *Paragraph
- func (c *Creator) NewRectangle(x, y, width, height float64) *Rectangle
- func (c *Creator) NewStyledParagraph() *StyledParagraph
- func (c *Creator) NewStyledTOCLine(number, title, page TextChunk, level uint, style TextStyle) *TOCLine
- func (c *Creator) NewTOC(title string) *TOC
- func (c *Creator) NewTOCLine(number, title, page string, level uint) *TOCLine
- func (c *Creator) NewTable(cols int) *Table
- func (c *Creator) NewTextStyle() TextStyle
- func (c *Creator) RotateDeg(angleDeg int64) error
- func (c *Creator) SetForms(form *model.PdfAcroForm) error
- func (c *Creator) SetOptimizer(optimizer model.Optimizer)
- func (c *Creator) SetOutlineTree(outlineTree *model.PdfOutlineTreeNode)
- func (c *Creator) SetPageLabels(pageLabels core.PdfObject)
- func (c *Creator) SetPageMargins(left, right, top, bottom float64)
- func (c *Creator) SetPageSize(size PageSize)
- func (c *Creator) SetPdfWriterAccessFunc(pdfWriterAccessFunc func(writer *model.PdfWriter) error)
- func (c *Creator) SetTOC(toc *TOC)
- func (c *Creator) TOC() *TOC
- func (c *Creator) Width() float64
- func (c *Creator) Write(ws io.Writer) error
- func (c *Creator) WriteToFile(outputPath string) error
- type Curve
- type Division
- type DrawContext
- type Drawable
- type Ellipse
- type FilledCurve
- type FooterFunctionArgs
- type FrontpageFunctionArgs
- type HeaderFunctionArgs
- type HorizontalAlignment
- type Image
- func (img *Image) ConvertToBinary() error
- func (img *Image) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (img *Image) GetHorizontalAlignment() HorizontalAlignment
- func (img *Image) GetMargins() (float64, float64, float64, float64)
- func (img *Image) Height() float64
- func (img *Image) Scale(xFactor, yFactor float64)
- func (img *Image) ScaleToHeight(h float64)
- func (img *Image) ScaleToWidth(w float64)
- func (img *Image) SetAngle(angle float64)
- func (img *Image) SetEncoder(encoder core.StreamEncoder)
- func (img *Image) SetHeight(h float64)
- func (img *Image) SetHorizontalAlignment(alignment HorizontalAlignment)
- func (img *Image) SetMargins(left, right, top, bottom float64)
- func (img *Image) SetOpacity(opacity float64)
- func (img *Image) SetPos(x, y float64)
- func (img *Image) SetWidth(w float64)
- func (img *Image) Width() float64
- type Invoice
- func (i *Invoice) AddInfo(description, value string) (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) AddLine(values ...string) []*InvoiceCell
- func (i *Invoice) AddSection(title, content string)
- func (i *Invoice) AddTotalLine(desc, value string) (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) AddressHeadingStyle() TextStyle
- func (i *Invoice) AddressStyle() TextStyle
- func (i *Invoice) AppendColumn(description string) *InvoiceCell
- func (i *Invoice) BuyerAddress() *InvoiceAddress
- func (i *Invoice) Columns() []*InvoiceCell
- func (i *Invoice) Date() (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) DueDate() (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (i *Invoice) InfoLines() [][2]*InvoiceCell
- func (i *Invoice) InsertColumn(index uint, description string) *InvoiceCell
- func (i *Invoice) Lines() [][]*InvoiceCell
- func (i *Invoice) Logo() *Image
- func (i *Invoice) NewCell(value string) *InvoiceCell
- func (i *Invoice) NewCellProps() InvoiceCellProps
- func (i *Invoice) NewColumn(description string) *InvoiceCell
- func (i *Invoice) NoteHeadingStyle() TextStyle
- func (i *Invoice) NoteStyle() TextStyle
- func (i *Invoice) Notes() (string, string)
- func (i *Invoice) Number() (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) Sections() [][2]string
- func (i *Invoice) SellerAddress() *InvoiceAddress
- func (i *Invoice) SetAddressHeadingStyle(style TextStyle)
- func (i *Invoice) SetAddressStyle(style TextStyle)
- func (i *Invoice) SetBuyerAddress(address *InvoiceAddress)
- func (i *Invoice) SetColumns(cols []*InvoiceCell)
- func (i *Invoice) SetDate(date string) (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) SetDueDate(dueDate string) (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) SetLogo(logo *Image)
- func (i *Invoice) SetNoteHeadingStyle(style TextStyle)
- func (i *Invoice) SetNoteStyle(style TextStyle)
- func (i *Invoice) SetNotes(title, content string)
- func (i *Invoice) SetNumber(number string) (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) SetSellerAddress(address *InvoiceAddress)
- func (i *Invoice) SetSubtotal(value string)
- func (i *Invoice) SetTerms(title, content string)
- func (i *Invoice) SetTitle(title string)
- func (i *Invoice) SetTitleStyle(style TextStyle)
- func (i *Invoice) SetTotal(value string)
- func (i *Invoice) Subtotal() (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) Terms() (string, string)
- func (i *Invoice) Title() string
- func (i *Invoice) TitleStyle() TextStyle
- func (i *Invoice) Total() (*InvoiceCell, *InvoiceCell)
- func (i *Invoice) TotalLines() [][2]*InvoiceCell
- type InvoiceAddress
- type InvoiceCell
- type InvoiceCellProps
- type Line
- type List
- func (l *List) Add(item VectorDrawable) (*TextChunk, error)
- func (l *List) AddTextItem(text string) (*StyledParagraph, *TextChunk, error)
- func (l *List) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (l *List) Height() float64
- func (l *List) Indent() float64
- func (l *List) Margins() (float64, float64, float64, float64)
- func (l *List) Marker() *TextChunk
- func (l *List) SetIndent(indent float64)
- func (l *List) SetMargins(left, right, top, bottom float64)
- func (l *List) Width() float64
- type PageBreak
- type PageSize
- type Paragraph
- func (p *Paragraph) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (p *Paragraph) GetMargins() (float64, float64, float64, float64)
- func (p *Paragraph) Height() float64
- func (p *Paragraph) SetAngle(angle float64)
- func (p *Paragraph) SetColor(col Color)
- func (p *Paragraph) SetEnableWrap(enableWrap bool)
- func (p *Paragraph) SetFont(font *model.PdfFont)
- func (p *Paragraph) SetFontSize(fontSize float64)
- func (p *Paragraph) SetLineHeight(lineheight float64)
- func (p *Paragraph) SetMargins(left, right, top, bottom float64)
- func (p *Paragraph) SetPos(x, y float64)
- func (p *Paragraph) SetText(text string)
- func (p *Paragraph) SetTextAlignment(align TextAlignment)
- func (p *Paragraph) SetWidth(width float64)
- func (p *Paragraph) Text() string
- func (p *Paragraph) Width() float64
- type Rectangle
- type StyledParagraph
- func (p *StyledParagraph) AddExternalLink(text, url string) *TextChunk
- func (p *StyledParagraph) AddInternalLink(text string, page int64, x, y, zoom float64) *TextChunk
- func (p *StyledParagraph) Append(text string) *TextChunk
- func (p *StyledParagraph) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (p *StyledParagraph) GetMargins() (float64, float64, float64, float64)
- func (p *StyledParagraph) Height() float64
- func (p *StyledParagraph) Insert(index uint, text string) *TextChunk
- func (p *StyledParagraph) Reset()
- func (p *StyledParagraph) SetAngle(angle float64)
- func (p *StyledParagraph) SetEnableWrap(enableWrap bool)
- func (p *StyledParagraph) SetLineHeight(lineheight float64)
- func (p *StyledParagraph) SetMargins(left, right, top, bottom float64)
- func (p *StyledParagraph) SetPos(x, y float64)
- func (p *StyledParagraph) SetText(text string) *TextChunk
- func (p *StyledParagraph) SetTextAlignment(align TextAlignment)
- func (p *StyledParagraph) SetWidth(width float64)
- func (p *StyledParagraph) Width() float64
- type TOC
- func (t *TOC) Add(number, title, page string, level uint) *TOCLine
- func (t *TOC) AddLine(line *TOCLine) *TOCLine
- func (t *TOC) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (t *TOC) Heading() *StyledParagraph
- func (t *TOC) Lines() []*TOCLine
- func (t *TOC) SetHeading(text string, style TextStyle)
- func (t *TOC) SetLineLevelOffset(levelOffset float64)
- func (t *TOC) SetLineMargins(left, right, top, bottom float64)
- func (t *TOC) SetLineNumberStyle(style TextStyle)
- func (t *TOC) SetLinePageStyle(style TextStyle)
- func (t *TOC) SetLineSeparator(separator string)
- func (t *TOC) SetLineSeparatorStyle(style TextStyle)
- func (t *TOC) SetLineStyle(style TextStyle)
- func (t *TOC) SetLineTitleStyle(style TextStyle)
- func (t *TOC) SetShowLinks(showLinks bool)
- type TOCLine
- func (tl *TOCLine) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (tl *TOCLine) GetMargins() (float64, float64, float64, float64)
- func (tl *TOCLine) Level() uint
- func (tl *TOCLine) LevelOffset() float64
- func (tl *TOCLine) SetLevel(level uint)
- func (tl *TOCLine) SetLevelOffset(levelOffset float64)
- func (tl *TOCLine) SetLink(page int64, x, y float64)
- func (tl *TOCLine) SetMargins(left, right, top, bottom float64)
- func (tl *TOCLine) SetStyle(style TextStyle)
- type Table
- func (table *Table) AddSubtable(row, col int, subtable *Table)
- func (table *Table) Cols() int
- func (table *Table) CurCol() int
- func (table *Table) CurRow() int
- func (table *Table) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
- func (table *Table) GetMargins() (float64, float64, float64, float64)
- func (table *Table) GetRowHeight(row int) (float64, error)
- func (table *Table) Height() float64
- func (table *Table) MultiColCell(colspan int) *TableCell
- func (table *Table) NewCell() *TableCell
- func (table *Table) Rows() int
- func (table *Table) SetColumnWidths(widths ...float64) error
- func (table *Table) SetHeaderRows(startRow, endRow int) error
- func (table *Table) SetMargins(left, right, top, bottom float64)
- func (table *Table) SetPos(x, y float64)
- func (table *Table) SetRowHeight(row int, h float64) error
- func (table *Table) SkipCells(num int)
- func (table *Table) SkipOver(rows, cols int)
- func (table *Table) SkipRows(num int)
- func (table *Table) Width() float64
- type TableCell
- func (cell *TableCell) SetBackgroundColor(col Color)
- func (cell *TableCell) SetBorder(side CellBorderSide, style CellBorderStyle, width float64)
- func (cell *TableCell) SetBorderColor(col Color)
- func (cell *TableCell) SetBorderLineStyle(style draw.LineStyle)
- func (cell *TableCell) SetContent(vd VectorDrawable) error
- func (cell *TableCell) SetHorizontalAlignment(halign CellHorizontalAlignment)
- func (cell *TableCell) SetIndent(indent float64)
- func (cell *TableCell) SetVerticalAlignment(valign CellVerticalAlignment)
- func (cell *TableCell) Width(ctx DrawContext) float64
- type TextAlignment
- type TextChunk
- type TextRenderingMode
- type TextStyle
- type VectorDrawable
Constants ¶
This section is empty.
Variables ¶
var ( ColorBlack = ColorRGBFromArithmetic(0, 0, 0) ColorWhite = ColorRGBFromArithmetic(1, 1, 1) ColorRed = ColorRGBFromArithmetic(1, 0, 0) ColorGreen = ColorRGBFromArithmetic(0, 1, 0) ColorBlue = ColorRGBFromArithmetic(0, 0, 1) ColorYellow = ColorRGBFromArithmetic(1, 1, 0) )
Commonly used colors.
var ( PageSizeA3 = PageSize{297 * PPMM, 420 * PPMM} PageSizeA4 = PageSize{210 * PPMM, 297 * PPMM} PageSizeA5 = PageSize{148 * PPMM, 210 * PPMM} PageSizeLetter = PageSize{8.5 * PPI, 11 * PPI} PageSizeLegal = PageSize{8.5 * PPI, 14 * PPI} )
Commonly used page sizes
var PPI float64 = 72 // Points per inch. (Default resolution).
PPI specifies the default PDF resolution in points/inch.
var PPMM = float64(72 * 1.0 / 25.4)
PPMM specifies the default PDF resolution in points/mm. Points per mm. (Default resolution).
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block contains a portion of PDF Page contents. It has a width and a position and can be placed anywhere on a Page. It can even contain a whole Page, and is used in the creator where each Drawable object can output one or more blocks, each representing content for separate pages (typically needed when Page breaks occur).
func NewBlockFromPage ¶
NewBlockFromPage creates a Block from a PDF Page. Useful for loading template pages as blocks from a PDF document and additional content with the creator.
func (*Block) AddAnnotation ¶
func (blk *Block) AddAnnotation(annotation *model.PdfAnnotation)
AddAnnotation adds an annotation to the current block. The annotation will be added to the page the block will be rendered on.
func (*Block) Draw ¶
Draw draws the drawable d on the block. Note that the drawable must not wrap, i.e. only return one block. Otherwise an error is returned.
func (*Block) DrawWithContext ¶
func (blk *Block) DrawWithContext(d Drawable, ctx DrawContext) error
DrawWithContext draws the Block using the specified drawing context.
func (*Block) GeneratePageBlocks ¶
func (blk *Block) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks draws the block contents on a template Page block. Implements the Drawable interface.
func (*Block) GetMargins ¶
GetMargins returns the Block's margins: left, right, top, bottom.
func (*Block) RotatedSize ¶
RotatedSize returns the width and height of the rotated block.
func (*Block) ScaleToHeight ¶
ScaleToHeight scales the Block to a specified height, maintaining the same aspect ratio.
func (*Block) ScaleToWidth ¶
ScaleToWidth scales the Block to a specified width, maintaining the same aspect ratio.
func (*Block) SetMargins ¶
SetMargins sets the Block's left, right, top, bottom, margins.
type CellBorderSide ¶
type CellBorderSide int
CellBorderSide defines the table cell's border side.
const ( // CellBorderSideLeft adds border on the left side of the table. CellBorderSideLeft CellBorderSide = iota // CellBorderSideRight adds a border on the right side of the table. CellBorderSideRight // CellBorderSideTop adds a border on the top side of the table. CellBorderSideTop // CellBorderSideBottom adds a border on the bottom side of the table. CellBorderSideBottom // CellBorderSideAll adds borders on all sides of the table. CellBorderSideAll )
type CellBorderStyle ¶
type CellBorderStyle int
CellBorderStyle defines the table cell's border style.
const ( CellBorderStyleNone CellBorderStyle = iota // no border CellBorderStyleSingle CellBorderStyleDouble )
Currently supported table styles are: None (no border) and boxed (line along each side).
type CellHorizontalAlignment ¶
type CellHorizontalAlignment int
CellHorizontalAlignment defines the table cell's horizontal alignment.
const ( // CellHorizontalAlignmentLeft aligns cell content on the left (with specified indent); unused space on the right. CellHorizontalAlignmentLeft CellHorizontalAlignment = iota // CellHorizontalAlignmentCenter aligns cell content in the middle (unused space divided equally on the left/right). CellHorizontalAlignmentCenter // CellHorizontalAlignmentRight aligns the cell content on the right; unsued space on the left. CellHorizontalAlignmentRight )
Table cells have three horizontal alignment modes: left, center and right.
type CellVerticalAlignment ¶
type CellVerticalAlignment int
CellVerticalAlignment defines the table cell's vertical alignment.
const ( // CellVerticalAlignmentTop aligns cell content vertically to the top; unused space below. CellVerticalAlignmentTop CellVerticalAlignment = iota // CellVerticalAlignmentMiddle aligns cell content in the middle; unused space divided equally above and below. CellVerticalAlignmentMiddle // CellVerticalAlignmentBottom aligns cell content on the bottom; unused space above. CellVerticalAlignmentBottom )
Table cells have three vertical alignment modes: top, middle and bottom.
type Chapter ¶
type Chapter struct {
// contains filtered or unexported fields
}
Chapter is used to arrange multiple drawables (paragraphs, images, etc) into a single section. The concept is the same as a book or a report chapter.
func (*Chapter) GeneratePageBlocks ¶
func (chap *Chapter) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generate the Page blocks. Multiple blocks are generated if the contents wrap over multiple pages.
func (*Chapter) GetHeading ¶
GetHeading returns the chapter heading paragraph. Used to give access to address style: font, sizing etc.
func (*Chapter) GetMargins ¶
GetMargins returns the Chapter's margin: left, right, top, bottom.
func (*Chapter) NewSubchapter ¶
NewSubchapter creates a new child chapter with the specified title.
func (*Chapter) SetIncludeInTOC ¶
SetIncludeInTOC sets a flag to indicate whether or not to include in tOC.
func (*Chapter) SetMargins ¶
SetMargins sets the Chapter margins: left, right, top, bottom. Typically not needed as the creator's page margins are used.
func (*Chapter) SetShowNumbering ¶
SetShowNumbering sets a flag to indicate whether or not to show chapter numbers as part of title.
type Color ¶
Color interface represents colors in the PDF creator.
func ColorRGBFrom8bit ¶
ColorRGBFrom8bit creates a Color from 8bit (0-255) r,g,b values. Example:
red := ColorRGBFrom8Bit(255, 0, 0)
func ColorRGBFromArithmetic ¶
ColorRGBFromArithmetic creates a Color from arithmetic (0-1.0) color values. Example:
green := ColorRGBFromArithmetic(0, 1.0, 0)
func ColorRGBFromHex ¶
ColorRGBFromHex converts color hex code to rgb color for using with creator. NOTE: If there is a problem interpreting the string, then will use black color and log a debug message. Example hex code: #ffffff -> (1,1,1) white.
type Creator ¶
type Creator struct { // Controls whether a table of contents will be generated. AddTOC bool // Controls whether outlines will be generated. AddOutlines bool // contains filtered or unexported fields }
Creator is a wrapper around functionality for creating PDF reports and/or adding new content onto imported PDF pages, etc.
func (*Creator) Context ¶
func (c *Creator) Context() DrawContext
Context returns the current drawing context.
func (*Creator) CreateFrontPage ¶
func (c *Creator) CreateFrontPage(genFrontPageFunc func(args FrontpageFunctionArgs))
CreateFrontPage sets a function to generate a front Page.
func (*Creator) CreateTableOfContents ¶
CreateTableOfContents sets a function to generate table of contents.
func (*Creator) Draw ¶
Draw processes the specified Drawable widget and generates blocks that can be rendered to the output document. The generated blocks can span over one or more pages. Additional pages are added if the contents go over the current page. Each generated block is assigned to the creator page it will be rendered to. In order to render the generated blocks to the creator pages, call Finalize, Write or WriteToFile.
func (*Creator) DrawFooter ¶
func (c *Creator) DrawFooter(drawFooterFunc func(footer *Block, args FooterFunctionArgs))
DrawFooter sets a function to draw a footer on created output pages.
func (*Creator) DrawHeader ¶
func (c *Creator) DrawHeader(drawHeaderFunc func(header *Block, args HeaderFunctionArgs))
DrawHeader sets a function to draw a header on created output pages.
func (*Creator) EnableFontSubsetting ¶
EnableFontSubsetting enables font subsetting for `font` when the creator output is written to file. Embeds only the subset of the runes/glyphs that are actually used to display the file. Subsetting can reduce the size of fonts significantly.
func (*Creator) Finalize ¶
Finalize renders all blocks to the creator pages. In addition, it takes care of adding headers and footers, as well as generating the front page, table of contents and outlines. Finalize is automatically called before writing the document out. Calling the method manually can be useful when adding external pages to the creator, using the AddPage method, as it renders all creator blocks to the added pages, without having to write the document out. NOTE: TOC and outlines are generated only if the AddTOC and AddOutlines fields of the creator are set to true (enabled by default). Furthermore, TOCs and outlines without content are skipped. TOC and outline content is added automatically when using the chapter component. TOCs and outlines can also be set externally, using the SetTOC and SetOutlineTree methods. Finalize should only be called once, after all draw calls have taken place, as it will return immediately if the creator instance has been finalized.
func (*Creator) GetOptimizer ¶
GetOptimizer returns current PDF optimizer.
func (*Creator) MoveDown ¶
MoveDown moves the drawing context down by relative displacement dy (negative goes up).
func (*Creator) MoveRight ¶
MoveRight moves the drawing context right by relative displacement dx (negative goes left).
func (*Creator) NewChapter ¶
NewChapter creates a new chapter with the specified title as the heading.
func (*Creator) NewCurve ¶
NewCurve returns new instance of Curve between points (x1,y1) and (x2, y2) with control point (cx,cy).
func (*Creator) NewDivision ¶
NewDivision returns a new Division container component.
func (*Creator) NewEllipse ¶
NewEllipse creates a new ellipse centered at (xc,yc) with a width and height specified.
func (*Creator) NewFilledCurve ¶
func (c *Creator) NewFilledCurve() *FilledCurve
NewFilledCurve returns a instance of filled curve.
func (*Creator) NewImageFromData ¶
NewImageFromData creates an Image from image data.
func (*Creator) NewImageFromFile ¶
NewImageFromFile creates an Image from a file.
func (*Creator) NewImageFromGoImage ¶
NewImageFromGoImage creates an Image from a go image.Image data structure.
func (*Creator) NewInvoice ¶
NewInvoice returns an instance of an empty invoice.
func (*Creator) NewLine ¶
NewLine creates a new Line with default parameters between (x1,y1) to (x2,y2).
func (*Creator) NewPageBreak ¶
NewPageBreak create a new page break.
func (*Creator) NewParagraph ¶
NewParagraph creates a new text paragraph. Default attributes: Font: Helvetica, Font size: 10 Encoding: WinAnsiEncoding Wrap: enabled Text color: black
func (*Creator) NewRectangle ¶
NewRectangle creates a new Rectangle with default parameters with left corner at (x,y) and width, height as specified.
func (*Creator) NewStyledParagraph ¶
func (c *Creator) NewStyledParagraph() *StyledParagraph
NewStyledParagraph creates a new styled paragraph. Default attributes: Font: Helvetica, Font size: 10 Encoding: WinAnsiEncoding Wrap: enabled Text color: black
func (*Creator) NewStyledTOCLine ¶
func (c *Creator) NewStyledTOCLine(number, title, page TextChunk, level uint, style TextStyle) *TOCLine
NewStyledTOCLine creates a new table of contents line with the provided style.
func (*Creator) NewTOCLine ¶
NewTOCLine creates a new table of contents line with the default style.
func (*Creator) NewTextStyle ¶
NewTextStyle creates a new text style object which can be used to style chunks of text. Default attributes: Font: Helvetica Font size: 10 Encoding: WinAnsiEncoding Text color: black
func (*Creator) RotateDeg ¶
RotateDeg rotates the current active page by angle degrees. An error is returned on failure, which can be if there is no currently active page, or the angleDeg is not a multiple of 90 degrees.
func (*Creator) SetForms ¶
func (c *Creator) SetForms(form *model.PdfAcroForm) error
SetForms adds an Acroform to a PDF file. Sets the specified form for writing.
func (*Creator) SetOptimizer ¶
SetOptimizer sets the optimizer to optimize PDF before writing.
func (*Creator) SetOutlineTree ¶
func (c *Creator) SetOutlineTree(outlineTree *model.PdfOutlineTreeNode)
SetOutlineTree adds the specified outline tree to the PDF file generated by the creator. Adding an external outline tree disables the automatic generation of outlines done by the creator for the relevant components.
func (*Creator) SetPageLabels ¶
SetPageLabels adds the specified page labels to the PDF file generated by the creator. See section 12.4.2 "Page Labels" (p. 382 PDF32000_2008). NOTE: for existing PDF files, the page label ranges object can be obtained using the model.PDFReader's GetPageLabels method.
func (*Creator) SetPageMargins ¶
SetPageMargins sets the page margins: left, right, top, bottom. The default page margins are 10% of document width.
func (*Creator) SetPageSize ¶
SetPageSize sets the Creator's page size. Pages that are added after this will be created with this Page size. Does not affect pages already created.
Common page sizes are defined as constants. Examples: 1. c.SetPageSize(creator.PageSizeA4) 2. c.SetPageSize(creator.PageSizeA3) 3. c.SetPageSize(creator.PageSizeLegal) 4. c.SetPageSize(creator.PageSizeLetter)
For custom sizes: Use the PPMM (points per mm) and PPI (points per inch) when defining those based on physical page sizes:
Examples: 1. 10x15 sq. mm: SetPageSize(PageSize{10*creator.PPMM, 15*creator.PPMM}) where PPMM is points per mm. 2. 3x2 sq. inches: SetPageSize(PageSize{3*creator.PPI, 2*creator.PPI}) where PPI is points per inch.
func (*Creator) SetPdfWriterAccessFunc ¶
SetPdfWriterAccessFunc sets a PdfWriter access function/hook. Exposes the PdfWriter just prior to writing the PDF. Can be used to encrypt the output PDF, etc.
Example of encrypting with a user/owner password "password" Prior to calling c.WriteFile():
c.SetPdfWriterAccessFunc(func(w *model.PdfWriter) error { userPass := []byte("password") ownerPass := []byte("password") err := w.Encrypt(userPass, ownerPass, nil) return err })
func (*Creator) SetTOC ¶
SetTOC sets the table of content component of the creator. This method should be used when building a custom table of contents.
func (*Creator) WriteToFile ¶
WriteToFile writes the Creator output to file specified by path.
type Curve ¶
type Curve struct {
// contains filtered or unexported fields
}
Curve represents a cubic Bezier curve with a control point.
func (*Curve) GeneratePageBlocks ¶
func (c *Curve) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks draws the curve onto page blocks.
type Division ¶
type Division struct {
// contains filtered or unexported fields
}
Division is a container component which can wrap across multiple pages (unlike Block). It can contain multiple Drawable components (currently supporting Paragraph and Image).
The component stacking behavior is vertical, where the Drawables are drawn on top of each other. Also supports horizontal stacking by activating the inline mode.
func (*Division) Add ¶
func (div *Division) Add(d VectorDrawable) error
Add adds a VectorDrawable to the Division container. Currently supported VectorDrawables: *Paragraph, *StyledParagraph, *Image.
func (*Division) GeneratePageBlocks ¶
func (div *Division) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generates the page blocks for the Division component. Multiple blocks are generated if the contents wrap over multiple pages.
func (*Division) Height ¶
Height returns the height for the Division component assuming all stacked on top of each other.
type DrawContext ¶
type DrawContext struct { // Current page number. Page int // Current position. In a relative positioning mode, a drawable will be placed at these coordinates. X, Y float64 // Context dimensions. Available width and height (on current page). Width, Height float64 // Page Margins. Margins margins // Absolute Page size, widths and height. PageWidth float64 PageHeight float64 // Controls whether the components are stacked horizontally Inline bool }
DrawContext defines the drawing context. The DrawContext is continuously used and updated when drawing the page contents in relative mode. Keeps track of current X, Y position, available height as well as other page parameters such as margins and dimensions.
type Drawable ¶
type Drawable interface { // GeneratePageBlocks draw onto blocks representing Page contents. As the content can wrap over many pages, multiple // templates are returned, one per Page. The function also takes a draw context containing information // where to draw (if relative positioning) and the available height to draw on accounting for Margins etc. GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error) }
Drawable is a widget that can be used to draw with the Creator.
type Ellipse ¶
type Ellipse struct {
// contains filtered or unexported fields
}
Ellipse defines an ellipse with a center at (xc,yc) and a specified width and height. The ellipse can have a colored fill and/or border with a specified width. Implements the Drawable interface and can be drawn on PDF using the Creator.
func (*Ellipse) GeneratePageBlocks ¶
func (ell *Ellipse) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks draws the rectangle on a new block representing the page.
func (*Ellipse) SetBorderColor ¶
SetBorderColor sets the border color.
func (*Ellipse) SetBorderWidth ¶
SetBorderWidth sets the border width.
func (*Ellipse) SetFillColor ¶
SetFillColor sets the fill color.
type FilledCurve ¶
type FilledCurve struct { FillEnabled bool // Show fill? BorderEnabled bool // Show border? BorderWidth float64 // contains filtered or unexported fields }
FilledCurve represents a closed path of Bezier curves with a border and fill.
func (*FilledCurve) AppendCurve ¶
func (fc *FilledCurve) AppendCurve(curve draw.CubicBezierCurve) *FilledCurve
AppendCurve appends a Bezier curve to the filled curve.
func (*FilledCurve) GeneratePageBlocks ¶
func (fc *FilledCurve) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks draws the filled curve on page blocks.
func (*FilledCurve) SetBorderColor ¶
func (fc *FilledCurve) SetBorderColor(color Color)
SetBorderColor sets the border color for the path.
func (*FilledCurve) SetFillColor ¶
func (fc *FilledCurve) SetFillColor(color Color)
SetFillColor sets the fill color for the path.
type FooterFunctionArgs ¶
type FooterFunctionArgs struct {}
FooterFunctionArgs holds the input arguments to a footer drawing function. It is designed as a struct, so additional parameters can be added in the future with backwards compatibility.
type FrontpageFunctionArgs ¶
FrontpageFunctionArgs holds the input arguments to a front page drawing function. It is designed as a struct, so additional parameters can be added in the future with backwards compatibility.
type HeaderFunctionArgs ¶
HeaderFunctionArgs holds the input arguments to a header drawing function. It is designed as a struct, so additional parameters can be added in the future with backwards compatibility.
type HorizontalAlignment ¶
type HorizontalAlignment int
HorizontalAlignment represents the horizontal alignment of components within a page.
const ( HorizontalAlignmentLeft HorizontalAlignment = iota HorizontalAlignmentCenter HorizontalAlignmentRight )
Horizontal alignment options.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
The Image type is used to draw an image onto PDF.
func (*Image) ConvertToBinary ¶
ConvertToBinary converts current image data into binary (Bi-level image) format. If provided image is RGB or GrayScale the function converts it into binary image using histogram auto threshold method.
func (*Image) GeneratePageBlocks ¶
func (img *Image) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generate the Page blocks. Draws the Image on a block, implementing the Drawable interface.
func (*Image) GetHorizontalAlignment ¶
func (img *Image) GetHorizontalAlignment() HorizontalAlignment
GetHorizontalAlignment returns the horizontal alignment of the image.
func (*Image) GetMargins ¶
GetMargins returns the Image's margins: left, right, top, bottom.
func (*Image) ScaleToHeight ¶
ScaleToHeight scale Image to a specified height h, maintaining the aspect ratio.
func (*Image) ScaleToWidth ¶
ScaleToWidth scale Image to a specified width w, maintaining the aspect ratio.
func (*Image) SetEncoder ¶
func (img *Image) SetEncoder(encoder core.StreamEncoder)
SetEncoder sets the encoding/compression mechanism for the image.
func (*Image) SetHorizontalAlignment ¶
func (img *Image) SetHorizontalAlignment(alignment HorizontalAlignment)
SetHorizontalAlignment sets the horizontal alignment of the image.
func (*Image) SetMargins ¶
SetMargins sets the margins for the Image (in relative mode): left, right, top, bottom.
func (*Image) SetOpacity ¶
SetOpacity sets opacity for Image.
type Invoice ¶
type Invoice struct {
// contains filtered or unexported fields
}
Invoice represents a configurable invoice template.
func (*Invoice) AddInfo ¶
func (i *Invoice) AddInfo(description, value string) (*InvoiceCell, *InvoiceCell)
AddInfo is used to append a piece of invoice information in the template information table.
func (*Invoice) AddLine ¶
func (i *Invoice) AddLine(values ...string) []*InvoiceCell
AddLine appends a new line to the invoice line items table.
func (*Invoice) AddSection ¶
AddSection adds a new content section at the end of the invoice.
func (*Invoice) AddTotalLine ¶
func (i *Invoice) AddTotalLine(desc, value string) (*InvoiceCell, *InvoiceCell)
AddTotalLine adds a new line in the invoice totals table.
func (*Invoice) AddressHeadingStyle ¶
AddressHeadingStyle returns the style properties used to render the heading of the invoice address sections.
func (*Invoice) AddressStyle ¶
AddressStyle returns the style properties used to render the content of the invoice address sections.
func (*Invoice) AppendColumn ¶
func (i *Invoice) AppendColumn(description string) *InvoiceCell
AppendColumn appends a column to the line items table.
func (*Invoice) BuyerAddress ¶
func (i *Invoice) BuyerAddress() *InvoiceAddress
BuyerAddress returns the buyer address used in the invoice template.
func (*Invoice) Columns ¶
func (i *Invoice) Columns() []*InvoiceCell
Columns returns all the columns in the invoice line items table.
func (*Invoice) Date ¶
func (i *Invoice) Date() (*InvoiceCell, *InvoiceCell)
Date returns the invoice date description and value cells. The returned values can be used to customize the styles of the cells.
func (*Invoice) DueDate ¶
func (i *Invoice) DueDate() (*InvoiceCell, *InvoiceCell)
DueDate returns the invoice due date description and value cells. The returned values can be used to customize the styles of the cells.
func (*Invoice) GeneratePageBlocks ¶
func (i *Invoice) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generate the Page blocks. Multiple blocks are generated if the contents wrap over multiple pages.
func (*Invoice) InfoLines ¶
func (i *Invoice) InfoLines() [][2]*InvoiceCell
InfoLines returns all the rows in the invoice information table as description-value cell pairs.
func (*Invoice) InsertColumn ¶
func (i *Invoice) InsertColumn(index uint, description string) *InvoiceCell
InsertColumn inserts a column in the line items table at the specified index.
func (*Invoice) Lines ¶
func (i *Invoice) Lines() [][]*InvoiceCell
Lines returns all the rows of the invoice line items table.
func (*Invoice) NewCell ¶
func (i *Invoice) NewCell(value string) *InvoiceCell
NewCell returns a new invoice table cell.
func (*Invoice) NewCellProps ¶
func (i *Invoice) NewCellProps() InvoiceCellProps
NewCellProps returns the default properties of an invoice cell.
func (*Invoice) NewColumn ¶
func (i *Invoice) NewColumn(description string) *InvoiceCell
NewColumn returns a new column for the line items invoice table.
func (*Invoice) NoteHeadingStyle ¶
NoteHeadingStyle returns the style properties used to render the heading of the invoice note sections.
func (*Invoice) NoteStyle ¶
NoteStyle returns the style properties used to render the content of the invoice note sections.
func (*Invoice) Number ¶
func (i *Invoice) Number() (*InvoiceCell, *InvoiceCell)
Number returns the invoice number description and value cells. The returned values can be used to customize the styles of the cells.
func (*Invoice) Sections ¶
Sections returns the custom content sections of the invoice as title-content pairs.
func (*Invoice) SellerAddress ¶
func (i *Invoice) SellerAddress() *InvoiceAddress
SellerAddress returns the seller address used in the invoice template.
func (*Invoice) SetAddressHeadingStyle ¶
SetAddressHeadingStyle sets the style properties used to render the heading of the invoice address sections.
func (*Invoice) SetAddressStyle ¶
SetAddressStyle sets the style properties used to render the content of the invoice address sections.
func (*Invoice) SetBuyerAddress ¶
func (i *Invoice) SetBuyerAddress(address *InvoiceAddress)
SetBuyerAddress sets the buyer address of the invoice.
func (*Invoice) SetColumns ¶
func (i *Invoice) SetColumns(cols []*InvoiceCell)
SetColumns overwrites any columns in the line items table. This should be called before AddLine.
func (*Invoice) SetDate ¶
func (i *Invoice) SetDate(date string) (*InvoiceCell, *InvoiceCell)
SetDate sets the date of the invoice.
func (*Invoice) SetDueDate ¶
func (i *Invoice) SetDueDate(dueDate string) (*InvoiceCell, *InvoiceCell)
SetDueDate sets the due date of the invoice.
func (*Invoice) SetNoteHeadingStyle ¶
SetNoteHeadingStyle sets the style properties used to render the heading of the invoice note sections.
func (*Invoice) SetNoteStyle ¶
SetNoteStyle sets the style properties used to render the content of the invoice note sections.
func (*Invoice) SetNumber ¶
func (i *Invoice) SetNumber(number string) (*InvoiceCell, *InvoiceCell)
SetNumber sets the number of the invoice.
func (*Invoice) SetSellerAddress ¶
func (i *Invoice) SetSellerAddress(address *InvoiceAddress)
SetSellerAddress sets the seller address of the invoice.
func (*Invoice) SetSubtotal ¶
SetSubtotal sets the subtotal of the invoice.
func (*Invoice) SetTitleStyle ¶
SetTitleStyle sets the style properties of the invoice title.
func (*Invoice) Subtotal ¶
func (i *Invoice) Subtotal() (*InvoiceCell, *InvoiceCell)
Subtotal returns the invoice subtotal description and value cells. The returned values can be used to customize the styles of the cells.
func (*Invoice) Terms ¶
Terms returns the terms and conditions section of the invoice as a title-content pair.
func (*Invoice) TitleStyle ¶
TitleStyle returns the style properties used to render the invoice title.
func (*Invoice) Total ¶
func (i *Invoice) Total() (*InvoiceCell, *InvoiceCell)
Total returns the invoice total description and value cells. The returned values can be used to customize the styles of the cells.
func (*Invoice) TotalLines ¶
func (i *Invoice) TotalLines() [][2]*InvoiceCell
TotalLines returns all the rows in the invoice totals table as description-value cell pairs.
type InvoiceAddress ¶
type InvoiceAddress struct { Heading string Name string Street string Street2 string Zip string City string State string Country string Phone string Email string // Separator defines the separator between different address components, // such as the city, state and zip code. It defaults to ", " when the // field is an empty string. Separator string }
InvoiceAddress contains contact information that can be displayed in an invoice. It is used for the seller and buyer information in the invoice template.
type InvoiceCell ¶
type InvoiceCell struct { InvoiceCellProps Value string }
InvoiceCell represents any cell belonging to a table from the invoice template. The main tables are the invoice information table, the line items table and totals table. Contains the text value of the cell and the style properties of the cell.
type InvoiceCellProps ¶
type InvoiceCellProps struct { TextStyle TextStyle Alignment CellHorizontalAlignment BackgroundColor Color BorderColor Color BorderWidth float64 BorderSides []CellBorderSide }
InvoiceCellProps holds all style properties for an invoice cell.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line), or arrows at either end. The line also has a specified width, color and opacity. Implements the Drawable interface and can be drawn on PDF using the Creator.
func (*Line) GeneratePageBlocks ¶
func (l *Line) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks draws the line on a new block representing the page. Implements the Drawable interface.
func (*Line) SetColor ¶
SetColor sets the line color. Use ColorRGBFromHex, ColorRGBFrom8bit or ColorRGBFromArithmetic to make the color object.
func (*Line) SetLineWidth ¶
SetLineWidth sets the line width.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List represents a list of items. The representation of a list item is as follows:
[marker] [content]
e.g.: • This is the content of the item. The supported components to add content to list items are: - Paragraph - StyledParagraph - List
func (*List) Add ¶
func (l *List) Add(item VectorDrawable) (*TextChunk, error)
Add appends a new item to the list. The supported components are: *Paragraph, *StyledParagraph and *List. Returns the marker used for the newly added item. The returned marker object can be used to change the text and style of the marker for the current item.
func (*List) AddTextItem ¶
func (l *List) AddTextItem(text string) (*StyledParagraph, *TextChunk, error)
AddTextItem appends a new item with the specified text to the list. The method creates a styled paragraph with the specified text and returns it so that the item style can be customized. The method also returns the marker used for the newly added item. The marker object can be used to change the text and style of the marker for the current item.
func (*List) GeneratePageBlocks ¶
func (l *List) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generate the Page blocks. Multiple blocks are generated if the contents wrap over multiple pages.
func (*List) Marker ¶
Marker returns the marker used for the list items. The marker instance can be used the change the text and the style of newly added list items.
func (*List) SetMargins ¶
SetMargins sets the margins of the paragraph.
type PageBreak ¶
type PageBreak struct { }
PageBreak represents a page break for a chapter.
func (*PageBreak) GeneratePageBlocks ¶
func (p *PageBreak) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generates a page break block.
type PageSize ¶
type PageSize [2]float64
PageSize represents the page size as a 2 element array representing the width and height in PDF document units (points).
type Paragraph ¶
type Paragraph struct {
// contains filtered or unexported fields
}
Paragraph represents text drawn with a specified font and can wrap across lines and pages. By default it occupies the available width in the drawing context.
func (*Paragraph) GeneratePageBlocks ¶
func (p *Paragraph) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generates the page blocks. Multiple blocks are generated if the contents wrap over multiple pages. Implements the Drawable interface.
func (*Paragraph) GetMargins ¶
GetMargins returns the Paragraph's margins: left, right, top, bottom.
func (*Paragraph) Height ¶
Height returns the height of the Paragraph. The height is calculated based on the input text and how it is wrapped within the container. Does not include Margins.
func (*Paragraph) SetColor ¶
SetColor sets the color of the Paragraph text.
Example:
p := NewParagraph("Red paragraph") // Set to red color with a hex code: p.SetColor(creator.ColorRGBFromHex("#ff0000"))
Make Paragraph green with 8-bit rgb values (0-255 each component) p.SetColor(creator.ColorRGBFrom8bit(0, 255, 0)
Make Paragraph blue with arithmetic (0-1) rgb components. p.SetColor(creator.ColorRGBFromArithmetic(0, 0, 1.0)
func (*Paragraph) SetEnableWrap ¶
SetEnableWrap sets the line wrapping enabled flag.
func (*Paragraph) SetFontSize ¶
SetFontSize sets the font size in document units (points).
func (*Paragraph) SetLineHeight ¶
SetLineHeight sets the line height (1.0 default).
func (*Paragraph) SetMargins ¶
SetMargins sets the Paragraph's margins.
func (*Paragraph) SetTextAlignment ¶
func (p *Paragraph) SetTextAlignment(align TextAlignment)
SetTextAlignment sets the horizontal alignment of the text within the space provided.
func (*Paragraph) SetWidth ¶
SetWidth sets the the Paragraph width. This is essentially the wrapping width, i.e. the width the text can extend to prior to wrapping over to next line.
type Rectangle ¶
type Rectangle struct {
// contains filtered or unexported fields
}
Rectangle defines a rectangle with upper left corner at (x,y) and a specified width and height. The rectangle can have a colored fill and/or border with a specified width. Implements the Drawable interface and can be drawn on PDF using the Creator.
func (*Rectangle) GeneratePageBlocks ¶
func (rect *Rectangle) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks draws the rectangle on a new block representing the page. Implements the Drawable interface.
func (*Rectangle) GetCoords ¶
GetCoords returns coordinates of the Rectangle's upper left corner (x,y).
func (*Rectangle) SetBorderColor ¶
SetBorderColor sets border color.
func (*Rectangle) SetBorderWidth ¶
SetBorderWidth sets the border width.
func (*Rectangle) SetFillColor ¶
SetFillColor sets the fill color.
type StyledParagraph ¶
type StyledParagraph struct {
// contains filtered or unexported fields
}
StyledParagraph represents text drawn with a specified font and can wrap across lines and pages. By default occupies the available width in the drawing context.
func (*StyledParagraph) AddExternalLink ¶
func (p *StyledParagraph) AddExternalLink(text, url string) *TextChunk
AddExternalLink adds a new external link to the paragraph. The text parameter represents the text that is displayed and the url parameter sets the destionation of the link.
func (*StyledParagraph) AddInternalLink ¶
func (p *StyledParagraph) AddInternalLink(text string, page int64, x, y, zoom float64) *TextChunk
AddInternalLink adds a new internal link to the paragraph. The text parameter represents the text that is displayed. The user is taken to the specified page, at the specified x and y coordinates. Position 0, 0 is at the top left of the page. The zoom of the destination page is controlled with the zoom parameter. Pass in 0 to keep the current zoom value.
func (*StyledParagraph) Append ¶
func (p *StyledParagraph) Append(text string) *TextChunk
Append adds a new text chunk to the paragraph.
func (*StyledParagraph) GeneratePageBlocks ¶
func (p *StyledParagraph) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generates the page blocks. Multiple blocks are generated if the contents wrap over multiple pages. Implements the Drawable interface.
func (*StyledParagraph) GetMargins ¶
func (p *StyledParagraph) GetMargins() (float64, float64, float64, float64)
GetMargins returns the Paragraph's margins: left, right, top, bottom.
func (*StyledParagraph) Height ¶
func (p *StyledParagraph) Height() float64
Height returns the height of the Paragraph. The height is calculated based on the input text and how it is wrapped within the container. Does not include Margins.
func (*StyledParagraph) Insert ¶
func (p *StyledParagraph) Insert(index uint, text string) *TextChunk
Insert adds a new text chunk at the specified position in the paragraph.
func (*StyledParagraph) Reset ¶
func (p *StyledParagraph) Reset()
Reset removes all the text chunks the paragraph contains.
func (*StyledParagraph) SetAngle ¶
func (p *StyledParagraph) SetAngle(angle float64)
SetAngle sets the rotation angle of the text.
func (*StyledParagraph) SetEnableWrap ¶
func (p *StyledParagraph) SetEnableWrap(enableWrap bool)
SetEnableWrap sets the line wrapping enabled flag.
func (*StyledParagraph) SetLineHeight ¶
func (p *StyledParagraph) SetLineHeight(lineheight float64)
SetLineHeight sets the line height (1.0 default).
func (*StyledParagraph) SetMargins ¶
func (p *StyledParagraph) SetMargins(left, right, top, bottom float64)
SetMargins sets the Paragraph's margins.
func (*StyledParagraph) SetPos ¶
func (p *StyledParagraph) SetPos(x, y float64)
SetPos sets absolute positioning with specified coordinates.
func (*StyledParagraph) SetText ¶
func (p *StyledParagraph) SetText(text string) *TextChunk
SetText replaces all the text of the paragraph with the specified one.
func (*StyledParagraph) SetTextAlignment ¶
func (p *StyledParagraph) SetTextAlignment(align TextAlignment)
SetTextAlignment sets the horizontal alignment of the text within the space provided.
func (*StyledParagraph) SetWidth ¶
func (p *StyledParagraph) SetWidth(width float64)
SetWidth sets the the Paragraph width. This is essentially the wrapping width, i.e. the width the text can extend to prior to wrapping over to next line.
func (*StyledParagraph) Width ¶
func (p *StyledParagraph) Width() float64
Width returns the width of the Paragraph.
type TOC ¶
type TOC struct {
// contains filtered or unexported fields
}
TOC represents a table of contents component. It consists of a paragraph heading and a collection of table of contents lines. The representation of a table of contents line is as follows:
[number] [title] [separator] [page]
e.g.: Chapter1 Introduction ........... 1
func (*TOC) GeneratePageBlocks ¶
func (t *TOC) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generate the Page blocks. Multiple blocks are generated if the contents wrap over multiple pages.
func (*TOC) Heading ¶
func (t *TOC) Heading() *StyledParagraph
Heading returns the heading component of the table of contents.
func (*TOC) SetHeading ¶
SetHeading sets the text and the style of the heading of the TOC component.
func (*TOC) SetLineLevelOffset ¶
SetLineLevelOffset sets the amount of space an indentation level occupies for all new lines of the table of contents.
func (*TOC) SetLineMargins ¶
SetLineMargins sets the margins for all new lines of the table of contents.
func (*TOC) SetLineNumberStyle ¶
SetLineNumberStyle sets the style for the numbers part of all new lines of the table of contents.
func (*TOC) SetLinePageStyle ¶
SetLinePageStyle sets the style for the page part of all new lines of the table of contents.
func (*TOC) SetLineSeparator ¶
SetLineSeparator sets the separator for all new lines of the table of contents.
func (*TOC) SetLineSeparatorStyle ¶
SetLineSeparatorStyle sets the style for the separator part of all new lines of the table of contents.
func (*TOC) SetLineStyle ¶
SetLineStyle sets the style for all the line components: number, title, separator, page. The style is applied only for new lines added to the TOC component.
func (*TOC) SetLineTitleStyle ¶
SetLineTitleStyle sets the style for the title part of all new lines of the table of contents.
func (*TOC) SetShowLinks ¶
SetShowLinks sets visibility of links for the TOC lines.
type TOCLine ¶
type TOCLine struct { // Holds the text and style of the number part of the TOC line. Number TextChunk // Holds the text and style of the title part of the TOC line. Title TextChunk // Holds the text and style of the separator part of the TOC line. Separator TextChunk // Holds the text and style of the page part of the TOC line. Page TextChunk // contains filtered or unexported fields }
TOCLine represents a line in a table of contents. The component can be used both in the context of a table of contents component and as a standalone component. The representation of a table of contents line is as follows:
[number] [title] [separator] [page]
e.g.: Chapter1 Introduction ........... 1
func (*TOCLine) GeneratePageBlocks ¶
func (tl *TOCLine) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generate the Page blocks. Multiple blocks are generated if the contents wrap over multiple pages.
func (*TOCLine) GetMargins ¶
GetMargins returns the margins of the TOC line: left, right, top, bottom.
func (*TOCLine) LevelOffset ¶
LevelOffset returns the amount of space an indentation level occupies.
func (*TOCLine) SetLevelOffset ¶
SetLevelOffset sets the amount of space an indentation level occupies.
func (*TOCLine) SetLink ¶
SetLink makes the line an internal link. The text parameter represents the text that is displayed. The user is taken to the specified page, at the specified x and y coordinates. Position 0, 0 is at the top left of the page.
func (*TOCLine) SetMargins ¶
SetMargins sets the margins TOC line.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table allows organizing content in an rows X columns matrix, which can spawn across multiple pages.
func (*Table) AddSubtable ¶
AddSubtable copies the cells of the subtable in the table, starting with the specified position. The table row and column indices are 1-based, which makes the position of the first cell of the first row of the table 1,1. The table is automatically extended if the subtable exceeds its columns. This can happen when the subtable has more columns than the table or when one or more columns of the subtable starting from the specified position exceed the last column of the table.
func (*Table) GeneratePageBlocks ¶
func (table *Table) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
GeneratePageBlocks generate the page blocks. Multiple blocks are generated if the contents wrap over multiple pages. Implements the Drawable interface.
func (*Table) GetMargins ¶
GetMargins returns the left, right, top, bottom Margins.
func (*Table) GetRowHeight ¶
GetRowHeight returns the height of the specified row.
func (*Table) MultiColCell ¶
MultiColCell makes a new cell with the specified column span and inserts it into the table at the current position.
func (*Table) NewCell ¶
NewCell makes a new cell and inserts it into the table at the current position.
func (*Table) SetColumnWidths ¶
SetColumnWidths sets the fractional column widths. Each width should be in the range 0-1 and is a fraction of the table width. The number of width inputs must match number of columns, otherwise an error is returned.
func (*Table) SetHeaderRows ¶
SetHeaderRows turns the selected table rows into headers that are repeated for every page the table spans. startRow and endRow are inclusive.
func (*Table) SetMargins ¶
SetMargins sets the Table's left, right, top, bottom margins.
func (*Table) SetPos ¶
SetPos sets the Table's positioning to absolute mode and specifies the upper-left corner coordinates as (x,y). Note that this is only sensible to use when the table does not wrap over multiple pages. TODO: Should be able to set width too (not just based on context/relative positioning mode).
func (*Table) SetRowHeight ¶
SetRowHeight sets the height for a specified row.
type TableCell ¶
type TableCell struct {
// contains filtered or unexported fields
}
TableCell defines a table cell which can contain a Drawable as content.
func (*TableCell) SetBackgroundColor ¶
SetBackgroundColor sets the cell's background color.
func (*TableCell) SetBorder ¶
func (cell *TableCell) SetBorder(side CellBorderSide, style CellBorderStyle, width float64)
SetBorder sets the cell's border style.
func (*TableCell) SetBorderColor ¶
SetBorderColor sets the cell's border color.
func (*TableCell) SetBorderLineStyle ¶
SetBorderLineStyle sets border style (currently dashed or plain).
func (*TableCell) SetContent ¶
func (cell *TableCell) SetContent(vd VectorDrawable) error
SetContent sets the cell's content. The content is a VectorDrawable, i.e. a Drawable with a known height and width. The currently supported VectorDrawable is: *Paragraph, *StyledParagraph.
func (*TableCell) SetHorizontalAlignment ¶
func (cell *TableCell) SetHorizontalAlignment(halign CellHorizontalAlignment)
SetHorizontalAlignment sets the cell's horizontal alignment of content. Can be one of: - CellHorizontalAlignmentLeft - CellHorizontalAlignmentCenter - CellHorizontalAlignmentRight
func (*TableCell) SetVerticalAlignment ¶
func (cell *TableCell) SetVerticalAlignment(valign CellVerticalAlignment)
SetVerticalAlignment set the cell's vertical alignment of content. Can be one of: - CellHorizontalAlignmentTop - CellHorizontalAlignmentMiddle - CellHorizontalAlignmentBottom
func (*TableCell) Width ¶
func (cell *TableCell) Width(ctx DrawContext) float64
Width returns the cell's width based on the input draw context.
type TextAlignment ¶
type TextAlignment int
TextAlignment options for paragraph.
const ( TextAlignmentLeft TextAlignment = iota TextAlignmentRight TextAlignmentCenter TextAlignmentJustify )
The options supported for text alignment are: left - TextAlignmentLeft right - TextAlignmentRight center - TextAlignmentCenter justify - TextAlignmentJustify
type TextChunk ¶
type TextChunk struct { // The text that is being rendered in the PDF. Text string // The style of the text being rendered. Style TextStyle // contains filtered or unexported fields }
TextChunk represents a chunk of text along with a particular style.
func NewTextChunk ¶
NewTextChunk returns a new text chunk instance.
func (*TextChunk) Fit ¶
Fit fits the chunk into the specified bounding box, cropping off the remainder in a new chunk, if it exceeds the specified dimensions. NOTE: The method assumes a line height of 1.0. In order to account for other line height values, the passed in height must be divided by the line height: height = height / lineHeight
func (*TextChunk) SetAnnotation ¶
func (tc *TextChunk) SetAnnotation(annotation *model.PdfAnnotation)
SetAnnotation sets a annotation on a TextChunk.
type TextRenderingMode ¶
type TextRenderingMode int
TextRenderingMode determines whether showing text shall cause glyph outlines to be stroked, filled, used as a clipping boundary, or some combination of the three. See section 9.3 "Text State Parameters and Operators" and Table 106 (pp. 254-255 PDF32000_2008).
const ( // TextRenderingModeFill (default) - Fill text. TextRenderingModeFill TextRenderingMode = iota // TextRenderingModeStroke - Stroke text. TextRenderingModeStroke // TextRenderingModeFillStroke - Fill, then stroke text. TextRenderingModeFillStroke // TextRenderingModeInvisible - Neither fill nor stroke text (invisible). TextRenderingModeInvisible // TextRenderingModeFillClip - Fill text and add to path for clipping. TextRenderingModeFillClip // TextRenderingModeStrokeClip - Stroke text and add to path for clipping. TextRenderingModeStrokeClip // TextRenderingModeFillStrokeClip - Fill, then stroke text and add to path for clipping. TextRenderingModeFillStrokeClip // TextRenderingModeClip - Add text to path for clipping. TextRenderingModeClip )
type TextStyle ¶
type TextStyle struct { // The color of the text. Color Color // The font the text will use. Font *model.PdfFont // The size of the font. FontSize float64 // The character spacing. CharSpacing float64 // The rendering mode. RenderingMode TextRenderingMode }
TextStyle is a collection of properties that can be assigned to a chunk of text.
type VectorDrawable ¶
type VectorDrawable interface { Drawable // Width returns the width of the Drawable. Width() float64 // Height returns the height of the Drawable. Height() float64 }
VectorDrawable is a Drawable with a specified width and height.