Generating ppt slides

Dear Anupam,

You should keep track of parent slide and the number of children slides needed.

For example, if your parent slide position is m and it has n children then you can start inserting children slides from position m+1 till m+1+n

for(int i=m+1; i<=m+n+1; i++)
{
Slide sld=pres.addEmptySlide(); //get the reference of the new child slide
//do work on this child slide
}

Hi Shakeel,



Is the Slide class serializable?? For the above problem my approach was
to serialize the Presentation and Slide objects and pass them to the
java program. As the parent data can have any number of children I
thought to create a slide outside the java program and pass it into the
method after serializing it. But it throws an error saying



java.io.NotSerializableException: com.aspose.slides.Slide

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)

at java.util.HashMap.writeObject(HashMap.java:985)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)

at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)

at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)





Any alternative for this?



Regards,

Anupam


As the exception says, Slide class is not serializable. You will have to find out some other way to handle your problem, like keeping/passing the reference to presentation object and required slide number position for doing your work on it.

Hi Shakeel,



I am still facing a problem… Please see my approach. I have a jsp where the code is as follows…



Presentation present = new Presentation();

Slide slide = null;

Object [] saSlide = new Slide [childScorecardMaplist.size()];

for (int i=0; i<childScorecardMaplist.size(); i++)

{

slide = present.addEmptySlide();

slide = present.getSlideByPosition(i) ;

saSlide [i] = (Object)JPO.invoke(context,

“GEDFRPPTGenerationJPO”, null, “generateDynamicReport”, args,
Object.class);

//System.out.println(">>>>object

[i]>>>"+object [i]);

}


In the above code depending on the size of the map
(childScorecardMaplist) I am invoking my java program
“GEDFRPPTGenerationJPO” recursively which returns a slide object and I
am trying to store it into an Object array.



Now what I want is, I want to pass the reference of the
Slide object returned by the java program into a new Presentation and
go on appending it with new slide references returned by the program
and at the end write it into a file. Can you please help me into this?
Is the above approach correct?



Regards,

Anupam


If your new program runs inside the your current process space, then create new presentation and new slide with all of your work there and then return the presentation as a java.io.BufferedOutputStream. Then create new presentation from this stream and clone the slide from the presentation to your target presentation.

In case, if your program runs outside your current process space, then you will have to save the new presentation on disk and then read it back from disk in your present code.

Hopefully you are getting me.

What I am saying is that although, you cannot serialize slide, but you can serialize the presentation using Presentation.write method into stream. Then you can create the replica of your presentation in your present code from that stream and clone your slide from replica presentation to your target/final presentation.

e.g

//cloning the slide at nth position of target Presentation from replica Presentation

replicaPres.cloneSlide(replicaPres.getSlideByPosition(1), nthPosition,targetPres, new TreeMap());

Hi Shakeel,

This is what I have done

Presentation present = new Presentation();

com.get.GEDFRPPTGenerationJPO report = new GEDFRPPTGenerationJPO();
report.generateDynamicReport(context, args, present); //args will contain parent id first

for (int i = 0; i < childScorecardMaplist.size(); i++) {
    Map mObject = (Map) childScorecardMaplist.get(i);
    args[0] = (String) mObject.get("id");
    report.generateDynamicReport(context, args, present); //now args will contain child scorecard id
}

present.getSlides().removeAt(0);
FileOutputStream fostream = new FileOutputStream("C:/Demo.ppt");

//Writing the presentation as a PPT file
present.write(fostream);
fostream.close();

I declaring a presentation object at first and passing the reference into the method
generateDynamicReport. Then for the number of data objects in the map, I am calling the same method and going on appending the slides in the presentation and at last I am writing it into a file “Demo.ppt”. This approach is working fine but again it has other problem. If the number of slides are more than 10 then the program runs out of memory and thows an exception “Java Out Of Heap Space”. We don’t know how many slides the report may have. It may have 100 slides. Increasing the heap size also may not solve as we can increase it upto a certain limit. Any alternative??

Regards,
Anupam

Any help from u guys???

The only way is increase heap space. Presentations are stored in heap so
if you need process it you should give your application enough memory.

I think you should change app logic. For example try to process each
presentation separately and don’t load everything to the memory.

Hi,

I have a table with 10 columns and have created it with the following code.

com.aspose.slides.Table relTable3=slide.getShapes().addTable(relTable2.getX(),relTable2.getY()+relTable2.getHeight(),relTable2.getWidth(),
tableHeight,101);

