Documentation
¶
Overview ¶
filepath: c:\Users\Cesar\Packages\Internal\docpdf\docChart.go
Index ¶
- Constants
- type Document
- func (d *Document) AddFootnote(text string) *docText
- func (d *Document) AddHeader1(text string) *docText
- func (d *Document) AddHeader2(text string) *docText
- func (d *Document) AddHeader3(text string) *docText
- func (doc *Document) AddImage(imagePathOrContent any) *docImage
- func (d *Document) AddJustifiedText(text string) *docText
- func (doc *Document) AddPage()
- func (d *Document) AddPageFooter(text string) *docText
- func (d *Document) AddPageHeader(text string) *docText
- func (doc *Document) AddPageWithOption(opt pdfengine.PageOption)
- func (d *Document) AddText(text string) *docText
- func (doc *Document) Chart() *docCharts
- func (doc *Document) EnsureElementFits(height float64, minBottomMargin ...float64) float64
- func (doc *Document) GetLineHeight() float64
- func (doc *Document) NewStyledCell(content string, style config.Cell) styledCell
- func (doc *Document) NewTable(headers ...string) *docTable
- func (doc *Document) RedrawHeaderFooter()
- func (d *Document) SetPageFooter() *headerFooter
- func (d *Document) SetPageHeader() *headerFooter
- func (d *Document) SpaceBefore(spaces ...float64)
Constants ¶
const ( FontRegular = "regular" FontBold = "bold" FontItalic = "italic" )
FontStyle defines the available font styles
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Document ¶
func NewDocument ¶
NewDocument creates a new PDF document with configurable settings Accepts optional configurations:
Optional configurations include:
- config.TextStyles: Custom text styles for different sections
- config.FontFamily: Custom font family
- canvas.Margins: Custom canvas.Margins in millimeters (more intuitive than points)
- canvas.PageSize: Custom page size with desired units
- *canvas.Rect: Predefined page size (like PageSizeLetter, canvas.PageSizeA4, etc.)
- func(string, []byte) error: Custom file writer function (if not provided, defaults to env.SetupDefaultFileWriter())
Examples:
- NewDocument() // Uses default file writer
- NewDocument(os.WriteFile) // Custom file writer
- NewDocument(canvas.Margins{config.Left: 15, config.Top: 10, config.Right: 10, config.Bottom: 10})
- NewDocument(canvas.PageSize{Width: 210, Height: 297, Unit: canvas.UnitMM}) // A4 size in mm
- NewDocument(canvas.PageSizeA4) // Using predefined page size
- NewDocument(os.WriteFile, canvas.PageSizeA4, canvas.Margins{config.Left: 20, config.Top: 10, config.Right: 20, config.Bottom: 10})
For web applications:
- NewDocument(func(filename string, data []byte) error { response.Header().Set("Content-Type", "application/pdf") _, err := response.Write(data) return err })
func (*Document) AddFootnote ¶
AddFootnote crea una nota al pie
func (*Document) AddHeader1 ¶
AddHeader1 crea un encabezado nivel 1
func (*Document) AddHeader2 ¶
AddHeader2 crea un encabezado nivel 2
func (*Document) AddHeader3 ¶
AddHeader3 crea un encabezado nivel 3
func (*Document) AddImage ¶
AddImage creates a new image element in the document supporting both absolute and relative paths or image data in []byte format eg: doc.AddImage("path/to/image.png") or doc.AddImage([]byte{...})
func (*Document) AddJustifiedText ¶
AddJustifiedText crea texto justificado directamente
func (*Document) AddPage ¶
func (doc *Document) AddPage()
AddPage añade una nueva página y actualiza el contador de páginas para el header y footer
func (*Document) AddPageFooter ¶
AddPageFooter adds a footer to the document (legacy method for backward compatibility)
func (*Document) AddPageHeader ¶
AddPageHeader adds a header to the document (legacy method for backward compatibility)
func (*Document) AddPageWithOption ¶
func (doc *Document) AddPageWithOption(opt pdfengine.PageOption)
AddPageWithOption añade una nueva página con opciones y actualiza el contador de páginas para el header y footer
func (*Document) Chart ¶ added in v0.0.48
func (doc *Document) Chart() *docCharts
Chart es el punto de entrada para la API de gráficos
func (*Document) EnsureElementFits ¶ added in v0.0.61
EnsureElementFits checks if an element with the specified height will fit on the current page. If it doesn't fit, it adds a new page and returns the new Y config.Alignment. Parameters:
- height: height of the element in document units
- minBottomMargin: optional minimum margin to leave at bottom of page
Returns:
- positionY: the Y config.Alignment where the element should be drawn
- newPageAdded: true if a new page was added
func (*Document) GetLineHeight ¶
GetLineHeight returns the current line height based on the active font and size
func (*Document) NewStyledCell ¶
NewStyledCell creates a new cell with custom styling
func (*Document) NewTable ¶
NewTable creates a new table with the specified headers Headers can include formatting options in the following format.
Format: "headerTitle|option1,option2,option3,..."
Available options:
- Header alignment: "HL" (left), "HC" (center, default), "HR" (right)
- Column alignment: "CL" (left, default), "CC" (center), "CR" (right)
- Prefix/Suffix: "P:value" (adds prefix), "S:value" (adds suffix)
- Width: "W:number" (fixed width), "W:number%" (percentage width) Note: If width is not specified, auto width is used by default
Examples:
- "Name" - Normal header, left-aligned column, auto width
- "Price|HR,CR" - config.Right-aligned header, right-aligned column
- "Price|HR,CR,P:$" - config.Right-aligned header, right-aligned column with "$" prefix
- "Percentage|HC,CC,S:%" - config.Center-aligned header, center-aligned column with "%" suffix
- "Name|HL,CL,W:30%" - config.Left-aligned header, left-aligned column with 30% of available width
- "Age|HC,CR,W:20" - config.Center-aligned header, right-aligned column with fixed width of 20 units
func (*Document) RedrawHeaderFooter ¶
func (doc *Document) RedrawHeaderFooter()
RedrawHeaderFooter fuerza el redibujado del encabezado y pie de página en la página actual
func (*Document) SetPageFooter ¶
func (d *Document) SetPageFooter() *headerFooter
SetPageFooter sets the document footer
func (*Document) SetPageHeader ¶
func (d *Document) SetPageHeader() *headerFooter
SetPageHeader sets the document header
func (*Document) SpaceBefore ¶
SpaceBefore adds vertical space (in font spaces) example: SpaceBefore(2) adds 2 spaces before the text
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package config contains configuration structures for docpdf.
|
Package config contains configuration structures for docpdf. |
The freetype package provides a convenient API to draw text onto an image.
|
The freetype package provides a convenient API to draw text onto an image. |
raster
Package raster provides an anti-aliasing 2-D rasterizer.
|
Package raster provides an anti-aliasing 2-D rasterizer. |
truetype
Package truetype provides a parser for the TTF and TTC file formats.
|
Package truetype provides a parser for the TTF and TTC file formats. |
filepath: c:\Users\Cesar\Packages\Internal\docpdf\pdfengine\pdfEngineExtra.go
|
filepath: c:\Users\Cesar\Packages\Internal\docpdf\pdfengine\pdfEngineExtra.go |