0

I need to convert docx file to an image page by page. So if I Pass page number to a method - that method should read that page out of docx file and convert that to an image. Any example of that using Apache POI API ? I did that for pptx file but was not able to find similar methods for docx. Following is the code for pptx.

        FileInputStream is = new FileInputStream(strTempPath);
        XMLSlideShow pptx = new XMLSlideShow(is);
        is.close();
        double zoom = 2; // magnify it by 2
        AffineTransform at = new AffineTransform();
        at.setToScale(zoom, zoom);
        Dimension pgsize = pptx.getPageSize();             
        XSLFSlide[] slide = pptx.getSlides();

        }              
        // BufferedImage img = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_INT_RGB);
        BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = img.createGraphics();
        //graphics.setTransform(at);                
        graphics.setPaint(Color.white);
        graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
        slide[iPageNo].draw(graphics);             
        // FileOutputStream output = new ByteArrayOutputStream("C:/Temp/aspose/word/slide-" + (10 + 1) + ".png");        
        output = new ByteArrayOutputStream();
        javax.imageio.ImageIO.write(img, "png", output);
Johnny000
  • 2,058
  • 5
  • 30
  • 59
user2565431
  • 49
  • 2
  • 10
  • You have used this path in your code "C:/Temp/aspose/word/slide-". If you use Aspose.Words then it can convert each page of docx to png. – Saqib Razzaq Sep 04 '13 at 14:15

1 Answers1

1

Unlike a presentation which has a natural notion of a page, there is no page as such in the WordML format.

It is up to consuming applications to create a page layout model if they need it (which is what Microsoft Word does).

What you can do with docx4j (which you've tagged your question with), is output using FOP, to, say PNG.

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84