pdfengine

package
v0.0.81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2025 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

filepath: c:\Users\Cesar\Packages\Internal\docpdf\pdfengine\pdfEngineExtra.go

Example (FormatFloatTrim)
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(10))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(10.0))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(10.01))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(10.001))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(10.0001))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(10.00001))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(9.99999))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(9.9999))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(9.999))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(9.99))
fmt.Printf("/F1 %s Tf\n", formatFloatTrim(9.9))
Output:

/F1 10 Tf
/F1 10 Tf
/F1 10.01 Tf
/F1 10.001 Tf
/F1 10 Tf
/F1 10 Tf
/F1 10 Tf
/F1 10 Tf
/F1 9.999 Tf
/F1 9.99 Tf
/F1 9.9 Tf

Index

Examples

Constants

View Source
const (
	// BreakModeStrict causes the text-line to break immediately in case the current character would not fit into
	// the processed text-line. The separator (if provided) will be attached accordingly as a line suffix
	// to stay within the defined width.
	BreakModeStrict breakMode = iota

	// BreakModeIndicatorSensitive will try to break the current line based on the last index of a provided
	// BreakIndicator. If no indicator sensitive break can be performed a strict break will be performed,
	// potentially working with the given separator as a suffix.
	BreakModeIndicatorSensitive
)
View Source
const (
	//PermissionsPrint setProtection print
	PermissionsPrint = 4
	//PermissionsModify setProtection modify
	PermissionsModify = 8
	//PermissionsCopy setProtection copy
	PermissionsCopy = 16
	//PermissionsAnnotForms setProtection  annot-forms
	PermissionsAnnotForms = 32
)

Variables

View Source
var (
	// DefaultBreakOption will cause the text to break mid-word without any separator suffixes.
	DefaultBreakOption = BreakOption{
		Mode:           BreakModeStrict,
		BreakIndicator: 0,
		Separator:      "",
	}
)

Functions

func CheckSum

func CheckSum(data []byte) uint

CheckSum check sum

func CreateContent added in v0.0.61

func CreateContent(f *ttfSubsetObj, text string, fontSize float64, charSpacing float64, rectangle *canvas.Rect) (float64, float64, float64, error)

func ImageHolderByBytes

func ImageHolderByBytes(b []byte) (imageHolder, error)

ImageHolderByBytes create imageHolder by []byte

Types

type BreakOption

type BreakOption struct {
	// Mode defines the mode which should be used
	Mode breakMode
	// BreakIndicator is taken into account when using indicator sensitive mode to avoid mid-word line breaks
	BreakIndicator rune
	// Separator will act as a suffix for mid-word breaks when using strict mode
	Separator string
}

BreakOption allows to configure the behavior of splitting or breaking larger texts via SplitTextWithOption.

func (BreakOption) HasSeparator

func (bo BreakOption) HasSeparator() bool

type CellOption

type CellOption struct {
	Align         config.Alignment //Allows to align the text. Possible values are: config.Left,config.Center,config.Right,config.Top,config.Bottom,config.Middle
	Border        config.Alignment //Indicates if borders must be drawn around the cell. Possible values are: config.Left, config.Top, config.Right, config.Bottom, ALL
	Float         config.Alignment //Indicates where the current config.Alignment should go after the call. Possible values are: config.Right, config.Bottom
	TruncateLines int              // Si > 0, limita el texto a este número de líneas y añade puntos suspensivos si es necesario

	CoefUnderlinePosition  float64
	CoefLineHeight         float64
	CoefUnderlineThickness float64
	BreakOption            *BreakOption
	// contains filtered or unexported fields
}

CellOption cell option

type Config

type Config struct {
	// Unit specifies the unit type to use when composing the document (canvas.UnitPT, canvas.UnitMM, canvas.UnitCM, canvas.UnitIN, canvas.UnitPX)
	Unit int

	// ConversionForUnit is a value used to convert units to points.
	// If this value is not 0, it will be used for unit conversion instead of the default constants.
	// When this is set, the Unit field is ignored.
	// Example: For 300 DPI, set this to 72.0/300.0
	ConversionForUnit float64

	// TrimBox defines the default trim canvas.Box for all pages in the document
	TrimBox canvas.Box

	// canvas.PageSize defines the default page size for all pages in the document
	PageSize canvas.Rect

	// K is a scaling factor (purpose not well-documented)
	K float64

	// Protection contains the settings for PDF document protection
	Protection PdfProtectionConfig
}

Config defines the basic configuration for a PDF document. It includes settings for unit types, page size, protection, and more.

func (Config) GetConversionForUnit

func (c Config) GetConversionForUnit() float64

GetConversionForUnit returns the custom conversion factor from the configuration

func (Config) GetUnit

func (c Config) GetUnit() int

GetUnit returns the unit type from the configuration

type CropOptions

type CropOptions struct {
	X      float64
	Y      float64
	Width  float64
	Height float64
}

type ICacheColorText added in v0.0.61

type ICacheColorText interface {
	ICacheContent
	Equal(obj ICacheColorText) bool
}

type ICacheContent added in v0.0.61

type ICacheContent interface {
	Write(w Writer, protection *pdfProtection) error
}

type ImageOptions

type ImageOptions struct {
	DegreeAngle    float64
	VerticalFlip   bool
	HorizontalFlip bool
	X              float64
	Y              float64
	Rect           *canvas.Rect
	Mask           *maskOptions
	Crop           *CropOptions
	// contains filtered or unexported fields
}

type JustifiedText

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

JustifiedText representa un texto justificado con sus espacios ajustados

func (*JustifiedText) Draw

func (jt *JustifiedText) Draw(gp *PdfEngine, x, y float64) error

Draw dibuja el texto justificado en las coordenadas especificadas

func (*JustifiedText) GetOriginalString

func (jt *JustifiedText) GetOriginalString() string

GetOriginalString retorna el texto original antes de ser justificado

func (*JustifiedText) GetSpaces

func (jt *JustifiedText) GetSpaces() []float64

GetSpaces retorna los espacios entre palabras del texto justificado

func (*JustifiedText) GetWidth

func (jt *JustifiedText) GetWidth() float64

GetWidth retorna el ancho total del texto justificado

func (*JustifiedText) GetWords

func (jt *JustifiedText) GetWords() []string

GetWords retorna las palabras del texto justificado

func (*JustifiedText) SpaceCount

func (jt *JustifiedText) SpaceCount() int

SpaceCount retorna el número de espacios del texto justificado

func (*JustifiedText) WordCount

func (jt *JustifiedText) WordCount() int

WordCount retorna el número de palabras del texto justificado

type PageOption

type PageOption struct {
	TrimBox  *canvas.Box
	PageSize *canvas.Rect
}

PageOption option of page

type PdfEngine

type PdfEngine struct {
	// FileWriter function for custom file writing logic
	FileWriter env.FileWriter

	Config Config

	// Number of pages obj
	NumOfPagesObj int

	// Log function for debugging
	Log func(...any)
	// contains filtered or unexported fields
}

PdfEngine : core library for generating PDF

func (gp *PdfEngine) AddExternalLink(url string, x, y, w, h float64)

AddExternalLink adds a new external link.

func (*PdfEngine) AddFontFamilyConfig added in v0.0.78

func (gp *PdfEngine) AddFontFamilyConfig(fontFamily config.FontFamily) error

AddFontFamilyConfig adds a font using config.FontFamily structure

func (*PdfEngine) AddFooter

func (gp *PdfEngine) AddFooter(f func())

AddFooter - add a footer function, if present this will be automatically called by AddPage()

func (*PdfEngine) AddHeader

func (gp *PdfEngine) AddHeader(f func())

AddHeader - add a header function, if present this will be automatically called by AddPage()

func (gp *PdfEngine) AddInternalLink(anchor string, x, y, w, h float64)

AddInternalLink adds a new internal link.

func (*PdfEngine) AddOutline

func (gp *PdfEngine) AddOutline(title string)

func (*PdfEngine) AddOutlineWithPosition

func (gp *PdfEngine) AddOutlineWithPosition(title string) *outlineObj

AddOutlineWithPosition add an outline with config.Alignment

func (*PdfEngine) AddPage

func (gp *PdfEngine) AddPage()

AddPage : add new page

func (*PdfEngine) AddPageWithOption

func (gp *PdfEngine) AddPageWithOption(opt PageOption)

AddPageWithOption : add new page with option

func (*PdfEngine) AddTTFFont

func (gp *PdfEngine) AddTTFFont(family string, ttfpath string) error

AddTTFFont : add font file - Legacy method, preserved for compatibility

func (*PdfEngine) AddTTFFontByReader

func (gp *PdfEngine) AddTTFFontByReader(family string, rd Reader) error

