Adding image to pdf not working when deployed
0xfourzerofour opened this issue · 2 comments
Description
I have a function running in a lambda that will grab a document from s3 and then add an image to the document using the NewImageFromData
function along with Creator.Draw
I have tested the function on my local machine and it works like a charm but whenever I upload it to the lambda env and run the code it will not add the image to the input pdf.
example function code (errs removed to read easier)
c := creator.New()
pdfReader, err := model.NewPdfReader(bytes.NewReader(file))
err = addImageToPdf(c, pdfReader, &body, pageNum, xPos, yPos, scaledWidth)
buf := new(bytes.Buffer)
err = c.Write(buf)
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
s3conn := s3.New(sess)
s3PutInput := s3.PutObjectInput{
Bucket: aws.String(os.Getenv("sign-bucket")),
Key: aws.String("local-pdf.pdf"),
Body: bytes.NewReader(buf.Bytes()),
}
_, err = s3conn.PutObject(&s3PutInput)
func addImageToPdf(c *creator.Creator, pdfReader *model.PdfReader, image *[]byte, pageNum int, xPos, yPos, scaledWidth float64) error {
// Prepare the image.
img, err := c.NewImageFromData(*image)
if err != nil {
return err
}
img.ScaleToWidth(scaledWidth)
img.SetPos(xPos, yPos)
if err != nil {
return err
}
numPages, err := pdfReader.GetNumPages()
if err != nil {
return err
}
// Load the pages.
for i := 0; i < numPages; i++ {
page, err := pdfReader.GetPage(i + 1)
if err != nil {
return err
}
// Add the page.
err = c.AddPage(page)
if err != nil {
return err
}
// If the specified page, or -1, apply the image to the page.
if i+1 == pageNum || pageNum == -1 {
_ = c.Draw(img)
}
}
return nil
}
I have used the exact same code in the deployed version however it does not work.
I think this may be something to do with the version as my local go version is 1.18 and the deployed version is 1.16
Attachments
Include a self-contained reproducible code snippet and PDF file that demonstrates the issue.
Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/
false alarm, I was able to fix the bug