如何将所有PowerPoint幻灯片转换为JPEG格式?

时间:2013-06-10 05:34:48

标签: java android

我正在使用Android应用程序转换JPEG格式的电源点幻灯片。我已经在文本视图中从SD卡上传了PowerPoint文件,并且还成功地计算了他们的幻灯片。但是当我转换JPEG格式的所有幻灯片时,它在Saaspose Sdk的Document类中显示Error。

这是我的Document类:

public class Document {
    public Document(String fileName) 
    {
        this.fileName = fileName;
        gson = new Gson();
    }

public String fileName="";
    Gson gson = null;

public int getSlideCount() {
        try {
            // build URI to get slide count

            String strURI = Product.getBaseProductUri() + "/slides/" + fileName + "/slides";
            String signedURI = Utils.sign(strURI);

            InputStream responseStream = Utils.processCommand(signedURI,"GET");

            String strJSON = Utils.streamToString(responseStream);

            SlidesResponse slidesResponse = gson.fromJson(strJSON,SlidesResponse.class);
            int count = slidesResponse.getSlides().getSlideList().size();
            return count;
        }

        catch (Exception e)
        {

            logger.error(e.getMessage());
            return -1;
        }

    }


public void saveSlideAs(String outputPath, int slideNumber,
            ImageFormat imageFormat)// Returns 100x100 image
    {

        try {

            // build URI to get page count
            String strURI = Product.getBaseProductUri() + "/slides/" + fileName
                    + "/slides/" + Integer.toString(slideNumber) + "?format="
                    + imageFormat.toString().toLowerCase();

            String signedURI = Utils.sign(strURI);

            InputStream responseStream = Utils.processCommand(signedURI, "GET");

            Folder.saveStreamToFile(outputPath,
                    responseStream);



            responseStream.close();

}

        catch (Exception e) {
            logger.error(e.getMessage());
        }
    }
}

这是我的StorageFolderUploadFile类

protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.storage_folder_uploadfile);
        init();

btnSubmit.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View arg0)
            {
                // TODO Auto-generated method stub
                if (function_arg1.getText().length() == 0)
                {
                    AlertDialog.Builder dialog = new AlertDialog.Builder(StorageFolderUploadFile.this);
                    dialog.setTitle("Error");
                    dialog.setMessage("Please Enter Require Fields");
                    dialog.setNeutralButton("Ok", null);
                    dialog.show();
                } 

                else

                {
                    System.out.println("*******************");

                    fileName = function_arg1.getText().toString();
                    Log.e("fileName ","-> " + fileName);

                    String[] afterSplit = fileName.split("/");
                    Log.e("String[] ","afterSplit -> " + afterSplit);

                    String mntString=afterSplit[1];
                    Log.e("mntString "," afterSplit -> " + mntString);

                    String sdCardString=afterSplit[2];
                    Log.e("adCardString "," afterSplit -> " + sdCardString);

                    String fileMainName=afterSplit[3];
                    Log.e("fileName "," afterSplit -> " + fileMainName);

                    txtFileNameForSlideCount.setText(fileMainName);

                    System.out.println("********************");


                    //folderName = function_arg2.getText().toString();
                    //folderName="tazeen";

                    Folder obj = new Folder();
                    try 
                    {
                        response = obj.uploadFile(fileName);

                        Log.e("",""+response);

                        if (response) 
                        {
                            result.append("File Uploaded Successfully " );

                            Document docObj1=new Document(txtFileNameForSlideCount.getText().toString());
                            countSlides=docObj1.getSlideCount();
                            Log.e("contSildes is","-> "+countSlides);

                            if(countSlides>0)
                            {
                                result.append(" Numbers Of Slides = " + countSlides);
                                Log.e("File Uploaded Successfully and ","Numbers Of Slides -> " + countSlides);

                            }


                            Document docObj2=new Document(fileMainName);
                            for(int i=1; i <= countSlides ; i++)
                            {

                                /*System.out.println("________________________________________");
                                String strformatName="Slide.png";
                                docObj2.saveSlideAs(strformatName,countSlides,imageFormat);
                                result.append("slide is converted and save to your sdcard");
                                System.out.println("Slides name and number " + strformatName +" "+countSlides);
                                Log.e("Document Object ","-> " + docObj2);*/


                                outputPath = "slide"+i+".png";
                                slideNumber = i;

                                docObj2.saveSlideAs(outputPath, slideNumber, imageFormat);
                                result.append("slide is converted and save to your sdcard");
                            }

                        } 

                        else 
                        {
                            result.append("Oops..Something went wrong");

                        }
                    } 

                    catch (Exception e)

                    {
                        // TODO Auto-generated catch block
                        Toast.makeText(StorageFolderUploadFile.this,
                                "Error occured while performing this task",
                                Toast.LENGTH_LONG).show();
                        result.append("Error Occured");

                    }
                }
            }
        });

    }
}   

0 个答案:

没有答案