You can not use ooxml to achieve this. Open xml can only be used to create/edit the office documents.
This can be achieved by converting slides to images and then convert images to pdf.
I have done PPTX slide to image conversion by reading the PPTX file using OpenXML SDK, asp.net chart control (need to refer System.Web.UI.Controls in the project) & windows form panel (need to refer windows controls).
Once you have your slide images ready, you can use iTextSharp or PdfSharp to convert images to pdf ( forums.asp.net/.../1 )
Hello Pramod,
Even I am trying to achieve the same as you did ,i.e. convert pptx to Image. Would it be too much for me to ask you to share the code.
Thanks
-Ajay
Hi Ajay, Sorry to say that I, cannot share the code with you. But you can look at the main method Render.
internal void Render(string powerpointFile, string imageStorage) { using (PresentationDocument presentationDoc = PresentationDocument.Open(powerpointFile, false)) { int slideCount = 0; foreach (SlidePart slidePart in presentationDoc.PresentationPart.SlideParts) { // collect the image chunks List<ImageProperties> imgChunks = new List<ImageProperties>(); imgChunks.Add(slidePart.SlideLayoutPart.GetLayoutImage()); // loop through every shape in the slide and convert them to images foreach (OpenXmlCompositeElement shapeElement in slidePart.Slide.CommonSlideData.ShapeTree.ChildElements) { /* * Process => ( shape, picture, chart and table elements ) and return ImageProperties */ if (shapeElement is Shape) { // process shape : convert static text / paragraph to image imgChunks.Add(new TextToImage().DrawImage(shapeElement as Shape)); } else if (shapeElement is Picture) { // process picture : pick an embedded image imgChunks.Add(slidePart.GetImage(shapeElement)); } else if (shapeElement is GraphicFrame) { if ((shapeElement as GraphicFrame).HasChild(typeof(DocumentFormat.OpenXml.Drawing.Table))) { // process table : pick table images imgChunks.Add(new HtmlToImage().GetImage(new Object())); } else if ((shapeElement as GraphicFrame).HasChild(typeof(DocumentFormat.OpenXml.Drawing.Charts.Chart))) { // process chart : create image of a chart imgChunks.Add(new ChartToImage().DrawImage(slidePart, shapeElement as GraphicFrame)); } } } // save as a single image System.Drawing.Image slideImage = imgChunks.RemoveNulls().MergeAllImages(); slideImage.Save(String.Format(@"{0}slide{1}.png",imageStorage,(++slideCount).ToString()), System.Drawing.Imaging.ImageFormat.Png); } } }
class ImageProperties { public Image Image { get; set; } public Int32 X { get; set; } public Int32 Y { get; set; } public Int32 Width { get; set; } public Int32 Height { get; set; } } You can start with Shapes to Images. That's the easier one. Get a Shape object. Get Height&Width of it by Transform2d/Transform property. Create a Bitmap object with this height & width. Then use Grphics.DrawString() to draw the text into the Bitmap image. Try to get the exact image. Once you get the image, you can work on coloring, size, styles... Let me know if u need any help.
class ImageProperties { public Image Image { get; set; } public Int32 X { get; set; } public Int32 Y { get; set; } public Int32 Width { get; set; } public Int32 Height { get; set; } }
You can start with Shapes to Images. That's the easier one.
Get a Shape object. Get Height&Width of it by Transform2d/Transform property. Create a Bitmap object with this height & width.
Then use Grphics.DrawString() to draw the text into the Bitmap image.
Try to get the exact image. Once you get the image, you can work on coloring, size, styles...
Let me know if u need any help.
Hi Pramod,
I need your help on PPTX slides to Image conversion.
Is there any other easy way to achieve this?.
I couldn't find any method like "GetLayoutImage" in the openXML assemblies.
Are you using any wrapper classes (your own class like TextToImage, HtmlToImage ) in the above code?
If possible please share your code or give me some idea to proceed further.
Thanks,
pragath