Skip to content

Commit

Permalink
Allow using custom importer
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedkamalio committed Feb 4, 2024
1 parent 99a04cd commit 7052c93
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions gopdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,20 @@ func (gp *GoPdf) AddFooter(f func()) {
// Start : init gopdf
func (gp *GoPdf) Start(config Config) {

gp.start(config)

}

func (gp *GoPdf) StartWithImporter(config Config, importer *gofpdi.Importer) {

gp.start(config, importer)

}

func (gp *GoPdf) start(config Config, importer ...*gofpdi.Importer) {

gp.config = config
gp.init()
gp.init(importer...)
//สร้าง obj พื้นฐาน
catalog := new(CatalogObj)
catalog.init(func() *GoPdf {
Expand Down Expand Up @@ -1890,7 +1902,7 @@ func (gp *GoPdf) Rectangle(x0 float64, y0 float64, x1 float64, y1 float64, style
/*---private---*/

// init
func (gp *GoPdf) init() {
func (gp *GoPdf) init(importer ...*gofpdi.Importer) {
gp.pdfObjs = []IObj{}
gp.buf = bytes.Buffer{}
gp.indexEncodingObjFonts = []int{}
Expand Down Expand Up @@ -1938,10 +1950,17 @@ func (gp *GoPdf) init() {
gp.config.TrimBox = *gp.config.TrimBox.UnitsToPoints(gp.config.Unit)

// init gofpdi free pdf document importer
gp.fpdi = gofpdi.NewImporter()
gp.fpdi = importerOrDefault(importer...)

}

func importerOrDefault(importer ...*gofpdi.Importer) *gofpdi.Importer {
if len(importer) != 0 {
return importer[len(importer)-1]
}
return gofpdi.NewImporter()
}

func (gp *GoPdf) resetCurrXY() {
gp.curr.X = gp.margins.Left
gp.curr.Y = gp.margins.Top
Expand Down

0 comments on commit 7052c93

Please sign in to comment.