-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to import more than one file #59
Comments
Until this is merged into this repository you can use the fixed fork over at https://github.com/chaintraced/gofpdi, just be sure to copy over this file to your repo https://github.com/phpdave11/gofpdf/blob/master/contrib/gofpdi/gofpdi.go but with the import changed to |
@johan-lejdung any example how to use your fork ? |
Copy in the file https://github.com/phpdave11/gofpdf/blob/master/contrib/gofpdi/gofpdi.go and point the import This is the start of the /*
Package gofpdi wraps the gofpdi PDF library to import existing PDFs as templates. See github.com/phpdave11/gofpdi
for further information and examples.
Users should call NewImporter() to obtain their own Importer instance to work with.
To retain backwards compatibility, the package offers a default Importer that may be used via global functions. Note
however that use of the default Importer is not thread safe.
ChainTraced NOTE: We're using this file copied from the https://github.com/phpdave11/gofpdf/blob/master/contrib/gofpdi/gofpdi.go
while we wait for our fix detailed here https://github.com/phpdave11/gofpdi/issues/59 to be merged (https://github.com/phpdave11/gofpdi/pull/60).
*/
package pdfgen
import (
"io"
realgofpdi "github.com/chaintraced/gofpdi"
)
// gofpdiPdf is a partial interface that only implements the functions we need
// from the PDF generator to put the imported PDF templates on the PDF.
type gofpdiPdf interface {
ImportObjects(objs map[string][]byte)
ImportObjPos(objs map[string]map[int]string)
ImportTemplates(tpls map[string]string)
UseImportedTemplate(tplName string, x float64, y float64, w float64, h float64)
SetError(err error)
}
// Importer wraps an Importer from the gofpdi library.
type Importer struct {
fpdi *realgofpdi.Importer
}
..... After that you import the package where you chose to save the file and use it as you normally would :) |
how to use your library. can you give an example? @johan-lejdung |
after doing the steps you've provided, it gives me blank pages |
Hello, I'm not sure why that happens. I have the wrapper file in a package then I've use the wrapped file for importing files for a project we had. Then just use it as the ...
importer := NewImporter()
rs := io.ReadSeeker(bytes.NewReader(attachment.Bytes))
tplID := importer.ImportPageFromStream(pdf, &rs, 1, "/MediaBox")
pageSizes := importer.GetPageSizes()
... Also it seems my PR were merged finally (but no new release was made), so maybe you can use the latest git commit from this repo and get around the need for a wrapper file. |
If I try to import more than one file the last file imported will be used instead of all other files. This is because the same hash is generated for both files, similarly to what is reported here: #33, as mentioned v1.0.12...v1.0.13 seemed to solve it, but not when importing from a stream.
Other issues that seem related:
sample code:
similar hashes:
In this case
i = 1
in both instances of the loop, andthis.r.sourcefile = ''
.Conclusion:
It seems the code is written to differentiate between filenames, and although each stream is assigned a unique
this.sourceFile
it is not used in any of the readers of writers. I found that by just setting that name it started working for me.I'll open up a pull request and hopefully this can get merged.
The text was updated successfully, but these errors were encountered: