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

Free Support Forum - aspose.com

Problem while converting certain ppt to JPEG

Hi

I have attached 2 Presentations - 1. PPT_1.ppt and

2. PPT_2.ppt

I have also attached the JPEG images obtained after converting the PPTs to JPEGs using Aspose.Slides in the following folders

1. JPEGs from PPT_1.zip

2. JPEGs from PPT_2.zip

I have used the code given in the end to convert the PPT.

PPT_1 is the orginal ppt. PPT_2 was created by following the steps given below

1. Copy PPT_1 as PPT_2

2. Delete all the slides from PPT_2

3. Copy all the slides from PPT_1 to PPT_2

PROBLEM:

If we compare the Jpegs obtained using the 2 ppts we can see that Jpeg's from PPT_1 does not render the bullets(i.e bullets appear as alphabets like 'u') whereas Jpeg's obtained from PPT_2 renders the bullets correctly.

I debuged through my code and I saw that for PPT_1 the paragraphs are not identified (paragraph count = 0)and hence skips the whole prcessing of replacing unistalled fonts with wingding font and hence the bullets are not rendered.

Where as for PPT_2 the paragraphs are identified properly and the uninstalled fonts are replaced with wingding.

Why is there so much difference even though the content of the PPTs are the same? Request you to provide a solution for the same.

Code:

bool hasAudioVideo = false;

Slide textSlide = null;

bool exists = false;

char bulletChar;

int bulletFontIndex = 0;

short bulletHeight;

Color bulletColor;

Aspose.Slides.License license = new Aspose.Slides.License();

Assembly currentAssembly = Assembly.GetExecutingAssembly();

string[] arrResources = currentAssembly.GetManifestResourceNames();

foreach (string resource in arrResources) {

if (resource.EndsWith("Aspose.Slides.lic")) {

license.SetLicense(resource);

}

}

Presentation textPres = new Presentation("C:\\PPT_1.ppt");

System.Drawing.FontFamily[] families = System.Drawing.FontFamily.Families;

Fonts fonts = textPres.Fonts;

//Setting the anti-alias for the text presetn in the slides.

for (int i = 1; i <= textPres.Slides.LastSlidePosition; i++) {

textSlide = textPres.GetSlideByPosition(i);

foreach (Shape shape in textSlide.Shapes) {

if (shape is Aspose.Slides.Rectangle) {

if (shape.TextFrame != null) {

foreach (Paragraph para in shape.TextFrame.Paragraphs) {

bool hasBullet = para.HasBullet;

if (hasBullet == true) {

para.HasBullet = true;

if (para.BulletType == BulletType.Symbol) {

bulletChar = para.BulletCharacter;

bulletFontIndex = para.BulletFontIndex;

exists = false;

foreach (System.Drawing.FontFamily family in families) {

if (fonts[bulletFontIndex].FontName == family.Name) {

exists = true;

break;

}

}

if (exists == false) {

fonts[bulletFontIndex].FontName = "WingDings";

}

bulletHeight = para.BulletHeight;

bulletColor = para.BulletColor;

para.BulletColor = bulletColor;

para.BulletHeight = bulletHeight;

para.BulletCharacter = Convert.ToChar(bulletChar);

}

}

if (para.Portions != null) {

foreach (Portion por in para.Portions) {

string text = por.Text;

int fontIndex = por.FontIndex;

FontEntity fontEntity = textPres.Fonts[fontIndex];

fontEntity.Quality = FontQuality.ANTIALIASED_QUALITY;

}

}

}

}

}

else if (shape is Aspose.Slides.PictureFrame) {

PictureFrame pf = (PictureFrame)shape;

int b = pf.Brightness;

pf.Brightness = EAPConstants.BRIGHTNESS;

b = pf.Brightness;

}

}

}

string tempPPTName = System.IO.Path.GetTempFileName();

textPres.Write(tempPPTName);

//Presentation imagePres = new Presentation(OriginalFilePath);

Presentation imagePres = new Presentation(tempPPTName);

int slideWidth = imagePres.SlideSize.Width;

int slideHeight = imagePres.SlideSize.Height;

Slide imageSlide = null;

for (int j = 1; j <= imagePres.Slides.LastSlidePosition; j++) {

imageSlide = imagePres.GetSlideByPosition(j);

tempPPTName = System.IO.Path.GetTempFileName();

hasAudioVideo = false;

foreach (Shape shape in imageSlide.Shapes) {

if (shape is AudioFrame || shape is VideoFrame) {

hasAudioVideo = true;

break;

}

}

if (hasAudioVideo == false) {

ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

ImageCodecInfo ici = null;

foreach (ImageCodecInfo codec in codecs) {

if (codec.MimeType == "image/jpeg") {

ici = codec;

break;

}

}

//Importing the file.

Image image= imageSlide.GetThumbnail(new Size(1813, 1360));

string tempFileName = System.IO.Path.GetTempFileName();

image.Save

@"C:\JPEGs from PPT1\" + j + ".JPG");

}

}

Presentation contains embedded fonts which are not supported by Aspose.Slides.
Most probably “Monotype Sorts” font not installed on your computer and rendered as ‘u’ or something else.

True, My PC does not have "monotype sorts" installed. That is y i am replacing it with "Wingdings". This works for PPT_2.ppt But fails for PPT_1.ppt. The contents of both the PPT are the same.

While debugging my code I found out that for PPT_1 the Paragraphs in the slides are not identified and there fore the step where monotype sorts are replaced by wingdings is not executed.

For PPT_2 the paragraphs are identified and hence the monotype sorts are replaced by wingdings.

Please advice me as to y there is a difference in the behaviour by aspose.slides towards 2 ppts having the same contents and what is the solution for such secnarios.

You should iterate both Shapes and Placeholders collections.

I tried iterating through both shapes and placeholders and still it does not work.

You did something wrong because it works for me.

Did you try for both the presentations I sent. Did it work for PPT_1.ppt?

If yes.. Can u pls send me the code snippet which u used?

ArrayList families = new ArrayList(System.Drawing.FontFamily.Families);
Fonts fonts = pres.Fonts;
for (int i = 1; i <= pres.Slides.LastSlidePosition; i++) 
{
    Slide slide = pres.GetSlideByPosition(i);
    foreach (Shape shape in slide.Shapes)
    {
        if (shape.TextFrame != null) 
        {
            foreach (Paragraph para in shape.TextFrame.Paragraphs)
            {
                if (para.HasBullet && para.BulletType == BulletType.Symbol) 
                {
                    int bulletFontIndex = para.BulletFontIndex;
                    if (!families.Contains(fonts[bulletFontIndex].FontName))
                    {
                        fonts[bulletFontIndex].FontName = "Wingdings";
                    }
                }
            }
        }
    }
    for (int j = 0; j < 8; j++)
    {
        TextHolder th = slide.Placeholders[j] as TextHolder;
        if (th != null) 
        {
            foreach (Paragraph para in th.Paragraphs)
            {
                if (para.HasBullet && para.BulletType == BulletType.Symbol) 
                {
                    int bulletFontIndex = para.BulletFontIndex;
                    if (!families.Contains(fonts[bulletFontIndex].FontName))
                    {
                        fonts[bulletFontIndex].FontName = "Wingdings";
                    }
                }
            }
        }
    }
}