ASP.NET Core PowerPoint Viewer
How to open, view a PowerPoint .pptx document in browser without Office, interop using C# ASP.NET MVC


How to read, display, annotate, redact, edit, convert Microsoft Office PowerPoint in web browser using C# ASP.NET PDF Viewer control.





EdgePDF is an ASP.NET PDF viewer and editor web control. However you will also read, view Office PowerPoint .pptx file in web browser with EdgePDF using C# ASP.NET

  • Open, read a PowerPoint file from server side document system or database
  • EdgePDF will automatically convert loaded PowerPoint to PDF document in ASP.NET web server
  • Converted PDF orientation could be Portrait or Landscape
  • View, comment PowerPoint content online in web browser
  • No Office, interop installed on ASP.NET web server

How to view a PowerPoint file programmatically in asp.net using C#

  1. Download EdgePDF asp.net PDF viewer web control
  2. Install EdgePDF demo project in IIS
  3. Follow step by step tutorial






Preparation



To run the following tutorial successfully, we need the following setup ready.



  1. For ASP.NET Core web app: Setup EdgePDF
  2. For ASP.NET Core MVC web app: Setup EdgePDF
  3. For ASP.NET (.net framework): Setup EdgePDF on IIS
  4. A demo Office PowerPoint .pptx file in folder C:\temp\powerpoint-1.pptx




How to open, view PowerPoint .pptx online in web browser in ASP.NET C#?



The following steps and C# demo source code will show how to read, view PowerPoint one slide per PDF page in web browser using ASP.NET C# code.

After you have completed the following guide, you can open, view a Office PowerPoint file online in web browser through url (a sample url http://localhost:56643/?yourtarget=powerpoint-1.pptx)

  • For ASP.NET Core web app, open file UserCommandProcessMiddleware.cs from /DemoProjects/EdgePDF for ASP.NET Core/

  • For ASP.NET (.net framework) project, open file UserCommandProcessHandler.ashx from {EdgePDF demo project}/RasterEdge_Resource_Files/

  • Go to method FileProcess()
  • Create a new byte[] object with viewed PPTX file in byte array
  • Call method REProcessControl.PageLoadFile() to load, view PowerPoint file in EdgePDF. The PowerPoint file (powerpoint-1.pptx) has been converted into PDF file and rendered in EdgePDF online in web browser


    public override PDFWebDocument FileProcess()
    {
        HttpRequest request = this.Context.Request;

        if (!String.IsNullOrEmpty(request.QueryString["yourtarget"]))
        {
            String docid = request.QueryString["yourtarget"];

            byte[] dataBytes = System.IO.File.ReadAllBytes(@"C:\\temp\" + docid);
                
            return REProcessControl.PageLoadFile(request, this.Manager, dataBytes, docid);
        }
        else
        {
            Logger.Log(">>> Unknown load file mode. Load default file defined in Web.config.", LogType.DEBUG);

            // load default file. defined in Web.config
            return REProcessControl.PageLoadFile(request, this.Manager, "", LoadType.Server);
        }
    }







How to read, view a PowerPoint file 2 slides in one PDF portrait page in web browser in ASP.NET C#?



The following steps and C# demo source code will help to enable your ASP.NET project read, view a Microsoft PowerPoint file in web browser using ASP.NET C# code.

After you have completed the following guide, you can open, view a Office PowerPoint file (2 slides per PDF page) online in web browser through url (a sample url http://localhost:56643/?yourtarget=powerpoint-1.pptx)



  • For ASP.NET Core web app, open file UserCommandProcessMiddleware.cs from /DemoProjects/EdgePDF for ASP.NET Core/

  • For ASP.NET (.net framework) project, open file UserCommandProcessHandler.ashx from {EdgePDF demo project}/RasterEdge_Resource_Files/

  • Go to method FileProcess()
  • Create a new PPTXDocument object with PowerPoint file loaded
  • Call method convertPPTX2PDF2SlidesInOnePage() to convert pptx to pdf with 2 slides in one PDF page (PDF page orientation is portrait)
  • Call method REProcessControl.PageLoadFile() to load, view PowerPoint file in EdgePDF. The PowerPoint file (powerpoint-1.pptx) has been converted into PDF file and rendered in EdgePDF online in web browser


    public override PDFWebDocument FileProcess()
    {
        HttpRequest request = this.Context.Request;

        if (!String.IsNullOrEmpty(request.QueryString["yourtarget"]))
        {
            String docid = request.QueryString["yourtarget"];

            PPTXDocument pptxDoc = new PPTXDocument(System.IO.File.ReadAllBytes(@"C:\\temp\" + docid));

            PDFDocument convertedPDFDoc = convertPPTX2PDF2SlidesInOnePage(pptxDoc);

            return REProcessControl.PageLoadFile(request, this.Manager, convertedPDFDoc, docid);
        }
        else
        {
            Logger.Log(">>> Unknown load file mode. Load default file defined in Web.config.", LogType.DEBUG);

            // load default file. defined in Web.config
            return REProcessControl.PageLoadFile(request, this.Manager, "", LoadType.Server);
        }
    }

    private PDFDocument convertPPTX2PDF2SlidesInOnePage(PPTXDocument pptxDoc)
    {
        //Step 1: convert PPTX to PDF
        MemoryStream tempPDFStream = new MemoryStream();
        pptxDoc.ConvertToDocument(DocumentType.PDF, tempPDFStream);

        //  Step 2: combine pages
        PageArrangeOptions ops = new PageArrangeOptions();
        //  set width of new page to 8.5 inches
        ops.PageWidth = 8.5F;
        //  set height of new page to 11 inches
        ops.PageHeight = 11F;
        //  set page margins in inch
        ops.TopMargin = 1F;
        ops.BottomMargin = 1F;
        ops.LeftMargin = 0.5F;
        ops.RightMargin = 0.5F;

        //  properties to arrange region for each page
        //  1 page per row
        ops.ColumnsPerPage = 1;
        //  2 pages per column
        ops.RowsPerPage = 2;
        //  0.1 inches interval between columns
        ops.ColumnInterval = 0.1F;
        //  0.1 inches interval between rows
        ops.RowInterval = 0.1F;
        //  set fit mode for each page
        ops.FitMode = PageArrangeOptions.PageFitMode.AspectFit;

        //  disable region border
        ops.RegionBorder.Width = 0;
        //  enable page border
        ops.PageBorder.Width = 1;
        ops.PageBorder.Color = Color.Blue;

        MemoryStream outputPDFStream = new MemoryStream();
        PDFDocument.CombinePages(tempPDFStream, outputPDFStream, ops);

        return new PDFDocument(outputPDFStream);
    }







How to view a PowerPoint file 4 slides in one PDF landscape page in web browser in ASP.NET C#?



The following steps and C# demo source code will help to setup a demo ASP.NET project, which allows you to read, view a Microsoft PowerPoint file in web browser using ASP.NET C# code.

After you have completed the following guide, you can open, view a Office PowerPoint file online in web browser through url (a sample url http://localhost:56643/?yourtarget=powerpoint-1.pptx)



  • For ASP.NET Core web app, open file UserCommandProcessMiddleware.cs from /DemoProjects/EdgePDF for ASP.NET Core/

  • For ASP.NET (.net framework) project, open file UserCommandProcessHandler.ashx from {EdgePDF demo project}/RasterEdge_Resource_Files/

  • Go to method FileProcess()
  • Create a new PPTXDocument object with PowerPoint file loaded
  • Call method convertPPTX2PDF4SlidesInOnePage() to convert pptx to pdf with 4 slides in one PDF page (PDF page orientation is landscape)
  • Call method REProcessControl.PageLoadFile() to load, view PowerPoint file in EdgePDF. The PowerPoint file (powerpoint-1.pptx) has been converted into PDF file and rendered in EdgePDF online in web browser


    public override PDFWebDocument FileProcess()
    {
        HttpRequest request = this.Context.Request;

        if (!String.IsNullOrEmpty(request.QueryString["yourtarget"]))
        {
            String docid = request.QueryString["yourtarget"];

            PPTXDocument pptxDoc = new PPTXDocument(System.IO.File.ReadAllBytes(@"C:\\temp\" + docid));

            PDFDocument convertedPDFDoc = convertPPTX2PDF4SlidesInOnePage(pptxDoc);

            return REProcessControl.PageLoadFile(request, this.Manager, convertedPDFDoc, docid);
        }
        else
        {
            Logger.Log(">>> Unknown load file mode. Load default file defined in Web.config.", LogType.DEBUG);

            // load default file. defined in Web.config
            return REProcessControl.PageLoadFile(request, this.Manager, "", LoadType.Server);
        }
    }

    private PDFDocument convertPPTX2PDF4SlidesInOnePage(PPTXDocument pptxDoc)
    {
        //Step 1: convert PPTX to PDF
        MemoryStream tempPDFStream = new MemoryStream();
        pptxDoc.ConvertToDocument(DocumentType.PDF, tempPDFStream);

        //  Step 2: combine pages
        PageArrangeOptions ops = new PageArrangeOptions();
        //  set width of new page to 11 inches
        ops.PageWidth = 11F;
        //  set height of new page to 8.5 inches
        ops.PageHeight = 8.5F;
        //  set page margins in inch
        ops.TopMargin = 1F;
        ops.BottomMargin = 1F;
        ops.LeftMargin = 0.5F;
        ops.RightMargin = 0.5F;

        //  properties to arrange region for each page
        //  1 page per row
        ops.ColumnsPerPage = 2;
        //  2 pages per column
        ops.RowsPerPage = 2;
        //  0.1 inches interval between columns
        ops.ColumnInterval = 0.1F;
        //  0.1 inches interval between rows
        ops.RowInterval = 0.1F;
        //  set fit mode for each page
        ops.FitMode = PageArrangeOptions.PageFitMode.AspectFit;

        //  disable region border
        ops.RegionBorder.Width = 0;
        //  enable page border
        ops.PageBorder.Width = 1;
        ops.PageBorder.Color = Color.Blue;

        MemoryStream outputPDFStream = new MemoryStream();
        PDFDocument.CombinePages(tempPDFStream, outputPDFStream, ops);

        return new PDFDocument(outputPDFStream);
    }







How to deploy ASP.NET MVC PowerPoint viewer web app to Azure service?



After complete the ASP.NET PPTX viewer web application, you could easily publish the ASP.NET Core web app to Azure cloud service. View details at How to deploy ASP.NET PowerPoint viewer web application to Azure?