Android PdfDocument.Page - Problems with image size

前端 未结 4 1333
闹比i
闹比i 2021-02-14 17:50

I am experiencing problems with images being larger when drawing onto a PdfDocument.Page. The app is targeted for a device running Android 4.4.4 (API level 19).

I am gen

4条回答
  •  醉话见心
    2021-02-14 18:18

    This is a late answer, but a have been dealing with the same problem, and found the solution, with an explanation.

    The explanation:

    PdfDocument.Page size units, Postscript points which are 1/72 inch.

    This means, that the PdfDocument uses points that measure 1/72th of an inch when physically printed, which is equal to say that in the printed document, there will be 72 points in 1 inch. This is also known as 72 DPI (Dots Per Inch).

    So, with 72 DPI, if you wanted to see the document in your screen at the same exact size of the document printed (with no zoom ofc), you would need 72 pixels per inch (PPI)

    Unlike pictures, PDF files have physical size, so the Canvas of the PdfDocument.Page can be understood as the "screen" where you are printing your document. This "screen" MUST have a density of 72 PPI for the content to be represented as the original.

    The solution:

    There is no need for logo.setDensity(DisplayMetrics.DENSITY_XHIGH); because you dont want to change the scale of the image, you need to specify the density of the canvas.

    Solution is canvas.setDensity(72);

提交回复
热议问题