下面的代码在我的代码后面用于上传.pdf文件,然后将其转换为.swf(flash) . WriteToFile
方法将pdf保存到服务器目录,并在 Button1_Click
方法中调用 . 在 Button1_Clicked
方法中,我创建了一个执行pdf2swf.exe的进程,该程序随swftools套件一起安装,该套件将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";
}
}
相关链接: