We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to genrate aspose slide

hey some one tell me how to use aspose slides for my java application


This message was posted using Aspose.Live 2 Forum

Dear setuaagrawal,

Thanks for considering Aspose.Slides for JAVA.

You must know how to write programs in JAVA.

Aspose.Slides for JAVA is available as a JAR file, which you add in your classpath and then import its package.

i.e

imports com.aspose.slides.*;

Then you write your program, which uses Aspose.Slides' APIs, classes or methods.

For code examples, you should see documentation, which is installed on your computer by installer or you can see it online.

http://www.aspose.com/documentation/file-format-components/aspose.slides-for-.net-and-java/index.html

Here is the link to Programmer's Guide for Aspose.Slides, there you will find code examples that make use of various Aspose.Slides features in JAVA as well as in other languages.

http://www.aspose.com/documentation/file-format-components/aspose.slides-for-.net-and-java/programmers-guide.html

Hi Faij thanks for responding .

but i am having some problem in Body slide

like i want create one body slide

it starts with one header

and in the body portion wants to put some bullet points

and one thing whenever i am tring to put header and footer for any slidefooter i am able to put but for header its not giving any thing , its compiling the code but its not giving any thing in header portion.

Header actually shows when you view your ppt file in notes view. If you want to put some code in title, then you can access the title placeholder with the following code.

TextHolder thld = (TextHolder) sld.getPlaceholders().get(0);
tld.getParagraphs().get(0).getPortions().get(0).setText("Your title text.");

Note, for the above code to work, your slide should be body or header or title slide, which you can with the following methods

Presentation.addTitleSlide()
Presentation.addBodySlide() etc

But if you have added the empty slide

Presentation.addEmptySlide()

Then, you need to add a textframe, and then set its formatting and text. For code example, you should see this post, which adds a title using TextFrame, the code is in C#, but you can easily convert it into JAVA, just use set and get words before the properties.

thanks faiz its working fine

can u plz tell me how to put images like company logo top left corner?

and can u plz tell me how to put some bullet points on a body part of body slide

thanks

Faiz

Dear setuaagrawal,

For your ease of understanding, I have written a JAVA code, which adds a logo and textframe with bullets.

It is easy to understand, as I have commented everyline and you should not have difficulty understanding it.

I have also attached the code and the presentation generated by this code namely outAddingLogoAndBulletedText.ppt so that you can view it.

Hopefully, it will be helpful for you.

JAVA CODE:

-----------------------------------------------------------------------------------------------------------------------------------

static void AddingLogoAndBulletedText() throws Exception

{

//Create a presentation from scratch

Presentation pres = new Presentation();

//Get the empty slide added by default

Slide sld = pres.getSlideByPosition(1);

//Add a company logo

//First add a logo picture inside presentation

FileInputStream logoStream=new FileInputStream("c:/logo.bmp");

com.aspose.slides.Picture pic = new com.aspose.slides.Picture(pres, logoStream);

int logoPicId = pres.getPictures().add(pic);

//Now add a picture to top left corner

//You need to pass it proper X, Y, Width and Height

int logoX = 100;

int logoY = 100;

int logoWidth = 2000;

int logoHeight = 500;

//To add picture, you need to add PictureFrame

//Pass it picture id, x, y, width and height

PictureFrame pf = sld.getShapes().addPictureFrame(logoPicId, logoX, logoY, logoWidth, logoHeight);

//We have finished adding picture, now add a TextFrame, with bullet paragraphs.

com.aspose.slides.Rectangle rect = sld.getShapes().addRectangle(200, 1200, 3000, 1);

//hide rectangle's lines

rect.getLineFormat().setShowLines(false);

//Add TextFrame inside

TextFrame tf = rect.addTextFrame("");

//Make the TextFrame wrap text if it exceeds its width

tf.setWrapText(true);

//Make the TextFrame expand rectangle shape, if text exceeds width

tf.setFitShapeToText(true);

//Add text inside TextFrame.

//Note, first paragraph and its portion is added by default

Paragraph para = tf.getParagraphs().get(0);

//Set first paragraph text

para.getPortions().get(0).setText("This is the first portion of the first bulleted paragraph.");

//Make the paragraph bulleted

para.setHasBullet((short)1);

para.setBulletType(BulletType.SYMBOL);

para.setBulletCharacter((char)8226);

//Make some space

para.setBulletOffset((short)0);

para.setTextOffset((short)150);

//To add more paragraphs, make copy of the above paragraph and then add

Paragraph newPara = new Paragraph(para);

newPara.getPortions().get(0).setText("This is the first portion of the second bulleted paragraph");

tf.getParagraphs().add(newPara);

//Write presentation on disk

FileOutputStream fout=new FileOutputStream("c:/outAddingLogoAndBulletedText.ppt");

pres.write(fout);

}

hey faiz thanks its working man

Hi faiz ,

1)

actully now i am trying to inceaes the width of slide by this line of code but i am not able increase it

slide2.getBackground().setWidth(slide2.getBackground().getWidth()*2);

2)

another thing i am having problem in master slide also

means i want to create one master slide other slide will use that slide as a background.

so can u plz help me.

Thanks

hi faiz

i am also trying to change the table height but looking like like some problem it always giving same height of table.

//Creating an table object and passing all parameter

Table table = slide4.getShapes().addTable(0,900,4960,0,12,4,1,Color.lightGray);

here in this code u can see height is 0 but it still giving one constant height

For changing slide width / height, you should Presentation.setSlideSize property.

Presentation pres = new Presentation();
pres.setSlideSize(new Point(1000, 4000));
pres.write(new FileOutputStream("c:\\outPres.ppt"));

You cannot create master slides; you can only copy them from other presentations and then change the master of your slide with slide.changeMaster() method. For code example, please see this.

