Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Wed Mar 11, 2015 1:25 am

Everything I open a generated ppt, keeps coming up corrupt.

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>

whittenmike807
 
Posts: 7
Joined: Thu Mar 05, 2015 9:23 pm

Wed Mar 11, 2015 8:00 am

Hello,

Thanks for your inquiry.
I have reproduced your issue that opening the document throw an error (I upload the error image) and posted it to our dev team. Once there are any processes, we will let you know.
Did you get the same information? If not, please provide the information of the error you met in detail.

Best Regards,
Betsy
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Thu Mar 12, 2015 5:09 pm

Is there an update on this?

I'm wanting to purchase this software, but I need it to save to the Http Response

whittenmike807
 
Posts: 7
Joined: Thu Mar 05, 2015 9:23 pm

Fri Mar 13, 2015 1:59 am

Hello,

After investigation, please add the following code after SaveToHttpResponse method:
Code: Select all
HttpContext.Current.Response.End();


Now you can open the document normally.
Please feel free to contact us if there are any questions.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Fri Mar 13, 2015 12:44 pm

Well, I'm almost there.


So I added that line to the end of the SaveToHttpReponse, and when I open the file I still get the repair pop-up.

But, If I click repair it will load fine.

Anything else?

whittenmike807
 
Posts: 7
Joined: Thu Mar 05, 2015 9:23 pm

Mon Mar 16, 2015 2:24 am

Hello,

It would be very helpful if you provide your sample files(CaseStudyTemplateTest.pptx and logos.png ) for our testing. And we may work out the solution for you ASAP.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.Presentation

cron