unipdf icon indicating copy to clipboard operation
unipdf copied to clipboard

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

Open Mahendershah opened this issue 3 years ago • 3 comments

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

Mahendershah avatar Mar 22 '21 03:03 Mahendershah

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/

github-actions[bot] avatar Mar 22 '21 03:03 github-actions[bot]

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

Mahendershah avatar Mar 22 '21 04:03 Mahendershah

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

gunnsth avatar Aug 01 '21 00:08 gunnsth