MS PPT export flext to Java

Flex code :

public function exportBitmap(comp:DisplayObject):void {

var bd:BitmapData = new BitmapData(comp.width,

comp.height);

//render the chart to the BitmapData

bd.draw(comp);

saveImagesID.SaveImages(bd.getPixels(bd.rect),

bd.width, bd.height);

}

Remote Object

Java code

import java.util.*;

import java.sql.*;

import java.lang.Integer;

import java.text.DecimalFormat;

import java.io.FileInputStream;

import java.io.*;

import java.text.*;

import java.awt.Color;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import java.awt.*;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;

import java.awt.Dimension;

import org.apache.poi.hslf.usermodel.SlideShow;

import org.apache.poi.hslf.model.Slide;

import org.apache.poi.hslf.model.Fill;

import org.apache.poi.hslf.model.Picture;

import org.apache.poi.hslf.model.TextBox;

//import org.apache.commons.codec.binary.Base64;

import org.apache.poi.hslf.HSLFSlideShow;

public class SaveImg

{

public DBConnection dbCon;

public Connection c;

public Vector columnTypeCategorical;

public Vector columnTypeNumeric;

public String strCatFields=””;

public String strNumFields=””;

public SlideShow ppt;

public Slide slide;

public Fill fill;

public int idx;

public FileOutputStream out;

public static Vector vcFileName = new Vector();

public int i=0;

public static Vector vcBytes = new Vector();

public void ConnectDatabase()

{

dbCon = new DBConnection();

dbCon.ConnectDB();

c = dbCon.conn;

}

/**

@param -Query String

@return -array List

*/

public void SaveImages(byte[] bd, int width, int height)

{

i++;

/*BufferedImage image = new BufferedImage(width, height,

BufferedImage.TYPE_INT_RGB);

//loop through all the pixels

for (int y=0; y<height; y++) {

for (int x=0; x<width; x++) {

//calculate array offset

int o = (x*4)+(y*width*4);

//set the pixel color

//here we will need to convert

//the byte data to an unsigned

//value using &0xFF before passing

//it to the Color constructor

image.setRGB(x, y, new Color(

bd[o+1]&0xFF, //red

bd[o+2]&0xFF, //green

bd[o+3]&0xFF //blue

).getRGB());

}

}

*/

try{

//write the image to a file

byte[] bds = createBytes( bd, width, height);

createSlideWithChart( bds);

//vcBytes.add(bds);

/*if(i<=3){

ImageWriter img = new ImageWriter();

ImageGrabber gbs = new ImageGrabber();

}*/

}catch(Exception e){};

}

private static byte[] createBytes(byte[] bd, int width, int height) throws IOException {

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

Graphics2D g = (Graphics2D) image.getGraphics();

for (int y=0; y<height; y++) {

for (int x=0; x<width; x++) {

//calculate array offset

int o = (x*4)+(y*width*4);

//set the pixel color

//here we will need to convert

//the byte data to an unsigned

//value using &0xFF before passing

//it to the Color constructor

image.setRGB(x, y, new Color(

bd[o+1]&0xFF, //red

bd[o+2]&0xFF, //green

bd[o+3]&0xFF //blue

).getRGB());

}

}

ByteArrayOutputStream baos = new ByteArrayOutputStream();

ImageIO.write(image, "PNG", baos);

byte[] data = baos.toByteArray();

return data;

}

public void createSlideWithChart(byte[] bd )

{

try

{

if(i==1)

{

String tomcatDir = System.getProperty("catalina.home");

File f = new File(tomcatDir+"/webapps/PPT/");

String path = tomcatDir+"/webapps/PPT";

out = new FileOutputStream(path+"/Dashboard.ppt");

ppt = new SlideShow();

ppt.setPageSize(new Dimension(600,600));

}

slide = ppt.createSlide();

slide.setFollowMasterBackground(false);

fill = slide.getBackground().getFill();

fill.setFillType(Fill.FILL_PICTURE);

idx = ppt.addPicture(bd, Picture.PNG);

fill.setPictureData(idx);

if(i==72){

ppt.write(out);

out.close();

i=0;

}

}catch(FileNotFoundException fnfe){}

catch(IOException ioe){}

}

public static byte[] toBytes(Object object){

java.io.ByteArrayOutputStream baos = new

java.io.ByteArrayOutputStream();

try{

java.io.ObjectOutputStream oos = new

java.io.ObjectOutputStream(baos);

oos.writeObject(object);

}catch(java.io.IOException ioe){

}

return baos.toByteArray();

}

}

About ashokabhat

I am a C,C ,JAVA,Adobe Flex,.NET Programmer Currently working as a Software Developer
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s