Skip to content

Commit

Permalink
feat: Remove ImportPagesFromFile
Browse files Browse the repository at this point in the history
  • Loading branch information
liasica committed Oct 17, 2024
1 parent 85230af commit 996989b
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions gopdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1574,59 +1574,6 @@ func (gp *GoPdf) UseImportedTemplate(tplid int, x float64, y float64, w float64,
gp.getContent().AppendStreamImportedTemplate(tplName, scaleX, scaleY, tX, tY)
}

// ImportPagesFromFile imports pages from a source file.
func (gp *GoPdf) ImportPagesFromFile(sourceFile string, box string) error {
// Set source file for fpdi
gp.fpdi.SetSourceFile(sourceFile)

// Get number of pages from source file
pages := gp.fpdi.GetNumPages()

// Get page sizes from source file
sizes := gp.fpdi.GetPageSizes()

for i := 0; i < pages; i++ {
pageno := i + 1

// Get the size of the page
size, ok := sizes[pageno][box]
if !ok {
return errors.New("can not get page size")
}

// Add a new page to the document
gp.AddPage()

// gofpdi needs to know where to start the object id at.
// By default, it starts at 1, but gopdf adds a few objects initially.
startObjID := gp.GetNextObjectID()

// Set gofpdi next object ID to whatever the value of startObjID is
gp.fpdi.SetNextObjectID(startObjID)

// Import page
tpl := gp.fpdi.ImportPage(pageno, box)

// Import objects into current pdf document
tplObjIDs := gp.fpdi.PutFormXobjects()

// Set template names and ids in gopdf
gp.ImportTemplates(tplObjIDs)

// Get a map[int]string of the imported objects.
// The map keys will be the ID of each object.
imported := gp.fpdi.GetImportedObjects()

// Import gofpdi objects into gopdf, starting at whatever the value of startObjID is
gp.ImportObjects(imported, startObjID)

// Draws the imported template on the current page
gp.UseImportedTemplate(tpl, 0, 0, size["w"], size["h"])
}

return nil
}

// ImportPagesFromSource imports pages from a source pdf.
// The source can be a file path, byte slice, or (*)io.ReadSeeker.
func (gp *GoPdf) ImportPagesFromSource(source interface{}, box string) error {
Expand Down

0 comments on commit 996989b

Please sign in to comment.