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

gofpdi import from stream changes the first page of the pdf #56

Open
SahaPratik6267 opened this issue Aug 13, 2022 · 1 comment
Open

Comments

@SahaPratik6267
Copy link

SahaPratik6267 commented Aug 13, 2022

Below is my code for pdf importer. I am trying to merge 2 pdf as 1. In this case, rsbp is one pdf and rsinv is another one. the system should be that first page of the pdf will have the content of rsbp and then rest of the pdf is rsinv. When i run this code i see the second page rsinv is ok but first page (where it should have the content of rsbp),has the content of the first page of rsinv.

now if i change it to inport page and manually input 2 files then everything works great(problem happens when converted to stream).

IF i remove the loop part then the outputpdf has the content of rsbp which is correct.

Not what is the issue here.

pdf := gofpdf.New("P", "mm", "A4", "")

w, h := m.GetPageSize()
imp1 := gofpdi.NewImporter()
rsbp := io.ReadSeeker(bytes.NewReader(pdfm.Bytes()))
tpl1 := imp1.ImportPageFromStream(pdf, &rsbp, 1, "/MediaBox")
pdf.AddPage()
imp1.UseImportedTemplate(pdf, tpl1, 0, 0, w, h)
rsinv := io.ReadSeeker(bytes.NewReader(bikepass.Invoicebyte))
tpl1 = imp1.ImportPageFromStream(pdf, &rsinv, 1, "/MediaBox")
nrPages := len(imp1.GetPageSizes())

for i := 1; i <= nrPages; i++ {
	pdf.AddPage()
	if i > 1 {
		tpl1 = imp1.ImportPageFromStream(pdf, &rsinv, i, "/MediaBox")
	}		
	imp1.UseImportedTemplate(pdf, tpl1, 0, 0, w, h)		
}
err := pdf.OutputFileAndClose("pdfs/example.pdf")
if err != nil {
	fmt.Errorf("error in generating the output pdf file: %w", err)
}
@SahaPratik6267
Copy link
Author

I just checked the system. If i pass the second pdf as a file with importpage function then all is good. My guess is that it can not work with 2 pdf stream.

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

1 participant