poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From atawfik <contact.txl...@gmail.com>
Subject Re: How to import complex shaps Using POI XMLSlideShow
Date Sun, 01 Feb 2015 07:17:37 GMT
Thanks Andi for your reply. 

My scenario is that i need to create presentations out of slides from
various presentations. In a typical case, I create a new presentation and
keep importing slides content to it using
XMLSlideShow.createSlide().importContent. This method works fine in simple
slides, but if i have slides  like the second slide in the attached
presentation, I get empty slides. 

I tested merging around 8 presentation files with around 450 slides. 100 of
450 slides were empty (25%). These empty slides are not coming from all
presentations. Therefore, it is a serious problem for our application.

I do not think the problem is drawing the slides because i successfully
exported these slides into thumbnails without any problem. Below is the code
to do that?

public class MergeSlideTest {
	public static void main(String[] args) {
		File srcDir = new File("/usr/home/ameer/ test.pptx
<http://apache-poi.1045710.n5.nabble.com/file/n5717802/test.pptx>  slides");

		
		String[] files = {"test.pptx"};

		for (String file : files) {
			try {
				FileInputStream fis = new FileInputStream(new File(srcDir,file));

				XMLSlideShow srcSlideShow = new XMLSlideShow(fis);

				XSLFSlide[] slides = srcSlideShow.getSlides();
				XMLSlideShow destSlideShow = new XMLSlideShow();
				for (int i = 0; i < slides.length; i++) {
					try {
						takeSnapshot(slides[i]);
						destSlideShow.createSlide().importContent(slides[i]);
					} catch (Exception e) {
						System.out.println("Problem in exporting " + (i + 1)
								+ " from " + file);
						e.printStackTrace();
					}
				}
				fis.close();
				FileOutputStream fos;
				try {
					fos = new FileOutputStream(new File("copy-"+file));
					destSlideShow.write(fos);
					fos.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
				
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		
		
	}
	
	public static void takeSnapshot(XSLFSlide slide){
		BufferedImage img = new BufferedImage(600, 600,
BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = img.createGraphics();
        //clear the drawing area
        graphics.setPaint(Color.white);
        graphics.fill(new Rectangle2D.Float(0, 0, 600, 600));

      
		try {
			  //render
	        slide.draw(graphics);
	        //save the output
	        FileOutputStream out = new FileOutputStream(new
File("slide-thumbnail.png"));
			javax.imageio.ImageIO.write(img, "png", out);
			out.close();		  
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-import-complex-shaps-Using-POI-XMLSlideShow-tp5717798p5717802.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message