0

目標は、.ppt をアップロードして .pdf に変換し、それをユーザーに表示することです。

今のところ、問題なくアップロードして変換できます。コード ビハインドでこれら 2 行のコメントを外すと、全画面表示になります。

「asp:Image」またはその他の非フルスクリーンのものの中に .pdf を表示する方法はありますか?

私のフロントはこれです:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs"  Inherits="WebApplication1._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">


            <input type="file" id=File1 name=File1 runat="server" />
            <asp:Button id="b1" Text="Upload" OnCLick="DoUpload" runat="server" />

           <asp:Image ID="img" runat="server"  AlternateText="" Width="400" Height="400" />


   </asp:Content>

私のコードビハインドはこれです

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)&&(File1.PostedFile.ContentLength>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.");
            }




        }
    }
}
4

1 に答える 1