thanks faiz its working fine

Hi Faiz,
Can we do one thing,
like can we use one of slide from our presentation as a master slide.
i tried my hand but not getting the result i am pasting peace of code


long mstrId = slide2.getMasterId();
pres.getSlides().remove(slide2);
System.out.println("master id – "+mstrId);
Slide mstrSld = pres.getSlideById(mstrId);
int lastSlidePos=pres.getSlides().getLastSlidePosition();
slide.changeMaster(mstrSld, true);
for (int i = 1; i <= lastSlidePos; i++)

{
System.out.println("mstrSld – "+mstrSld);
System.out.println("lasslidePos – "+lastSlidePos);
System.out.println("i – "+i);
Slide normSld = pres.getSlideByPosition(i);

normSld.changeMaster(mstrSld, true);

}



plz just check can we do by this way.

another thing i am trying to reduce the height of table but its now getting reduce means it getting reduce to some extent but not after that even i have given height is 0 then also its giving a default height

//Setting table parameters
int xPosition=1000;
int yPosition=slide2.getBackground().getHeight()*1/6;
int tableWidth=slide2.getBackground().getWidth()-1000;
int tableHeight=0; // slide2.getBackground().getHeight()/10;
int columns=18;
int rows=3;
float borderWidth=1;

//Creating an table object and passing all parameter
Table table = slide2.getShapes().addTable(xPosition,slide2.getBackground().getHeight()*1/2,tableWidth,tableHeight,columns,rows,borderWidth,Color.BLACK);


above peace of code i am using for the table so can u plz tell me how to reduce the table height.




Thanks And Regards


hi Faiz please can u rply me back i am waiting for ur response.

Your first code does not seem to have any problem. I have checked it with little additions to make it running.

-------------------------------------------------------

Presentation pres = new Presentation(new FileInputStream("c:\\source.ppt"));

Slide slide2=pres.getSlideByPosition(2);

long mstrId = slide2.getMasterId();

pres.getSlides().remove(slide2);

System.out.println("master id -- "+mstrId);

Slide mstrSld = pres.getSlideById(mstrId);

int lastSlidePos=pres.getSlides().getLastSlidePosition();

//slide.changeMaster(mstrSld, true);

for (int i = 1; i <= lastSlidePos; i++)

{

System.out.println("mstrSld -- "+mstrSld);

System.out.println("lasslidePos -- "+lastSlidePos);

System.out.println("i -- "+i);

Slide normSld = pres.getSlideByPosition(i);

normSld.changeMaster(mstrSld, true);

}

pres.write(new FileOutputStream("c:\\output.ppt"));

-------------------------------------------------------

Table height cannot be set after a minimum height of it has reached, this is because of font size inside table cells. For example, if font size of text inside the cell is 45, then row height cannot be decreased further after some specific height, to decrease it further, you need to set the font size to lesser than 45 say 30, 20.

You can try it in MS-PowerPoint.

Also, there are two other important APIs for setting height and width, they are Tables.setColumnWidth and Tables.setRowHeight.

hi,

we are using visual studio asp.net with c#. can you tell me how to add rectangles with different colors having spaces between words like

ColumnName Data
ColumnName2 Data,Data,Data

like that i should have many rows with same spacing…
can you plese help me…

thanks
rmarala

Dear rmarala,

Thanks for considering Aspose.Slides

Please see the following example. I have also attached the output presentation generated by the code, please see it. The code is commented for your ease of understanding, if you still have question, please feel free to ask.

C#

//Create a presentation
Presentation pres = new Presentation();

//Get a slide
Slide sld = pres.GetSlideByPosition(1);

//Create 4 rectangles
Aspose.Slides.Rectangle rect1 = sld.Shapes.AddRectangle(760, 1050, 1730, 430);
Aspose.Slides.Rectangle rect2 = sld.Shapes.AddRectangle(760, 1830, 1730, 430);
Aspose.Slides.Rectangle rect3 = sld.Shapes.AddRectangle(3170, 1050, 1730, 430);
Aspose.Slides.Rectangle rect4 = sld.Shapes.AddRectangle(3170, 1830, 1730, 430);

//Give them background colors
rect1.FillFormat.Type = FillType.Solid;
rect1.FillFormat.ForeColor = Color.Aquamarine;
rect2.FillFormat.Type = FillType.Solid;
rect2.FillFormat.ForeColor = Color.Aquamarine;
rect3.FillFormat.Type = FillType.Solid;
rect3.FillFormat.ForeColor = Color.Bisque;
rect4.FillFormat.Type = FillType.Solid;
rect4.FillFormat.ForeColor = Color.Bisque;

//Assign center aligned bold text to first two rectangles

//1st
TextFrame tf = rect1.AddTextFrame(" ");
Paragraph para = tf.Paragraphs[0];
para.Alignment = TextAlignment.Center;
Portion port = tf.Paragraphs[0].Portions[0];
port.Text = "Column Name";
port.FontBold = true;

//2nd
tf = rect2.AddTextFrame(" ");
para = tf.Paragraphs[0];
para.Alignment = TextAlignment.Center;
port = tf.Paragraphs[0].Portions[0];
port.Text = "Column Name 2";
port.FontBold = true;

//Assign center aligned text to other two rectangles

//3rd
tf = rect3.AddTextFrame(" ");
para = tf.Paragraphs[0];
para.Alignment = TextAlignment.Center;
port = tf.Paragraphs[0].Portions[0];
port.Text = "Data";

//4th
tf = rect4.AddTextFrame(" ");
para = tf.Paragraphs[0];
para.Alignment = TextAlignment.Center;
port = tf.Paragraphs[0].Portions[0];
port.Text = "Data, Data";

pres.Write("c:\\outRectangles.ppt");