Skip to content
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

Problem import page #33

Closed
balsamic-r opened this issue May 1, 2020 · 8 comments
Closed

Problem import page #33

balsamic-r opened this issue May 1, 2020 · 8 comments

Comments

@balsamic-r
Copy link

balsamic-r commented May 1, 2020

Hello i'm having problems with ImportPage

The code

 documents := [...]string{"146654.pdf", "141368.pdf", "146654.pdf"}
 pdf := gofpdf.New("P", "mm", "A4", "")

	

 for _, document := range documents {
  pdf.AddPage()
  gofpdi.UseImportedTemplate(pdf, gofpdi.ImportPage(pdf, document, 1, "/MediaBox"), 0, 0, 210, 297)
  
}

 err = pdf.OutputFileAndClose("example.pdf")
  if err != nil {
     panic(err)
  }	

the result is a 3-page PDF but each page is the first page of document "146654.pdf"

Sorry for my English

@phpdave11
Copy link
Owner

I don't see where articolo is defined. Please provide a full snippet of code that I can compile and run as well as the 3 PDFs in question.

@balsamic-r
Copy link
Author

sorry, I updated the code

@phpdave11
Copy link
Owner

Please also attach the 3 PDFs: "146654.pdf", "141368.pdf", "146654.pdf"

@balsamic-r
Copy link
Author

141368.pdf
146654.pdf

@wdrai
Copy link

wdrai commented May 27, 2020

Same problem when importing 2 pdf from 2 different streams.
I have tried with a single importer for both streams or with 2 different importers, inside the same target pdf.

@wdrai
Copy link

wdrai commented May 27, 2020

Seems in the case of streams the PdfReader created in NewPdfReaderFromStream does not have a sourceFile set, then the hashes generated by shaOfInt() are the same for all objects of all documents, thus the last one imported wins.

I could make it work either with :
parser := &PdfReader{f: rs, nBytes: length, sourceFile: fmt.Sprintf("%p", rs)} in NewPdfReaderFromStream(), but this assumes rs is a pointer
or with :
hasher.Write([]byte(fmt.Sprintf("%s-%s-%s", this.tpl_id_offset, i, this.r.sourceFile))) in shaToInt()

@ghiewa
Copy link

ghiewa commented May 27, 2020

@wdrai possible paste code you mentioned above, sorry, i didn't fint it but

func (this *PdfWriter) shaOfInt(i int) string { hasher := sha1.New() hasher.Write([]byte(fmt.Sprintf("%s-%s-%s", this.tpl_id_offset, i, this.r.sourceFile))) sha := hex.EncodeToString(hasher.Sum(nil)) return sha }

but didn't help

@phpdave11
Copy link
Owner

@Zer0-Day this has been fixed in gofpdi v1.0.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants