Created
November 3, 2017 10:00
-
-
Save serdardurbaris/1487412326b0109bf18bf7aaa929b1d7 to your computer and use it in GitHub Desktop.
OpenXml PowerPoint to Jpg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fileName = Server.MapPath("/Content/test_small.pptx"); | |
var presentation = PresentationDocument.Open(fileName, true); | |
int i = 1; | |
ViewBag.Link = null; | |
foreach (var slide in presentation.PresentationPart.SlideParts) | |
{ | |
var imagePart = (ImagePart)slide.GetPartById("rId2"); | |
var img = Image.FromStream(imagePart.GetStream()); | |
var bmp = new Bitmap(1920, 1080); | |
using (var graph = Graphics.FromImage(bmp)) | |
{ | |
var imageSize = new Rectangle(0, 0, 1920, 1080); | |
graph.FillRectangle(Brushes.White, imageSize); | |
} | |
var xposition = (1920 - img.Width) / 2; | |
var yposition = (1080 - img.Height) / 2; | |
var zemin = new Bitmap(bmp); | |
var g = Graphics.FromImage(zemin); | |
g.SmoothingMode = SmoothingMode.HighQuality; | |
g.PixelOffsetMode = PixelOffsetMode.HighQuality; | |
g.CompositingQuality = CompositingQuality.HighQuality; | |
g.InterpolationMode = InterpolationMode.HighQualityBicubic; | |
g.DrawImage(img, xposition, yposition, img.Width, img.Height); | |
var filename = "powerpoint_" + i++ + ".jpg"; | |
zemin.Save(Server.MapPath("~/Content/" + filename), ImageFormat.Jpeg); | |
g.Dispose(); | |
zemin.Dispose(); | |
ViewBag.Link += "<a href='/Content/" + filename + "' target='_blank'>"+ filename + "</a></br>"; | |
} | |
presentation.Close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment