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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top