Hi
I have attached a ppt Test.ppt which contains only one slide. When I convert it to JPEG using the below code the text is all mixed up. The alignment is completely lost. I have attached the JPEG image also. Can you please look into it and diagnose the problem. Please let me know the solution for it.
Thanks so much
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;
}
}
for (int j = 0; j < textSlide.Placeholders.Count; j++) {
TextHolder th = textSlide.Placeholders[j] as TextHolder;
if (th != null) {
foreach (Paragraph para in th.Paragraphs) {
if (para.HasBullet && para.BulletType == BulletType.Symbol) {
bulletFontIndex = para.BulletFontIndex;
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;
}
}
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;
}
}
}
}
}
}
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");
}
}