Question

I am writing a pdf viewer in Qt and C++ using Poppler. How can I render a pdf page to fit my widget size? Poppler provides a method named renderToImage which takes in a dpi and returns a QImage whose size varies with that dpi. How to calculate the right dpi?

Was it helpful?

Solution

pageSizeF() returns the page size in points, which divided by 72 gives you the page size in inches.

Each component of your widget size in pixels divided by each component of the size in inches gives you 2 dpi values (1 for each axis).

If you want to keep the page aspect ratio, you should pass the smaller of these two dpi values to renderToImage for both xres and yres parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top