unidoc: github.com/unidoc/unidoc/pdf/creator Index | Files

package creator

import "github.com/unidoc/unidoc/pdf/creator"

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

Package Files

block.go chapters.go color.go const.go creator.go curve.go division.go doc.go drawable.go ellipse.go filled_curve.go image.go line.go pagebreak.go paragraph.go rectangle.go styled_paragraph.go subchapter.go table.go text_style.go toc.go utils.go

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 // Points per mm. (Default resolution).

PPMM specifies the default PDF resolution in points/mm.

type Block Uses

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 NewBlock Uses

func NewBlock(width float64, height float64) *Block

NewBlock creates a new Block with specified width and height.

func NewBlockFromPage Uses

func NewBlockFromPage(page *model.PdfPage) (*Block, error)

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) Draw Uses

func (blk *Block) Draw(d Drawable) error

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 Uses

func (blk *Block) DrawWithContext(d Drawable, ctx DrawContext) error

DrawWithContext draws the Block using the specified drawing context.

func (*Block) GeneratePageBlocks Uses

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 Uses

func (blk *Block) GetMargins() (float64, float64, float64, float64)

GetMargins returns the Block's margins: left, right, top, bottom.

func (*Block) Height Uses

func (blk *Block) Height() float64

Height returns the Block's height.

func (*Block) Scale Uses

func (blk *Block) Scale(sx, sy float64)

Scale block by specified factors in the x and y directions.

func (*Block) ScaleToHeight Uses

func (blk *Block) ScaleToHeight(h float64)

ScaleToHeight scales the Block to a specified height, maintaining the same aspect ratio.

func (*Block) ScaleToWidth Uses

func (blk *Block) ScaleToWidth(w float64)

ScaleToWidth scales the Block to a specified width, maintaining the same aspect ratio.

func (*Block) SetAngle Uses

func (blk *Block) SetAngle(angleDeg float64)

SetAngle sets the rotation angle in degrees.

func (*Block) SetMargins Uses

func (blk *Block) SetMargins(left, right, top, bottom float64)

SetMargins sets the Block's left, right, top, bottom, margins.

func (*Block) SetPos Uses

func (blk *Block) SetPos(x, y float64)

SetPos sets the Block's positioning to absolute mode with the specified coordinates.

func (*Block) Width Uses

func (blk *Block) Width() float64

Width returns the Block's width.

type CellBorderStyle Uses

type CellBorderStyle int

CellBorderStyle defines the table cell's border style.

const (
    // No border
    CellBorderStyleNone CellBorderStyle = iota

    // Borders along all sides (boxed).
    CellBorderStyleBox
)

Currently supported table styles are: None (no border) and boxed (line along each side).

type CellHorizontalAlignment Uses

type CellHorizontalAlignment int

CellHorizontalAlignment defines the table cell's horizontal alignment.

const (
    // Align cell content on the left (with specified indent); unused space on the right.
    CellHorizontalAlignmentLeft CellHorizontalAlignment = iota

    // Align cell content in the middle (unused space divided equally on the left/right).
    CellHorizontalAlignmentCenter

    // Align 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 Uses

type CellVerticalAlignment int

CellVerticalAlignment defines the table cell's vertical alignment.

const (
    // Align cell content vertically to the top; unused space below.
    CellVerticalAlignmentTop CellVerticalAlignment = iota

    // Align cell content in the middle; unused space divided equally above and below.
    CellVerticalAlignmentMiddle

    // Align cell content on the bottom; unused space above.
    CellVerticalAlignmentBottom
)

Table cells have three vertical alignment modes: top, middle and bottom.

type Chapter Uses

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) Add Uses

func (chap *Chapter) Add(d Drawable) error

Add adds a new Drawable to the chapter.

func (*Chapter) GeneratePageBlocks Uses

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 Uses

func (chap *Chapter) GetHeading() *Paragraph

GetHeading returns the chapter heading paragraph. Used to give access to address style: font, sizing etc.

func (*Chapter) GetMargins Uses

func (chap *Chapter) GetMargins() (float64, float64, float64, float64)

GetMargins returns the Chapter's margin: left, right, top, bottom.

func (*Chapter) SetIncludeInTOC Uses