AddTTFFontByReader adds font file by reader.

func (*PdfEngine) AddTTFFontByReaderWithOption

func (gp *PdfEngine) AddTTFFontByReaderWithOption(family string, rd Reader, option TtfOption) error

AddTTFFontByReaderWithOption adds font file by reader with option.

func (*PdfEngine) AddTTFFontData

func (gp *PdfEngine) AddTTFFontData(family string, fontData []byte) error

AddTTFFontByReader adds font data by reader.

func (*PdfEngine) AddTTFFontDataWithOption

func (gp *PdfEngine) AddTTFFontDataWithOption(family string, fontData []byte, option TtfOption) error

AddTTFFontDataWithOption adds font data with option.

func (*PdfEngine) AddTTFFontWithOption

func (gp *PdfEngine) AddTTFFontWithOption(family string, ttfpath string, option TtfOption) error

AddTTFFontWithOption : add font file

func (*PdfEngine) AllMargins added in v0.0.61

func (gp *PdfEngine) AllMargins() (float64, float64, float64, float64)

AllMargins gets the current Margins, The Margins will be converted back to the documents units. Returned values will be in the following order Left, Top, Right, Bottom

func (*PdfEngine) Br

func (gp *PdfEngine) Br(h float64)

Br : new line

func (*PdfEngine) Cell

func (gp *PdfEngine) Cell(rectangle *canvas.Rect, text string) error

Cell : create cell of text ( use current x,y is upper-left corner of cell) Note that this has no effect on canvas.Rect.H pdf (now). Fix later :-)

func (*PdfEngine) CellWithOption

func (gp *PdfEngine) CellWithOption(rectangle *canvas.Rect, text string, opt CellOption) error

CellWithOption create cell of text ( use current x,y is upper-left corner of cell)

func (*PdfEngine) ClearTransparency

func (gp *PdfEngine) ClearTransparency()

func (*PdfEngine) Close

func (gp *PdfEngine) Close() error

Close clears the gopdf buffer.

func (*PdfEngine) CurrentPdf added in v0.0.61

func (gp *PdfEngine) CurrentPdf() *currentPdf

metodo que retorna currentPdf

func (*PdfEngine) Curve

func (gp *PdfEngine) Curve(x0 float64, y0 float64, x1 float64, y1 float64, x2 float64, y2 float64, x3 float64, y3 float64, style string)

Curve Draws a Bézier curve (the Bézier curve is tangent to the line between the control points at either end of the curve) Parameters: - x0, y0: Start point - x1, y1: Control point 1 - x2, y2: Control point 2 - x3, y3: End point - style: Style of rectangule (draw and/or fill: D, F, DF, FD)

func (*PdfEngine) DrawImageByHolder

func (gp *PdfEngine) DrawImageByHolder(img imageHolder, x float64, y float64, rect *canvas.Rect) error

DrawImageByHolder : draw image by imageHolder

func (*PdfEngine) DrawImageInPdf added in v0.0.61

func (gp *PdfEngine) DrawImageInPdf(imageContent []byte, x float64, y float64, rect *canvas.Rect) error

DrawImageInPdf : draw image in pdf by image content

func (*PdfEngine) FillInPlaceHoldText

func (gp *PdfEngine) FillInPlaceHoldText(placeHolderName string, text string, align config.Alignment) error

[experimental] fill in text that created by function PlaceHolderText align: config.Left,config.Right,config.Center

func (*PdfEngine) GetAnchors

func (gp *PdfEngine) GetAnchors() map[string]anchorOption

metodo que retorna anchors

func (*PdfEngine) GetBuf

func (gp *PdfEngine) GetBuf() *bytes.Buffer

GetBuf returns the buffer

func (*PdfEngine) GetBytesPdf

func (gp *PdfEngine) GetBytesPdf() []byte

GetBytesPdf : get bytes of pdf file

func (*PdfEngine) GetBytesPdfReturnErr

func (gp *PdfEngine) GetBytesPdfReturnErr() ([]byte, error)

GetBytesPdfReturnErr : get bytes of pdf file

func (*PdfEngine) GetEncryptionObjID

func (gp *PdfEngine) GetEncryptionObjID() int

GetEncryptionObjID returns the encryption object ID

func (*PdfEngine) GetIndexEncodingObjFonts

func (gp *PdfEngine) GetIndexEncodingObjFonts() []int

GetIndexEncodingObjFonts returns the index encoding object fonts

