fpdi

package
v0.0.0-...-5d8e3e1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: BSD-3-Clause, MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPageSizes

func GetPageSizes() map[int]map[string]map[string]float64

GetPageSizes returns page dimensions for all pages of the imported pdf. Result consists of map[<page number>]map[<box>]map[<dimension>]<value>. <page number>: page number, note that page numbers start at 1 <box>: box identifier, e.g. "/MediaBox" <dimension>: dimension string, either "w" or "h" Note: This uses the default Importer. Call NewImporter() to obtain a custom Importer.

func ImportPage

func ImportPage(f fpdiPdf, sourceFile string, pageno int, box string) int

ImportPage imports a page of a PDF file with the specified box (/MediaBox, /TrimBox, /ArtBox, /CropBox, or /BleedBox). Returns a template id that can be used with UseImportedTemplate to draw the template onto the page. Note: This uses the default Importer. Call NewImporter() to obtain a custom Importer.

func ImportPageFromStream

func ImportPageFromStream(f fpdiPdf, rs *io.ReadSeeker, pageno int, box string) int

ImportPageFromStream imports a page of a PDF with the specified box (/MediaBox, TrimBox, /ArtBox, /CropBox, or /BleedBox). Returns a template id that can be used with UseImportedTemplate to draw the template onto the page. Note: This uses the default Importer. Call NewImporter() to obtain a custom Importer.

func UseImportedTemplate

func UseImportedTemplate(f fpdiPdf, tplid int, x float64, y float64, w float64, h float64)

UseImportedTemplate draws the template onto the page at x,y. If w is 0, the template will be scaled to fit based on h. If h is 0, the template will be scaled to fit based on w. Note: This uses the default Importer. Call NewImporter() to obtain a custom Importer.

Types

type Importer

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

Importer wraps an Importer from the fpdi library.

func NewImporter

func NewImporter() *Importer

NewImporter creates a new Importer wrapping functionality from the fpdi library.

Example
// create new pdf
pdf := fpdf.New("P", "pt", "A4", "")

// for testing purposes, get an arbitrary template pdf as stream
rs, _ := getTemplatePdf()

// create a new Importer instance
imp := NewImporter()

// import first page and determine page sizes
tpl := imp.ImportPageFromStream(pdf, &rs, 1, "/MediaBox")
pageSizes := imp.GetPageSizes()
nrPages := len(imp.GetPageSizes())

// add all pages from template pdf
for i := 1; i <= nrPages; i++ {
	pdf.AddPage()
	if i > 1 {
		tpl = imp.ImportPageFromStream(pdf, &rs, i, "/MediaBox")
	}
	imp.UseImportedTemplate(pdf, tpl, 0, 0, pageSizes[i]["/MediaBox"]["w"], pageSizes[i]["/MediaBox"]["h"])
}

// output
fileStr := example.Filename("contrib_fpdi_Importer")
err := pdf.OutputFileAndClose(fileStr)
example.Summary(err, fileStr)
Output:

Successfully generated ../../pdf/contrib_fpdi_Importer.pdf

func (*Importer) GetPageSizes

func (i *Importer) GetPageSizes() map[int]map[string]map[string]float64

GetPageSizes returns page dimensions for all pages of the imported pdf. Result consists of map[<page number>]map[<box>]map[<dimension>]<value>. <page number>: page number, note that page numbers start at 1 <box>: box identifier, e.g. "/MediaBox" <dimension>: dimension string, either "w" or "h"

func (*Importer) ImportPage

func (i *Importer) ImportPage(f fpdiPdf, sourceFile string, pageno int, box string) int

ImportPage imports a page of a PDF file with the specified box (/MediaBox, /TrimBox, /ArtBox, /CropBox, or /BleedBox). Returns a template id that can be used with UseImportedTemplate to draw the template onto the page.

func (*Importer) ImportPageFromStream

func (i *Importer) ImportPageFromStream(f fpdiPdf, rs *io.ReadSeeker, pageno int, box string) int

ImportPageFromStream imports a page of a PDF with the specified box (/MediaBox, TrimBox, /ArtBox, /CropBox, or /BleedBox). Returns a template id that can be used with UseImportedTemplate to draw the template onto the page.

func (*Importer) UseImportedTemplate

func (i *Importer) UseImportedTemplate(f fpdiPdf, tplid int, x float64, y float64, w float64, h float64)

UseImportedTemplate draws the template onto the page at x,y. If w is 0, the template will be scaled to fit based on h. If h is 0, the template will be scaled to fit based on w.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