How can I convert PDF to Flash for the web?

2k views Asked by At

This code below is used in my code behind to upload a .pdf file then convert it into a .swf(flash). The WriteToFile method saves the pdf to the server directory and is called in the Button1_Click method. In the Button1_Clicked method I created a process to execute the pdf2swf.exe that was installed with the swftools suite that converts pdf to flash readable form.

However, the downloaded pdf is not being converted to swf, which I want to use to display to my site's users in a non-downloadable form. I already know how to display the flash file (.swf), but need help with conversion.

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";
    }
}

Related Links:

  1. This link attempts the same pdf to .swf conversion

  2. This is a link to the tool pdf2swf tool that is installed with the swftools version 0.92 which i installed to do the conversion

  3. This person figured out how to get it to work but i don't understand how to make such changes: SWFTools' pdf2swf: No text converted if started from IIS-hosted website

0

There are 0 answers