func (*PdfEngine) GetIndexOfContent

func (gp *PdfEngine) GetIndexOfContent() int

GetIndexOfContent returns the index of content

func (*PdfEngine) GetInfo

func (gp *PdfEngine) GetInfo() *PdfInfo

GetInfo get Document Information Dictionary

func (*PdfEngine) GetNextObjectID

func (gp *PdfEngine) GetNextObjectID() int

GetNextObjectID gets the next object ID so that gofpdi knows where to start the object IDs.

func (*PdfEngine) GetNumberOfPages

func (gp *PdfEngine) GetNumberOfPages() int

GetNumberOfPages gets the number of pages from the PDF.

func (*PdfEngine) GetPageSize added in v0.0.74

func (gp *PdfEngine) GetPageSize() *canvas.Rect

metodo que obteine la estrucutua tamaño de la pagina

func (*PdfEngine) GetPdfObjs

func (gp *PdfEngine) GetPdfObjs() []iObj

metodo que retorna iObjs

func (*PdfEngine) GetPdfProtection

func (gp *PdfEngine) GetPdfProtection() *pdfProtection

metodo que retorna el objeto de proteccion

func (*PdfEngine) GetX

func (gp *PdfEngine) GetX() float64

GetX : get current config.Alignment X

func (*PdfEngine) GetY

func (gp *PdfEngine) GetY() float64

GetY : get current config.Alignment y

func (*PdfEngine) ImageByHolderWithOptions

func (gp *PdfEngine) ImageByHolderWithOptions(img imageHolder, opts ImageOptions) error

func (*PdfEngine) ImageFrom

func (gp *PdfEngine) ImageFrom(img image.Image, x float64, y float64, rect *canvas.Rect) error

func (*PdfEngine) ImageFromWithOption

func (gp *PdfEngine) ImageFromWithOption(img image.Image, opts imageFromOption) error

func (*PdfEngine) ImportObjects

func (gp *PdfEngine) ImportObjects(objs map[int]string, startObjID int)

ImportObjects imports objects from gofpdi into current document.

func (*PdfEngine) ImportPage

func (gp *PdfEngine) ImportPage(sourceFile string, pageno int, Box string) int

ImportPage imports a page and return template id. gofpdi code

func (*PdfEngine) ImportPageStream

func (gp *PdfEngine) ImportPageStream(sourceStream *io.ReadSeeker, pageno int, Box string) int

ImportPageStream imports page using a stream. Return template id after importing. gofpdi code

func (*PdfEngine) ImportPagesFromSource

func (gp *PdfEngine) ImportPagesFromSource(source any, Box string) error

ImportPagesFromSource imports pages from a source pdf. The source can be a file path, byte slice, or (*)io.ReadSeeker.

func (*PdfEngine) ImportTemplates

func (gp *PdfEngine) ImportTemplates(tpls map[string]int)

ImportTemplates names into procset dictionary.

func (*PdfEngine) Init added in v0.0.61

func (gp *PdfEngine) Init(importer ...*importer)

init

func (*PdfEngine) IsCurrFontContainGlyph

func (gp *PdfEngine) IsCurrFontContainGlyph(r rune) (bool, error)

IsCurrFontContainGlyph defines is current font contains to a glyph r: any rune

func (*PdfEngine) IsFitMultiCell

func (gp *PdfEngine) IsFitMultiCell(rectangle *canvas.Rect, text string) (bool, float64, error)

IsFitMultiCell : check whether the rectangle's area is big enough for the text

func (*PdfEngine) IsFitMultiCellWithNewline

func (gp *PdfEngine) IsFitMultiCellWithNewline(rectangle *canvas.Rect, text string) (bool, float64, error)

IsFitMultiCellWithNewline : similar to IsFitMultiCell, but process char newline as Br

func (*PdfEngine) KernOverride

func (gp *PdfEngine) KernOverride(family string, fn funcKernOverride) error

KernOverride override kern value

func (*PdfEngine) Line

func (gp *PdfEngine) Line(x1 float64, y1 float64, x2 float64, y2 float64)

Line : draw line

Usage:
pdf.SetTransparency(docpdf.transparency{Alpha: 0.5,blendModeType: docpdf.colorBurn})
pdf.SetLineType("dotted")
pdf.SetStrokeColor(255, 0, 0)
pdf.SetLineWidth(2)
pdf.Line(10, 30, 585, 30)
pdf.ClearTransparency()