Now I want to access three of the columns from the middle set its column width less than the other columns. But once I do this I see that the overall width of the table starts decreasing. I don't want this. I want the overall width of the table to remain the same while only the three columns should have a lesser width than others. How to achieve this?

Regards,

Anupam

If you will shrink/expand some column, the overall width of the table will also shrink/expand.

You can also change the width of the table by using Table.setWidth method.

If it does not work then recalculate the widths of all columns and set them each.

Hi Shakeel,

Thanks for the help. I tried that and its working. I have a question. Suppose I have a table with three columns Baseline, Predicted, Actual as you can see from the ppt attached herewith. Under this table you can see another table with values MF/LY, Equiv R etc. This columns of this table is set dynamically after cerain calculations. Just under the column "Predicted" you can see that there are three columns MF/LY, Equiv R, DVS. The widths of these columns are set by taking the reference of column width of "Predicted" column and dividing it by 3. But after doing that still I had to subtract somewhat around 43 to get the exact width and make it symmetrical to the Predicted column. Can you tell me can't we take the reference of some other table column and divide it into 3 parts to get another column width? The width of Predicted column is 1600 and dividing it by 3 gives us 533 but we have to subtract some another 43 to get exact width. I dnt want to use any hardcoded value because it is totally dynamic.

Regards

Anupam

You should keep the width of Predicted Column as multiple of 3, so that when you divide it into three parts, it could divide into 3 equal whole parts without any fractional part. For example, instead of 1600 (1600/3=533.33) use 1599 (1599/3=533) or 1602 (1602/3=534)

You can also make use of one more option, you can use separate tables vertically aligned (instead of horizontally). For example, you can have a separate table for BaseLine having 5 rows and two columns, where the columns of the first row are merged.

Likewise, you could have another table for Predicted, having 5 rows and 3 columns, where the 3 columns in the first row are merged.

In a similar way, you can construct table for Actual.

Aligning vertically will free you from tension of changing column widths.

Hi Shakeel,

Thanks for the help. I have finished generating the tables. Now I need to show it to the user dynamically. Once a user hits a generate button, it will call a bean class which will generate the ppt and a popup will appear showing Open, Save and Cancel buttons. If the user hits Open button the ppt should open in the browser so that the user can view it or else he can save it a certain location to view it later. I have written a code in a jsp which is already working in Apache Tomcat server.

Presentation present = new Presentation();
GEDFRPPTGeneration report = new GEDFRPPTGeneration(); //bean class
report.generateAssemblyLevelDynamicReport(context, args, present); OutputStream fostream=response.getOutputStream();

String fileEncodeType = UINavigatorUtil.getFileEncoding(context, request);
response.setContentType("application/vnd.ms-powerpoint; charset="+fileEncodeType);
present.write(fostream);
fostream.close();

But when I try to execute it in Weblogic server, the ppt opens but it is white. Instead of the tables, there is slide area with no data. If I save the file and check the size its is around 67KB and try to open it same thing happens. Can you please tell me what is the problem here? Why it is not working in Weblogic Server?

Regards,

Anupam

Dear Anupam,

I have forwarded your query to technical team lead and he will help you as soon as possible.

Hi Shakeel,

Please try to give me the solution ASAP as we have to give a demo to the client. I am stuck up with this and if demo is not given on time everything will be a waste.

Regards,

Anupam

In case presentation is empty or broken Aspose.Slides should throw some exceptions.
If you need a solution I think it’s a good idea to provide such exceptions and generated (67kb) ppt file.
Most probably your weblogic server doesn’t grant enough rights for the app or some jars not found in the classpath.

Hi All,

The above issue has been fixed.

We need to add one more line for Weblogic server before writing the presentation in outputstream.

response.resetBuffer();
present.write(fostream);

The buffer is automatically set in Tomcat but not in Weblogic. Hope this helps others who might be facing this kind of issue.

I need to ask one more thing regarding this. When the powerpoint presentation opens in a browser and then we try to scroll to the next slide, the browser closes automatically and we are not able to view the next slide. We are able to see the first slide only. This behaviour is not in all browsers. It happens in some browsers only. I would like to add that we are using Internet Explorer browser and the settings are same for all. Could you please solve this issue?

This is a bit urgent.

Regards,

Anupam

I have forwarded your query and you will get a reply as early as possible.

Hi,

I have a String variable which contains "\n" in between to display the string in a new line. However when I try to use TextFrame.setText() method, the text does not go to the next line. I am using this for slide footer.How can I show the text in a new line where there is a "\n" character?

Regards

Anupam

Hello Anupam,

Replace “\n” with “\r” and everything should work fine.