title: Display .pdf in image box in asp.net
body: <p>The goal is to upload a .ppt, convert it to a .pdf, and then show that to the user.</p>
  
  <p>Right now I can upload and convert just fine. If I uncomment those two lines in my code-behind, it shows a full-screen display.</p>
  
  <p>Is there any way I can display the .pdf inside an 'asp:Image' or some other non-fullscreen thing?</p>
  
  <p>My front is this:</p>
  
  <pre><code>&lt;%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
      CodeBehind="Default.aspx.cs"  Inherits="WebApplication1._Default" %&gt;
  
  &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
  
  
              &lt;input type="file" id=File1 name=File1 runat="server" /&gt;
              &lt;asp:Button id="b1" Text="Upload" OnCLick="DoUpload" runat="server" /&gt;
  
             &lt;asp:Image ID="img" runat="server"  AlternateText="" Width="400" Height="400" /&gt;
  
  
     &lt;/asp:Content&gt;
  </code></pre>
  
  <p>My code-behind is this</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Diagnostics;
  namespace WebApplication1
  {
  
      public partial class _Default : System.Web.UI.Page
      {
          protected System.Web.UI.HtmlControls.HtmlInputFile File1;
          protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;
  
  
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
  
  
          protected void DoUpload(object sender, EventArgs e)
          {
  
              if((File1.PostedFile!=null)&amp;&amp;(File1.PostedFile.ContentLength&gt;0))
              {
                  string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
                  string pdfn = fn.Remove(fn.Length - 3) + "pdf";
                  string SaveLocation = Server.MapPath("Data")+"\\"+fn;
                  string ShortLocation = Server.MapPath("Data")+"\\";
                  string PdfLocation = Server.MapPath("Data") + "\\" + pdfn;
                  try
                  {
                      File1.PostedFile.SaveAs(SaveLocation);
                      Response.Write("The file has been uploaded. ||");
  
                      Response.Write(" " + SaveLocation + " " + ShortLocation);
                      Process p = new Process();
                      p.StartInfo.FileName = "cmd.exe";
                      p.StartInfo.Arguments = "soffice --headless --invisible -convert-to pdf "+fn;
                      p.StartInfo.UseShellExecute = false;
                      p.StartInfo.RedirectStandardOutput = true;
                      p.Start();
                      p.WaitForExit();
                      Response.Write(" || File converted");
                      Response.Clear();
  
                      string filePath = PdfLocation;
  
                      //Response.ContentType = "application/pdf";
                      //Response.WriteFile(filePath);
  
                      img.ImageUrl = filePath;
  
                  }
                  catch(Exception ex)
                  {
                      Response.Write("Error: " + ex.Message);
                  }
              }
              else
              {
                  Response.Write("Please select a file to upload.");
              }
  
  
  
  
          }
      }
  }
  </code></pre>