func (*PdfEngine) MarginBottom

func (gp *PdfEngine) MarginBottom() float64

MarginBottom returns the bottom margin.

func (*PdfEngine) MarginLeft

func (gp *PdfEngine) MarginLeft() float64

MarginLeft returns the left margin.

func (*PdfEngine) MarginRight

func (gp *PdfEngine) MarginRight() float64

MarginRight returns the right margin.

func (*PdfEngine) MarginTop

func (gp *PdfEngine) MarginTop() float64

MarginTop returns the top margin.

func (*PdfEngine) Margins

func (gp *PdfEngine) Margins() canvas.Margins

func (*PdfEngine) MeasureCellHeightByText

func (gp *PdfEngine) MeasureCellHeightByText(text string) (float64, error)

MeasureCellHeightByText : measure Height of cell by text (use current font)

func (*PdfEngine) MeasureTextWidth

func (gp *PdfEngine) MeasureTextWidth(text string) (float64, error)

MeasureTextWidth : measure Width of text (use current font)

func (*PdfEngine) MultiCell

func (gp *PdfEngine) MultiCell(rectangle *canvas.Rect, text string) error

MultiCell : create of text with line breaks (use current x,y is upper-left corner of cell)

func (*PdfEngine) MultiCellJustified

func (gp *PdfEngine) MultiCellJustified(rectangle *canvas.Rect, text string) error

MultiCellJustified dibuja texto justificado dentro de un rectángulo

func (*PdfEngine) MultiCellWithOption

func (gp *PdfEngine) MultiCellWithOption(rectangle *canvas.Rect, text string, opt CellOption) error

MultiCellWithOption create of text with line breaks (use current x,y is upper-left corner of cell)

func (*PdfEngine) Oval

func (gp *PdfEngine) Oval(x1 float64, y1 float64, x2 float64, y2 float64)

Oval : draw oval

func (*PdfEngine) ParseTextForJustification

func (gp *PdfEngine) ParseTextForJustification(text string, width float64) (*JustifiedText, error)

ParseTextForJustification divide un texto en sus palabras y calcula los espacios necesarios

func (*PdfEngine) PlaceHolderText

func (gp *PdfEngine) PlaceHolderText(placeHolderName string, placeHolderWidth float64) error

[experimental] PlaceHolderText Create a text placehold for fillin text later with function FillInPlaceHoldText.

func (*PdfEngine) PointsToUnitsVar added in v0.0.61

func (gp *PdfEngine) PointsToUnitsVar(u ...*float64)

PointsToUnitsVar converts the points to the documents unit type for all variables passed in

func (*PdfEngine) Polygon

func (gp *PdfEngine) Polygon(points []point, style string)

Polygon : draw polygon

  • style: Style of polygon (draw and/or fill: D, F, DF, FD) D or empty string: draw. This is the default value. F: fill DF or FD: draw and fill

Usage:

 pdf.SetStrokeColor(255, 0, 0)
	pdf.SetLineWidth(2)
	pdf.SetFillColor(0, 255, 0)
	pdf.Polygon([]docpdf.point{{X: 10, Y: 30}, {X: 585, Y: 200}, {X: 585, Y: 250}}, "DF")

func (*PdfEngine) Read

func (gp *PdfEngine) Read(p []byte) (int, error)

func (*PdfEngine) RectFromLowerLeft

func (gp *PdfEngine) RectFromLowerLeft(x float64, y float64, wdth float64, hght float64)

RectFromLowerLeft : draw rectangle from lower-left corner (x, y)

func (*PdfEngine) RectFromLowerLeftWithOpts

func (gp *PdfEngine) RectFromLowerLeftWithOpts(opts drawableRectOptions) error

func (*PdfEngine) RectFromLowerLeftWithStyle

func (gp *PdfEngine) RectFromLowerLeftWithStyle(x float64, y float64, wdth float64, hght float64, style string)

RectFromLowerLeftWithStyle : draw rectangle from lower-left corner (x, y)

  • style: Style of rectangule (draw and/or fill: D, F, DF, FD) D or empty string: draw. This is the default value. F: fill DF or FD: draw and fill

func (*PdfEngine) RectFromUpperLeft

func (gp *PdfEngine) RectFromUpperLeft(x float64, y float64, wdth float64, hght float64)

RectFromUpperLeft : draw rectangle from upper-left corner (x, y)

func (*PdfEngine) RectFromUpperLeftWithOpts

