unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.48k stars 250 forks source link

The Image size is altering when trying to Print 300 DPI in PDF #449

Open Mahendershah opened 3 years ago

Mahendershah commented 3 years ago

Description

We have a image that is fixed size and is in 300 DPI. We want to add that image in the PDF. On doing so when we add the image in the PDF using Unidoc unipdf, the image overall size is reducing.

Expected Behavior

Since the size of the image and DPI is fixed i.e. DPI is 300 the size of the image in the output PDF should be of the same size as provided

Actual Behavior

Steps to reproduce the behavior:


pageSize := creator.PageSize{creator.PageSizeA4[0], creator.PageSizeA4[1]} c.SetPageSize(pageSize) c.NewPage() img, err := getImage(c, imgPath, 22.2, 18.8, 80.35) _ = c.Draw(img) c.SetOptimizer(optimize.New(optimize.Options{ ImageQuality: 300, ImageUpperPPI: 300, }))

err = c.WriteToFile(outputPath)

The above bold text shows how we are specifying the Optimizer to create 300 DPI image.


func getImage(c creator.Creator, imgPath string, x float64, y float64, w float64) (creator.Image, error) { img, err := c.NewImageFromFile(imgPath) if err != nil { common.Log.Debug("Error loading image: %v", err) return nil, err }

//var xx = float64(300 * 1.0 / 25.4)
new_x := x * creator.PPMM
new_y := y * creator.PPMM
new_w := w * creator.PPMM
img.ScaleToWidth(new_w)
img.SetPos(new_x, new_y)
return img, nil

}

Attachments

None

github-actions[bot] commented 3 years ago

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/

Mahendershah commented 3 years ago

I am working for a company and we are having the license for use in commercial product.

gunnsth commented 2 years ago

Hi @Mahendershah I do not recall seeing this reported in our service desk? Was it filed there, and has this been resolved? Would be good to close. There was a fix related to image optimization with PPI settings in the newest release https://github.com/unidoc/unipdf/releases/tag/v3.27.0