func (chap *Chapter) SetIncludeInTOC(includeInTOC bool)

SetIncludeInTOC sets a flag to indicate whether or not to include in tOC.

func (*Chapter) SetMargins Uses

func (chap *Chapter) SetMargins(left, right, top, bottom float64)

SetMargins sets the Chapter margins: left, right, top, bottom. Typically not needed as the creator's page margins are used.

func (*Chapter) SetShowNumbering Uses

func (chap *Chapter) SetShowNumbering(show bool)

SetShowNumbering sets a flag to indicate whether or not to show chapter numbers as part of title.

type Color Uses

type Color interface {
    ToRGB() (float64, float64, float64)
}

Color interface represents colors in the PDF creator.

func ColorRGBFrom8bit Uses

func ColorRGBFrom8bit(r, g, b byte) Color

ColorRGBFrom8bit creates a Color from 8bit (0-255) r,g,b values. Example:

red := ColorRGBFrom8Bit(255, 0, 0)

func ColorRGBFromArithmetic Uses

func ColorRGBFromArithmetic(r, g, b float64) Color

ColorRGBFromArithmetic creates a Color from arithmetic (0-1.0) color values. Example:

green := ColorRGBFromArithmetic(0, 1.0, 0)

func ColorRGBFromHex Uses

func ColorRGBFromHex(hexStr string) Color

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 Uses

type Creator struct {
    // 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 New Uses

func New() *Creator

New creates a new instance of the PDF Creator.

func (*Creator) AddPage Uses

func (c *Creator) AddPage(page *model.PdfPage) error

AddPage adds the specified page to the creator.

func (*Creator) Context Uses

func (c *Creator) Context() DrawContext

Context returns the current drawing context.

func (*Creator) CreateFrontPage Uses

func (c *Creator) CreateFrontPage(genFrontPageFunc func(args FrontpageFunctionArgs))

CreateFrontPage sets a function to generate a front Page.

func (*Creator) CreateTableOfContents Uses

func (c *Creator) CreateTableOfContents(genTOCFunc func(toc *TableOfContents) (*Chapter, error))

CreateTableOfContents sets a function to generate table of contents.

func (*Creator) Draw Uses

func (c *Creator) Draw(d Drawable) error

Draw draws the Drawable widget to the document. This can span over 1 or more pages. Additional pages are added if the contents go over the current Page.

func (*Creator) DrawFooter Uses

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 Uses

func (c *Creator) DrawHeader(drawHeaderFunc func(header *Block, args HeaderFunctionArgs))

DrawHeader sets a function to draw a header on created output pages.

func (*Creator) Height Uses

func (c *Creator) Height() float64

Height returns the current page height.

func (*Creator) MoveDown Uses

func (c *Creator) MoveDown(dy float64)

MoveDown moves the drawing context down by relative displacement dy (negative goes up).

func (*Creator) MoveRight Uses

func (c *Creator) MoveRight(dx float64)

MoveRight moves the drawing context right by relative displacement dx (negative goes left).

func (*Creator) MoveTo Uses

func (c *Creator) MoveTo(x, y float64)

MoveTo moves the drawing context to absolute coordinates (x, y).

func (*Creator) MoveX Uses

func (c *Creator) MoveX(x float64)

MoveX moves the drawing context to absolute position x.

func (*Creator) MoveY Uses

func (c *Creator) MoveY(y float64)

MoveY moves the drawing context to absolute position y.

func (*Creator) NewChapter Uses

func (c *Creator) NewChapter(title string) *Chapter

NewChapter creates a new chapter with the specified title as the heading.

func (*Creator) NewPage Uses

func (c *Creator) NewPage()

NewPage adds a new Page to the Creator and sets as the active Page.

func (*Creator) NewSubchapter Uses

func (c *Creator) NewSubchapter(ch *Chapter, title string) *Subchapter

NewSubchapter creates a new Subchapter under Chapter ch with specified title. All other parameters are set to their defaults.

func (*Creator) RotateDeg Uses

func (c *Creator) RotateDeg(angleDeg int64) error

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 Uses

func (c *Creator) SetForms(form *model.PdfAcroForm) error

SetForms Add Acroforms to a PDF file. Sets the specified form for writing.

func (*Creator) SetPageMargins Uses

func (c *Creator) SetPageMargins(left, right, top, bottom float64)

SetPageMargins sets the page margins: left, right, top, bottom. The default page margins are 10% of document width.

func (*Creator) SetPageSize Uses

func (c *Creator) SetPageSize(size PageSize)

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 Uses

func (c *Creator) SetPdfWriterAccessFunc(pdfWriterAccessFunc func(writer *model.PdfWriter) error)

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) Width Uses

