I wanted to convert some images to pdf So in order to do that, I need to make pages for the image first I will have to provide the width and height of the page and put the image on the page, The problem is that the resolution of some images is greater than the other so the pdf does not get formed on a constant scale.
I need to make the page's scale constant without changing the resolution.
some image resolution which I tried
4160 × 3120, 720 × 1560, 466 × 400, 577 × 360, 492 × 144, 554 × 554,
I tried using this code
double ratio = (float) bitmap.getWidth() / (float) bitmap.getHeight();
double bestDelta = Double.MAX_VALUE;
int bestI = 0;
int bestJ = 0;
for (int i = 1; i < 100; i++)
{
for (int j = 1; j < 100; j++)
{
double newDelta = Math.abs ((double) i / (double) j - ratio);
if (newDelta < bestDelta)
{
bestDelta = newDelta;
bestI = i;
bestJ = j;
}
}
}
pageInfo = new PdfDocument.PageInfo.Builder(bestI, bestJ, page_no).create();
and getting the ratios but still some resolution give bigger values at some resolutions(here 466 × 400) which generates some bigger images