Arrsoya / jmupdf

Automatically exported from code.google.com/p/jmupdf
1 stars 0 forks source link

How to set a fixed width (or height) when converting to an image? #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
does anyone can help?
I see I can only set the zoom value, but what if I need to have a fixed width 
JPG/PNG conversion?

pix = new PagePixels(page);
pix.setZoom(1f);

Can it be done on the drawPage method?

pix.drawPage(null, pix.getX0(), pix.getY0(), pix.getX1(), pix.getY1());

If so can you give an example?

Many thanks!

Original issue reported on code.google.com by giuseppe...@gmail.com on 18 Mar 2014 at 4:17

GoogleCodeExporter commented 9 years ago
Hi there, just thought I Would share this with you. This is what I do. :

float w = "my width" ; < enter your figures here.
float h = "my height";

            Float scale = 1f;

            float sh = page.getHeight();
            float sw = page.getWidth();
            if (w > 0)
                scale = w / sw;
            else
                scale = h / sh;

            int rotate = Page.PAGE_ROTATE_AUTO;
            ImageType color = ImageType.IMAGE_TYPE_ARGB;

            PageRenderer render = new PageRenderer(page, scale, rotate, color);
            render.setAntiAliasLevel(antiAliasLevel);
            render.setZoom(scale);
            render.render(true);
            img = render.getImage();
            render.dispose();

ps. zoom is in there twice cos on version 5 zoom does not work on PageRenderer 
line at the moment.

Anyway hope this helps

Original comment by terry.cl...@gmail.com on 7 Apr 2014 at 10:29

GoogleCodeExporter commented 9 years ago
Yup...that's the way to do it!  Also the PageRendereer issue should be fixed 
now. I updated the Jar files.

Thanks!

Original comment by pedro.ri...@gmail.com on 9 Apr 2014 at 1:53