func (c *Creator) Width() float64

Width returns the current page width.

func (*Creator) Write Uses

func (c *Creator) Write(ws io.WriteSeeker) error

Write output of creator to io.WriteSeeker interface.

func (*Creator) WriteToFile Uses

func (c *Creator) WriteToFile(outputPath string) error

WriteToFile writes the Creator output to file specified by path.

type Curve Uses

type Curve struct {
    // contains filtered or unexported fields
}

Curve represents a cubic Bezier curve with a control point.

func NewCurve Uses

func NewCurve(x1, y1, cx, cy, x2, y2 float64) *Curve

NewCurve returns new instance of Curve between points (x1,y1) and (x2, y2) with control point (cx,cy).

func (*Curve) GeneratePageBlocks Uses

func (c *Curve) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)

GeneratePageBlocks draws the curve onto page blocks.

func (*Curve) SetColor Uses

func (c *Curve) SetColor(col Color)

SetColor sets the line color.

func (*Curve) SetWidth Uses

func (c *Curve) SetWidth(width float64)

SetWidth sets line width.

type Division Uses

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 NewDivision Uses

func NewDivision() *Division

NewDivision returns a new Division container component.

func (*Division) Add Uses

func (div *Division) Add(d VectorDrawable) error

Add adds a VectorDrawable to the Division container. Currently supported VectorDrawables: *Paragraph, *StyledParagraph, *Image.

func (*Division) GeneratePageBlocks Uses

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 Uses

func (div *Division) Height() float64

Height returns the height for the Division component assuming all stacked on top of each other.

func (*Division) Inline Uses

func (div *Division) Inline() bool

Inline returns whether the inline mode of the division is active.

func (*Division) SetInline Uses

func (div *Division) SetInline(inline bool)

SetInline sets the inline mode of the division.

func (*Division) Width Uses

func (div *Division) Width() float64

Width is not used. Not used as a Division element is designed to fill into available width depending on context. Returns 0.

type DrawContext Uses

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 Uses

type Drawable interface {
    // 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 Uses

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 NewEllipse Uses

func NewEllipse(xc, yc, width, height float64) *Ellipse

NewEllipse creates a new ellipse centered at (xc,yc) with a width and height specified.

func (*Ellipse) GeneratePageBlocks Uses

func (ell *Ellipse) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)

GeneratePageBlocks draws the rectangle on a new block representing the page.

func (*Ellipse) GetCoords Uses

func (ell *Ellipse) GetCoords() (float64, float64)

GetCoords returns the coordinates of the Ellipse's center (xc,yc).

func (*Ellipse) SetBorderColor Uses

func (ell *Ellipse) SetBorderColor(col Color)

SetBorderColor sets the border color.

func (*Ellipse) SetBorderWidth Uses

func (ell *Ellipse) SetBorderWidth(bw float64)

SetBorderWidth sets the border width.

func (*Ellipse) SetFillColor Uses

func (ell *Ellipse) SetFillColor(col Color)

SetFillColor sets the fill color.

type FilledCurve Uses

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 NewFilledCurve Uses

func NewFilledCurve() *FilledCurve

NewFilledCurve returns a instance of filled curve.

func (*FilledCurve) AppendCurve Uses

func (fc *FilledCurve) AppendCurve(curve draw.CubicBezierCurve) *FilledCurve

AppendCurve appends a Bezier curve to the filled curve.

func (*FilledCurve) GeneratePageBlocks Uses

func (fc *FilledCurve) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)

GeneratePageBlocks draws the filled curve on page blocks.

func (*FilledCurve) SetBorderColor Uses

func (fc *FilledCurve) SetBorderColor(color Color)

SetBorderColor sets the border color for the path.

func (*FilledCurve) SetFillColor Uses

func (fc *FilledCurve) SetFillColor(color Color)

SetFillColor sets the fill color for the path.

type FooterFunctionArgs Uses

type FooterFunctionArgs struct {
    PageNum    int
    TotalPages int
}

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 Uses

type FrontpageFunctionArgs struct {
    PageNum    int
    TotalPages int
}

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 Uses

type HeaderFunctionArgs struct {
    PageNum    int
    TotalPages int
}

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 Image Uses

type Image struct {
    // contains filtered or unexported fields
}

The Image type is used to draw an image onto PDF.

func NewImage Uses

func NewImage(img *model.Image) (*Image, error)

NewImage create a new image from a unidoc image (model.Image).

func NewImageFromData Uses

func NewImageFromData(data []byte) (*Image, error)

NewImageFromData creates an Image from image data.

func NewImageFromFile Uses

func NewImageFromFile(path string) (*Image, error)

NewImageFromFile creates an Image from a file.

func NewImageFromGoImage Uses

func NewImageFromGoImage(goimg goimage.Image) (*Image, error)

NewImageFromGoImage creates an Image from a go image.Image datastructure.

func (*Image) GeneratePageBlocks Uses

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) GetMargins Uses

func (img *Image) GetMargins() (float64, float64, float64, float64)

GetMargins returns the Image's margins: left, right, top, bottom.

func (*Image) Height Uses

func (img *Image) Height() float64

Height returns Image's document height.

func (*Image) Scale Uses

func (img *Image) Scale(xFactor, yFactor float64)

Scale scales Image by a constant factor, both width and height.

func (*Image) ScaleToHeight Uses

func (img *Image) ScaleToHeight(h float64)

ScaleToHeight scale Image to a specified height h, maintaining the aspect ratio.

func (*Image) ScaleToWidth Uses

func (img *Image) ScaleToWidth(w float64)

ScaleToWidth scale Image to a specified width w, maintaining the aspect ratio.

func (*Image) SetAngle Uses

func (img *Image) SetAngle(angle float64)

SetAngle sets Image rotation angle in degrees.

func (*Image) SetEncoder Uses

func (img *Image) SetEncoder(encoder core.StreamEncoder)

SetEncoder sets the encoding/compression mechanism for the image.

func (*Image) SetHeight Uses

func (img *Image) SetHeight(h float64)

SetHeight sets the Image's document height to specified h.

func (*Image) SetMargins Uses

func (img *Image) SetMargins(left, right, top, bottom float64)

SetMargins sets the margins for the Image (in relative mode): left, right, top, bottom.

func (*Image) SetOpacity Uses

func (img *Image) SetOpacity(opacity float64)

SetOpacity sets opacity for Image.

func (*Image) SetPos Uses

func (img *Image) SetPos(x, y float64)

SetPos sets the absolute position. Changes object positioning to absolute.

func (*Image) SetWidth Uses

func (img *Image) SetWidth(w float64)

SetWidth set the Image's document width to specified w. This does not change the raw image data, i.e. no actual scaling of data is performed. That is handled by the PDF viewer.

func (*Image) Width Uses

func (img *Image) Width() float64

Width returns Image's document width.

type Line Uses

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 NewLine Uses

func NewLine(x1, y1, x2, y2 float64) *Line

NewLine creates a new Line with default parameters between (x1,y1) to (x2,y2).

func (*Line) GeneratePageBlocks Uses

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) GetCoords Uses

func (l *Line) GetCoords() (float64, float64, float64, float64)

GetCoords returns the (x1, y1), (x2, y2) points defining the Line.

func (*Line) Length Uses

func (l *Line) Length() float64

Length calculates and returns the line length.

func (*Line) SetColor Uses

func (l *Line) SetColor(col Color)

SetColor sets the line color. Use ColorRGBFromHex, ColorRGBFrom8bit or ColorRGBFromArithmetic to make the color object.

func (*Line) SetLineWidth Uses

func (l *Line) SetLineWidth(lw float64)

SetLineWidth sets the line width.

type PageBreak Uses

type PageBreak struct {
}

PageBreak represents a page break for a chapter.

func NewPageBreak Uses

func NewPageBreak() *PageBreak

NewPageBreak create a new page break.

func (*PageBreak) GeneratePageBlocks Uses

func (p *PageBreak) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)

GeneratePageBlocks generates a page break block.

type PageSize Uses

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 Uses

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 occupies the available width in the drawing context.

func NewParagraph Uses

func NewParagraph(text string) *Paragraph

NewParagraph create a new text paragraph. Uses default parameters: Helvetica, WinAnsiEncoding and wrap enabled with a wrap width of 100 points.

func (*Paragraph) GeneratePageBlocks Uses

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 Uses

func (p *Paragraph) GetMargins() (float64, float64, float64, float64)

GetMargins returns the Paragraph's margins: left, right, top, bottom.

func (*Paragraph) Height Uses

func (p *Paragraph) 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 (*Paragraph) SetAngle Uses

func (p *Paragraph) SetAngle(angle float64)

SetAngle sets the rotation angle of the text.

func (*Paragraph) SetColor Uses

func (p *Paragraph) SetColor(col Color)

SetColor set the color of the Paragraph text.

Example: 1. p := NewParagraph("Red paragraph")

// Set to red color with a hex code:
p.SetColor(creator.ColorRGBFromHex("#ff0000"))

2. Make Paragraph green with 8-bit rgb values (0-255 each component)

p.SetColor(creator.ColorRGBFrom8bit(0, 255, 0)

3. Make Paragraph blue with arithmetic (0-1) rgb components.

p.SetColor(creator.ColorRGBFromArithmetic(0, 0, 1.0)

func (*Paragraph) SetEnableWrap Uses

func (p *Paragraph) SetEnableWrap(enableWrap bool)

SetEnableWrap sets the line wrapping enabled flag.

func (*Paragraph) SetEncoder Uses

func (p *Paragraph) SetEncoder(encoder textencoding.TextEncoder)

SetEncoder sets the text encoding.

func (*Paragraph) SetFont Uses

func (p *Paragraph) SetFont(font fonts.Font)

SetFont sets the Paragraph's font.

func (*Paragraph) SetFontSize Uses

func (p *Paragraph) SetFontSize(fontSize float64)

SetFontSize sets the font size in document units (points).

func (*Paragraph) SetLineHeight Uses

func (p *Paragraph) SetLineHeight(lineheight float64)

SetLineHeight sets the line height (1.0 default).

func (*Paragraph) SetMargins Uses

func (p *Paragraph) SetMargins(left, right, top, bottom float64)

SetMargins sets the Paragraph's margins.

func (*Paragraph) SetPos Uses

func (p *Paragraph) SetPos(x, y float64)

SetPos sets absolute positioning with specified coordinates.

func (*Paragraph) SetText Uses

func (p *Paragraph) SetText(text string)

SetText sets the text content of the Paragraph.

func (*Paragraph) SetTextAlignment Uses

func (p *Paragraph) SetTextAlignment(align TextAlignment)

SetTextAlignment sets the horizontal alignment of the text within the space provided.

func (*Paragraph) SetWidth Uses

func (p *Paragraph) 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 (*Paragraph) Text Uses

func (p *Paragraph) Text() string

Text sets the text content of the Paragraph.

func (*Paragraph) Width Uses

func (p *Paragraph) Width() float64

Width returns the width of the Paragraph.

type Rectangle Uses

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 NewRectangle Uses

func NewRectangle(x, y, width, height float64) *Rectangle

NewRectangle creates a new Rectangle with default parameters with left corner at (x,y) and width, height as specified.

func (*Rectangle) GeneratePageBlocks Uses

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 Uses

func (rect *Rectangle) GetCoords() (float64, float64)

GetCoords returns coordinates of the Rectangle's upper left corner (x,y).

func (*Rectangle) SetBorderColor Uses

func (rect *Rectangle) SetBorderColor(col Color)

SetBorderColor sets border color.

func (*Rectangle) SetBorderWidth Uses

func (rect *Rectangle) SetBorderWidth(bw float64)

SetBorderWidth sets the border width.

func (*Rectangle) SetFillColor Uses

func (rect *Rectangle) SetFillColor(col Color)

SetFillColor sets the fill color.

type StyledParagraph Uses

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 NewStyledParagraph Uses

func NewStyledParagraph(text string, style TextStyle) *StyledParagraph

NewStyledParagraph creates a new styled paragraph. Uses default parameters: Helvetica, WinAnsiEncoding and wrap enabled with a wrap width of 100 points.

func (*StyledParagraph) Append Uses

func (p *StyledParagraph) Append(text string, style TextStyle)

Append adds a new text chunk with a specified style to the paragraph.

func (*StyledParagraph) GeneratePageBlocks Uses

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 Uses

func (p *StyledParagraph) GetMargins() (float64, float64, float64, float64)

GetMargins returns the Paragraph's margins: left, right, top, bottom.

func (*StyledParagraph) Height Uses

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) Reset Uses

func (p *StyledParagraph) Reset(text string, style TextStyle)

Reset sets the entire text and also the style of the paragraph to those specified. It behaves as if the paragraph was a new one.

func (*StyledParagraph) SetAngle Uses

func (p *StyledParagraph) SetAngle(angle float64)

SetAngle sets the rotation angle of the text.

func (*StyledParagraph) SetEnableWrap Uses

func (p *StyledParagraph) SetEnableWrap(enableWrap bool)

SetEnableWrap sets the line wrapping enabled flag.

func (*StyledParagraph) SetEncoder Uses

func (p *StyledParagraph) SetEncoder(encoder textencoding.TextEncoder)

SetEncoder sets the text encoding.

func (*StyledParagraph) SetLineHeight Uses

func (p *StyledParagraph) SetLineHeight(lineheight float64)

SetLineHeight sets the line height (1.0 default).

func (*StyledParagraph) SetMargins Uses

func (p *StyledParagraph) SetMargins(left, right, top, bottom float64)

SetMargins sets the Paragraph's margins.

func (*StyledParagraph) SetPos Uses

func (p *StyledParagraph) SetPos(x, y float64)

SetPos sets absolute positioning with specified coordinates.

func (*StyledParagraph) SetTextAlignment Uses

func (p *StyledParagraph) SetTextAlignment(align TextAlignment)

SetTextAlignment sets the horizontal alignment of the text within the space provided.

func (*StyledParagraph) SetWidth Uses

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 Uses

func (p *StyledParagraph) Width() float64

Width returns the width of the Paragraph.

type Subchapter Uses

type Subchapter struct {
    // contains filtered or unexported fields
}

Subchapter simply represents a sub chapter pertaining to a specific Chapter. It can contain multiple Drawables, just like a chapter.

func (*Subchapter) Add Uses

func (subchap *Subchapter) Add(d Drawable)

Add adds a new Drawable to the chapter. The currently supported Drawables are: *Paragraph, *Image, *Block, *Table.

func (*Subchapter) GeneratePageBlocks Uses

func (subchap *Subchapter) 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 (*Subchapter) GetHeading Uses

func (subchap *Subchapter) GetHeading() *Paragraph

GetHeading returns the Subchapter's heading Paragraph to address style (font type, size, etc).

func (*Subchapter) GetMargins Uses

func (subchap *Subchapter) GetMargins() (float64, float64, float64, float64)

GetMargins returns the Subchapter's margins: left, right, top, bottom.

func (*Subchapter) SetIncludeInTOC Uses

func (subchap *Subchapter) SetIncludeInTOC(includeInTOC bool)

SetIncludeInTOC sets a flag to indicate whether or not to include in the table of contents.

func (*Subchapter) SetMargins Uses

func (subchap *Subchapter) SetMargins(left, right, top, bottom float64)

SetMargins sets the Subchapter's margins (left, right, top, bottom). These margins are typically not needed as the Creator's page margins are used preferably.

func (*Subchapter) SetShowNumbering Uses

func (subchap *Subchapter) SetShowNumbering(show bool)

SetShowNumbering sets a flag to indicate whether or not to show chapter numbers as part of title.

type Table Uses

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 NewTable Uses

func NewTable(cols int) *Table

NewTable create a new Table with a specified number of columns.

func (*Table) CurCol Uses

func (table *Table) CurCol() int

CurCol returns the currently active cell's column number.

func (*Table) CurRow Uses

func (table *Table) CurRow() int

CurRow returns the currently active cell's row number.

func (*Table) GeneratePageBlocks Uses

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 Uses

func (table *Table) GetMargins() (float64, float64, float64, float64)

GetMargins returns the left, right, top, bottom Margins.

func (*Table) Height Uses

func (table *Table) Height() float64

Height returns the total height of all rows.

func (*Table) NewCell Uses

func (table *Table) NewCell() *TableCell

NewCell makes a new cell and inserts into the table at current position in the table.

func (*Table) SetColumnWidths Uses

func (table *Table) SetColumnWidths(widths ...float64) error

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) SetMargins Uses