func (gp *PdfEngine) RectFromUpperLeftWithOpts(opts drawableRectOptions) error

func (*PdfEngine) RectFromUpperLeftWithStyle

func (gp *PdfEngine) RectFromUpperLeftWithStyle(x float64, y float64, wdth float64, hght float64, style string)

RectFromUpperLeftWithStyle : draw rectangle from upper-left corner (x, y)

  • style: Style of rectangule (draw and/or fill: D, F, DF, FD) D or empty string: draw. This is the default value. F: fill DF or FD: draw and fill

func (*PdfEngine) Rectangle

func (gp *PdfEngine) Rectangle(x0 float64, y0 float64, x1 float64, y1 float64, style string, radius float64, radiusPointNum int) error

Rectangle : draw rectangle, and add radius input to make a round corner, it helps to calculate the round corner coordinates and use Polygon functions to draw rectangle

  • style: Style of Rectangle (draw and/or fill: D, F, DF, FD) D or empty string: draw. This is the default value. F: fill DF or FD: draw and fill

Usage:

 pdf.SetStrokeColor(255, 0, 0)
	pdf.SetLineWidth(2)
	pdf.SetFillColor(0, 255, 0)
	pdf.Rectangle(196.6, 336.8, 398.3, 379.3, "DF", 3, 10)

func (*PdfEngine) Rotate

func (gp *PdfEngine) Rotate(angle, x, y float64)

Rotate rotate text or image angle is angle in degrees. x, y is rotation center

func (*PdfEngine) RotateReset

func (gp *PdfEngine) RotateReset()

RotateReset reset rotate

func (*PdfEngine) SetAnchor

func (gp *PdfEngine) SetAnchor(name string)

SetAnchor creates a new anchor.

func (*PdfEngine) SetCharSpacing

func (gp *PdfEngine) SetCharSpacing(charSpacing float64) error

SetCharSpacing : set the character spacing of the currently active font

func (*PdfEngine) SetCompressLevel

func (gp *PdfEngine) SetCompressLevel(level int)

SetCompressLevel : set compress Level for content streams Possible values for level:

-2 HuffmanOnly, -1 DefaultCompression (which is level 6)
 0 No compression,
 1 fastest compression, but not very good ratio
 9 best compression, but slowest

func (*PdfEngine) SetCustomLineType

func (gp *PdfEngine) SetCustomLineType(dashArray []float64, dashPhase float64)

SetCustomLineType : set custom line type

Usage:
pdf.SetCustomLineType([]float64{0.8, 0.8}, 0)
pdf.Line(50, 200, 550, 200)

func (*PdfEngine) SetFileWriter

func (gp *PdfEngine) SetFileWriter(writer env.FileWriter)

SetFileWriter sets a custom function for writing PDF files

func (*PdfEngine) SetFillColor

func (gp *PdfEngine) SetFillColor(r uint8, g uint8, b uint8)

SetFillColor set the color for the stroke

func (*PdfEngine) SetFillColorCMYK

func (gp *PdfEngine) SetFillColorCMYK(c, m, y, k uint8)

SetFillColorCMYK set the color for the fill in CMYK color mode

func (*PdfEngine) SetFont

func (gp *PdfEngine) SetFont(cfs config.FontStyle) error

SetFont

func (*PdfEngine) SetFontSize

func (gp *PdfEngine) SetFontSize(fontSize float64) error

SetFontSize : set the font size (and only the font size) of the currently active font

func (*PdfEngine) SetFontWithStyle

func (gp *PdfEngine) SetFontWithStyle(updatedStyle config.FontStyle) error

SetFontWithStyle

func (*PdfEngine) SetGrayFill

func (gp *PdfEngine) SetGrayFill(grayScale float64)

SetGrayFill set the grayscale for the fill, takes a float64 between 0.0 and 1.0

func (*PdfEngine) SetGrayStroke

func (gp *PdfEngine) SetGrayStroke(grayScale float64)

SetGrayStroke set the grayscale for the stroke, takes a float64 between 0.0 and 1.0

func (*PdfEngine) SetIndexOfProcSet

func (gp *PdfEngine) SetIndexOfProcSet(index int)

metodo para setar IndexOfProcSet

func (*PdfEngine) SetInfo

func (gp *PdfEngine) SetInfo(info PdfInfo)

SetInfo set Document Information Dictionary

func (*PdfEngine) SetLeftMargin

func (gp *PdfEngine) SetLeftMargin(margin float64)

SetLeftMargin sets left margin.

func (*PdfEngine) SetLineType

func (gp *PdfEngine) SetLineType(linetype string)

SetLineType : set line type ("dashed" ,"dotted")

Usage:
pdf.SetLineType("dashed")
pdf.Line(50, 200, 550, 200)
pdf.SetLineType("dotted")
pdf.Line(50, 400, 550, 400)

func (*PdfEngine) SetLineWidth

func (gp *PdfEngine) SetLineWidth(width float64)

SetLineWidth : set line width

func (*PdfEngine) SetMarginBottom

func (gp *PdfEngine) SetMarginBottom(margin float64)

SetMarginBottom set the bottom margin

func (*PdfEngine) SetMarginLeft

func (gp *PdfEngine) SetMarginLeft(margin float64)

SetMarginLeft sets the left margin

func (*PdfEngine) SetMarginRight

func (gp *PdfEngine) SetMarginRight(margin float64)

SetMarginRight sets the right margin

func (*PdfEngine) SetMarginTop

func (gp *PdfEngine) SetMarginTop(margin float64)

SetMarginTop sets the top margin

func (*PdfEngine) SetMargins

func (gp *PdfEngine) SetMargins(left, top, right, bottom float64)

SetMargins defines the left, top, right and bottom canvas.Margins. By default, they equal 1 cm. Call this method to change them.

func (*PdfEngine) SetNewXY

func (gp *PdfEngine) SetNewXY(y float64, x, h float64)

SetNewXY : set current config.Alignment x and y, and modified y if add a new page. Example: For example, if the page height is set to 841px, MarginTop is 20px, MarginBottom is 10px, and the height of the element to be inserted is 25px, because 10<25, you need to add another page and set y to 20px. Because of AddPage(), X is set to MarginLeft, so you should specify X if needed, or make sure SetX() is after SetNewY().

func (*PdfEngine) SetNewY

func (gp *PdfEngine) SetNewY(y float64, h float64)

SetNewY : set current config.Alignment y, and modified y if add a new page. Example: For example, if the page height is set to 841px, MarginTop is 20px, MarginBottom is 10px, and the height of the element(such as text) to be inserted is 25px, because 10<25, you need to add another page and set y to 20px. Because of called AddPage(), X is set to MarginLeft, so you should specify X if needed, or make sure SetX() is after SetNewY(), or using SetNewXY(). SetNewYIfNoOffset is more suitable for scenarios where the offset does not change, such as pdf.Image().

func (*PdfEngine) SetNewYIfNoOffset

func (gp *PdfEngine) SetNewYIfNoOffset(y float64, h float64)

SetNewYIfNoOffset : set current config.Alignment y, and modified y if add a new page. Example: For example, if the page height is set to 841px, MarginTop is 20px, MarginBottom is 10px, and the height of the element(such as image) to be inserted is 200px, because 10<200, you need to add another page and set y to 20px. Tips: gp.curr.X and gp.curr.Y do not change when pdf.Image() is called.

func (*PdfEngine) SetNoCompression

func (gp *PdfEngine) SetNoCompression()

SetNoCompression : compressLevel = 0

func (*PdfEngine) SetPage

func (gp *PdfEngine) SetPage(pageno int) error

SetPage set current page

func (*PdfEngine) SetStrokeColor

func (gp *PdfEngine) SetStrokeColor(r uint8, g uint8, b uint8)

SetStrokeColor set the color for the stroke

func (*PdfEngine) SetStrokeColorCMYK

func (gp *PdfEngine) SetStrokeColorCMYK(c, m, y, k uint8)

SetStrokeColorCMYK set the color for the stroke in CMYK color mode

func (*PdfEngine) SetTextColor

func (gp *PdfEngine) SetTextColor(r uint8, g uint8, b uint8)

SetTextColor : function sets the text color

func (*PdfEngine) SetTextColorCMYK

func (gp *PdfEngine) SetTextColorCMYK(c, m, y, k uint8)

func (*PdfEngine) SetTopMargin

func (gp *PdfEngine) SetTopMargin(margin float64)

SetTopMargin sets top margin.

func (*PdfEngine) SetTransparency

func (gp *PdfEngine) SetTransparency(transparency transparency) error

SetTransparency sets transparency. alpha: value from 0 (transparent) to 1 (opaque) blendMode: blend mode, one of the following:

