Setting PictureBullet per Paragraph at runtime

How do I set a bullet picture for each paragraph in a textframe at runtime?

Dear cbaker,

To add picture bullet, you will first create an instance of PictureBullet class, then add that instance to Presentation.PictureBullets collection and save the ID return by Presentation.PictureBullets.Add method. Then you will set the Paragraph.BulletType as BulletType.Picture, and Paragraph.PictureBulletId to the ID saved by you earlier. Below is a complete code, which creates a presentation and add paragraphs with the picture bullets. Source code and output presentation generated by it is attached.

void PictureBullet()

{

Presentation srcPres = new Presentation();

Slide sld = srcPres.GetSlideByPosition(1);

PictureBullet picBullet=new PictureBullet(srcPres, @"c:\bullet.jpg");

int picBulletId = srcPres.PictureBullets.Add(picBullet);

Shape shp = sld.Shapes.AddRectangle(500, 500, 3000, 1);

shp.AddTextFrame("");

shp.LineFormat.ShowLines=false;

TextFrame tf = shp.TextFrame;

tf.WrapText = true;

tf.FitShapeToText = true;

Paragraph para = new Paragraph();

para.Text = "Some text";

para.HasBullet = 1;

para.BulletType = BulletType.Picture;

para.PictureBulletId = (short)picBulletId;

tf.Paragraphs.Clear();

tf.Paragraphs.Add(new Paragraph(para));

tf.Paragraphs.Add(new Paragraph(para));

tf.Paragraphs.Add(new Paragraph(para));

srcPres.Write(@"c:\out.ppt");

}

Not entirely what I was looking for, but I figured it out on my own.

For those with a similar issue:

string strBulletImagePath1 = HttpContext.Current.Server.MapPath("/images/Bullet1.png");

string strBulletImagePath2 = HttpContext.Current.Server.MapPath("/images/Bullet2.png");

PictureBullet picBullet1 = new PictureBullet(pPresentation, strBulletImagePath1);

PictureBullet picBullet2 = new PictureBullet(pPresentation, strBulletImagePath2);

pPresentation.PictureBullets.Add(picBullet1);

pPresentation.PictureBullets.Add(picBullet2);

Paragraph paragraphToClone = currentTextFrame.Paragraphs[0];

currentTextFrame.Paragraphs.Clear();

for ( int j = 0; j < count; j++ )

{

string strParagraphText = "text";

short strBulletCode = String.Empty;

Paragraph paragraphToInsert = new Paragraph(paragraphToClone);

short shtPictureBulletID = 0;

switch ( strBulletCode )

{

case "bullet1":

shtPictureBulletID = 1;

break;

case "bullet2":

shtPictureBulletID = 2;

break;

}

paragraphToInsert.PictureBulletId = shtPictureBulletID;

paragraphToInsert.Portions[0].Text = strParagraphText ;

currentTextFrame.Paragraphs.Add(paragraphToInsert);

}

{As you add PictureBullets to the presentation, you can set the appropriate bullet of each paragraph in the textframe by assigning the Paragraph[i].PictureBulletId equal to the newly available Picture Bullet IDs. If your textframe already has an picture bullet before runtime, then that Picture Bullet ID will be 0. Otherwise the first PictureBullet you add will be 0, 2nd will be 1, and so on. If you attempt to set to a PictureBulletId that does not exist, the error is not handled, so you will get some strange results.}

Can you send the Java example of the above code please.

cheers

Harry

Then, see this thread.

<A href="https://forum.aspose.com/t/100432</A></P>