func (table *Table) SetMargins(left, right, top, bottom float64)

SetMargins sets the Table's left, right, top, bottom margins.

func (*Table) SetPos Uses

func (table *Table) SetPos(x, y float64)

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 Uses

func (table *Table) SetRowHeight(row int, h float64) error

SetRowHeight sets the height for a specified row.

func (*Table) SkipCells Uses

func (table *Table) SkipCells(num int)

SkipCells skips over a specified number of cells in the table.

func (*Table) SkipOver Uses

func (table *Table) SkipOver(rows, cols int)

SkipOver skips over a specified number of rows and cols.

func (*Table) SkipRows Uses

func (table *Table) SkipRows(num int)

SkipRows skips over a specified number of rows in the table.

type TableCell Uses

type TableCell struct {
    // contains filtered or unexported fields
}

TableCell defines a table cell which can contain a Drawable as content.

func (*TableCell) SetBackgroundColor Uses

func (cell *TableCell) SetBackgroundColor(col Color)

SetBackgroundColor sets the cell's background color.

func (*TableCell) SetBorder Uses

func (cell *TableCell) SetBorder(style CellBorderStyle, width float64)

SetBorder sets the cell's border style.

func (*TableCell) SetBorderColor Uses

func (cell *TableCell) SetBorderColor(col Color)

SetBorderColor sets the cell's border color.

func (*TableCell) SetContent Uses

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 Uses

func (cell *TableCell) SetHorizontalAlignment(halign CellHorizontalAlignment)

SetHorizontalAlignment sets the cell's horizontal alignment of content. Can be one of: - CellHorizontalAlignmentLeft - CellHorizontalAlignmentCenter - CellHorizontalAlignmentRight

func (*TableCell) SetIndent Uses

func (cell *TableCell) SetIndent(indent float64)

SetIndent sets the cell's left indent.

func (*TableCell) SetVerticalAlignment Uses

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 Uses

func (cell *TableCell) Width(ctx DrawContext) float64

Width returns the cell's width based on the input draw context.

type TableOfContents Uses

type TableOfContents struct {
    // contains filtered or unexported fields
}

TableOfContents provides an overview over chapters and subchapters when creating a document with Creator.

func (*TableOfContents) Entries Uses

func (toc *TableOfContents) Entries() []TableOfContentsEntry

Entries returns the table of content entries.

type TableOfContentsEntry Uses

type TableOfContentsEntry struct {
    Title      string
    Chapter    int
    Subchapter int // 0 if chapter
    PageNumber int // Page number
}

TableOfContentsEntry defines a single entry in the TableOfContents. Each entry has a title, chapter number, sub chapter (0 if chapter) and the page number.

type TextAlignment Uses

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 Uses

type TextChunk struct {
    Text  string
    Style TextStyle
}

TextChunk represents a chunk of text along with a particular style.

type TextStyle Uses

type TextStyle struct {
    // The color of the text.
    Color Color

    // The font the text will use.
    Font fonts.Font

    // The size of the font.
    FontSize float64
}

TextStyle is a collection of properties that can be assigned to a chunk of text.

func NewTextStyle Uses

func NewTextStyle() TextStyle

NewTextStyle creates a new text style object which can be used with chunks of text. Uses default parameters: Helvetica, WinAnsiEncoding and wrap enabled with a wrap width of 100 points.

type VectorDrawable Uses

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.

Package creator imports 17 packages (graph) and is imported by 3 packages. Updated 2019-05-24. Refresh now. Tools for package owners.