Normal, multiply, screen, overlay, darken, lighten, colorDodge, colorBurn,
hardLight, softLight, difference, exclusion, hue, saturation, Color, luminosity

func (*PdfEngine) SetX

func (gp *PdfEngine) SetX(x float64)

SetX : set current config.Alignment X

func (*PdfEngine) SetXY

func (gp *PdfEngine) SetXY(x, y float64)

SetXY : set current config.Alignment x and y

func (*PdfEngine) SetY

func (gp *PdfEngine) SetY(y float64)

SetY : set current config.Alignment y

func (*PdfEngine) SplitText

func (gp *PdfEngine) SplitText(text string, width float64) ([]string, error)

SplitText splits text into multiple lines based on width performing potential mid-word breaks.

func (*PdfEngine) SplitTextWithOption

func (gp *PdfEngine) SplitTextWithOption(text string, width float64, opt *BreakOption) ([]string, error)

SplitTextWithOption splits a text into multiple lines based on the current font size of the document. BreakOptions allow to define the behavior of the split (strict or sensitive). For more information see BreakOption.

func (*PdfEngine) SplitTextWithWordWrap

func (gp *PdfEngine) SplitTextWithWordWrap(text string, width float64) ([]string, error)

SplitTextWithWordWrap behaves the same way SplitText does but performs a word-wrap considering spaces in case a text line split would split a word.

func (*PdfEngine) Start

func (gp *PdfEngine) Start(Config Config)

Start : init gopdf

func (*PdfEngine) StartWithImporter

func (gp *PdfEngine) StartWithImporter(Config Config, importer *importer)

func (*PdfEngine) Text

func (gp *PdfEngine) Text(text string) error

Text write text start at current x,y ( current y is the baseline of text )

func (*PdfEngine) UnitsToPoints

func (gp *PdfEngine) UnitsToPoints(u float64) float64

UnitsToPoints converts the units to the documents unit type

func (*PdfEngine) UnitsToPointsVar

func (gp *PdfEngine) UnitsToPointsVar(u ...*float64)

UnitsToPointsVar converts the units to the documents unit type for all variables passed in

func (*PdfEngine) UseImportedTemplate

func (gp *PdfEngine) UseImportedTemplate(tplid int, x float64, y float64, w float64, h float64)

UseImportedTemplate draws an imported PDF page.

func (*PdfEngine) Write deprecated

func (gp *PdfEngine) Write(w Writer) error

Write streams the pdf as it is compiled to an Writer

Deprecated: use the WritePdf method instead.

func (*PdfEngine) WritePdf

func (gp *PdfEngine) WritePdf(pdfPath string) error

WritePdf writes the PDF file to the specified path using the configured FileWriter

func (*PdfEngine) WriteTo

func (gp *PdfEngine) WriteTo(w Writer) (n int64, err error)

WritePdf implements the io.WriterTo interface and can be used to stream the PDF as it is compiled to an Writer.

type PdfInfo

type PdfInfo struct {
	Title        string    // The document’s title
	Author       string    // The name of the person who created the document
	Subject      string    // The subject of the document
	Creator      string    // If the document was converted to PDF from another format, the name of the application which created the original document
	Producer     string    // If the document was converted to PDF from another format, the name of the application that converted the original document to PDF
	CreationDate time.Time // The date and time the document was created, in human-readable form
}

PdfInfo Document Information Dictionary

type PdfProtectionConfig

type PdfProtectionConfig struct {
	// UseProtection determines whether to apply protection to the PDF
	UseProtection bool

	// Permissions specifies the allowed operations on the PDF (PermissionsPrint, PermissionsCopy, etc.)
	Permissions int

	// UserPass is the password required for general users to open the PDF
	UserPass []byte

	// OwnerPass is the password required for owners to remove restrictions
	OwnerPass []byte
}

PdfProtectionConfig defines the configuration for PDF document protection.

type Reader added in v0.0.66

type Reader interface {
	Read(p []byte) (n int, err error)
}

type TtfOption

type TtfOption struct {
	UseKerning                bool
	Style                     config.FontStyle  //Regular|Bold|Italic
	OnGlyphNotFound           func(r rune)      //Called when a glyph cannot be found, just for debugging
	OnGlyphNotFoundSubstitute func(r rune) rune //Called when a glyph cannot be found, we can return a new rune to replace it.
}

TtfOption font option

type Writer added in v0.0.61

type Writer interface {
	Write(p []byte) (n int, err error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL