Here is the code I am using: (I'm doing this with razor c#)
- Code: Select all
@using System;
@using System.Drawing;
@using System.Web.Mvc;
@using Spire.Presentation;
@using Spire.Presentation.Drawing;
@{
var companyLogoFileName = "";
if (IsPost) {
string companyName = Request["companyName"];
string objectiveValue = Request["txtObjective"];
string solutionValue = Request["txtSolution"];
string resultValue = Request["txtResult"];
string marketName = "Nashville";
var companyLogoFileSavePath = "";
var uploadedCompanyLogoFile = Request.Files[0];
companyLogoFileName = Path.GetFileName(uploadedCompanyLogoFile.FileName);
companyLogoFileSavePath = Server.MapPath("~/App_Data/UploadedFiles/" + companyLogoFileName);
uploadedCompanyLogoFile.SaveAs(companyLogoFileSavePath);
Presentation ppt = new Presentation("c:\\temp\\CaseStudyTemplateTest.pptx", FileFormat.Pptx2010);
string marketLogo = "c:\\temp\\logos.png";
RectangleF marketLogoRect = new RectangleF(5, 145, 135, 232);
ppt.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, marketLogo, marketLogoRect).Line.FillType = FillFormatType.None;
System.Drawing.Image img = System.Drawing.Image.FromFile(companyLogoFileSavePath);
var ratioX = (double)130 / img.Width;
var ratioY = (double)101 / img.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(img.Width * ratio);
var newHeight = (int)(img.Height * ratio);
var positionX = (int)((144 - newWidth) / 2);
var positionY = (int)((116 - newHeight) / 2);
RectangleF companyLogoRect = new RectangleF(positionX, positionY, newWidth, newHeight);
ppt.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, companyLogoFileSavePath, companyLogoRect).Line.FillType = FillFormatType.None;
IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(0, 117, 144, 279));
shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.FromArgb(158, Color.White);
shape.Line.FillType = FillFormatType.None;
IAutoShape companyNameText = (IAutoShape)ppt.Slides[0].Shapes[0];
IAutoShape objectiveText = (IAutoShape)ppt.Slides[0].Shapes[1];
IAutoShape solutionText = (IAutoShape)ppt.Slides[0].Shapes[2];
IAutoShape resultText = (IAutoShape)ppt.Slides[0].Shapes[3];
IAutoShape marketNameText = (IAutoShape)ppt.Slides[0].Shapes[4];
companyNameText.TextFrame.Text = companyName.ToUpper();
objectiveText.TextFrame.Text = objectiveValue;
solutionText.TextFrame.Text = solutionValue;
resultText.TextFrame.Text = resultValue;
marketNameText.TextFrame.Text = marketName.ToUpper();
//ppt.SaveToFile("c:\\temp\\ExportedPowerpoint-3102014.pptx", FileFormat.Pptx2010);
ppt.SaveToHttpResponse("httpResponse.pptx", FileFormat.Pptx2010, HttpContext.Current.Response);
//File.Delete(companyLogoFileSavePath);
}
}
<div class="form-horizontal">
<fieldset>
<legend>Case Study Generator</legend>
<div class="form-group">
<label class="col-md-2 control-label" for="companyName">Company Name</label>
<div class="col-md-10">
<input id="companyName" name="companyName" type="text" placeholder="Enter Company Name..." class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="fileCompanyLogo">Upload Company Logo</label>
<div class="col-md-10">
<input id="fileCompanyLogo" name="fileCompanyLogo" class="input-file" type="file">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="txtObjective">Objective</label>
<div class="col-md-10">
<textarea class="form-control" id="txtObjective" name="txtObjective" >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="txtSolution">Solution</label>
<div class="col-md-10">
<textarea class="form-control" id="txtSolution" name="txtSolution">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="txtResult">Result</label>
<div class="col-md-10">
<textarea class="form-control" id="txtResult" name="txtResult">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</textarea>
</div>
</div>
<legend>Generate Case Study</legend>
<div class="form-group">
<div class="col-md-3 col-md-push-2">
<button id="btnGenerateCaseStudyPPT" name="btnGenerateCaseStudyPPT" class="btn btn-primary btn-block">Download Powerpoint</button>
</div>
<div class="col-md-3">
<button id="btnGenerateCaseStudyPDF" name="btnGenerateCaseStudyPDF" class="btn btn-primary btn-block">Download PDF</button>
</div>
</div>
</fieldset>
</div>