2

下面的代码在我后面的代码中用于上传 .pdf 文件,然后将其转换为 .swf(flash)。该 WriteToFile方法将pdf保存到服务器目录并在该Button1_Click方法中调用。在该Button1_Clicked方法中,我创建了一个进程来执行随 swftools 套件安装的 pdf2swf.exe,该套件将 pdf 转换为 flash 可读形式。

但是,下载的 pdf 没有转换为 swf,我想用它以不可下载的形式向我的网站用户显示。我已经知道如何显示 Flash 文件 (.swf),但需要转换方面的帮助。

private void WriteToFile(string fileName)
{
    // Create a file

    string path = Server.MapPath("~/");           
    // string filename = FileUpload1.PostedFile.FileName;
    int fileLength = FileUpload1.PostedFile.ContentLength;
    byte[] imageBytes = new byte[fileLength];
    FileUpload1.SaveAs(path + fileName);
}


protected void Button1_Click(object sender, EventArgs e)
{
    int pageNumber = 1;
    string inputfile = FileUpload1.FileName;
    string filename = @"Sports_Events.pdf";
    WriteToFile(FileUpload1.FileName);
    string outputfile = @"pdfdoc.swf";
    System.Diagnostics.Process pdf2swfprocess = new System.Diagnostics.Process();
    // Process pdf2swfprocess = new Process();
    pdf2swfprocess.StartInfo.UseShellExecute = false;
    pdf2swfprocess.StartInfo.RedirectStandardOutput = true;
    pdf2swfprocess.StartInfo.CreateNoWindow = true;
    pdf2swfprocess.EnableRaisingEvents = false;
    pdf2swfprocess.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~");
    pdf2swfprocess.StartInfo.RedirectStandardError = true;
    pdf2swfprocess.StartInfo.FileName = HttpContext.Current.Server.MapPath("~/PDF2SWF/pdf2swf.exe");
    //pdf2swfprocess.StartInfo.Arguments = inputfile + "-o" + outputfile;
    pdf2swfprocess.StartInfo.Arguments = "\"" + HttpContext.Current.Server.MapPath("~/PDF2SWF/FONTS") + "\"" + " -p " + pageNumber + " " + filename + " -o " + filename + pageNumber + ".swf";
    if (FileUpload1.HasFile)
    {

        try
        {

            pdf2swfprocess.Start();

            pdf2swfprocess.WaitForExit();
            pdf2swfprocess.Close();
        }
        catch (System.Exception)
        {
            Error1.Text = "Error converting file";
        }

    }
    else
    {
        Error1.Text = "The selected file does not exist";
    }
}

相关链接:

  1. 此链接尝试将相同的 pdf 转换为 .swf

  2. 这是工具 pdf2swf 工具的链接,该工具与我安装的 swftools 版本 0.92 一起安装以进行转换

  3. 这个人想出了如何让它工作,但我不明白如何做出这样的改变:SWFTools' pdf2swf: No text conversion if started from IIS-hosted website

4

0 回答 0