Convert PDF to SWF in ASP.NET

I always wanted to guarantee that users of my application can view my published documents even if they don't have the needed application installed on their machines. To achieve this requirement and MACROMEDIA FLASH being installed on almost every browser, i got to either build a tool to convert my PDF files to flash files or to use a free tool. I came across an excellent and effective tool called SWFTOOLS. The beauty of this tool is that it can convert not just all the pdf file to swf file but it can convert a specific page also. In this way, i reduce the time needed to convert all the file and make it on demand. This tool can run using shell commands and using ASP.NET we can execute this process by using the System.Diagnostics.Process class.

When you install this tool on your local machine, copy the "font" and the PDF2SWF.exe file into a folder in your application root folder "PDF2SWF" and use the below code

int pageNumber = 1;
string fileName = "Files/1.pdf";

System.Diagnostics.Process p = new System.Diagnostics.Process();

p.StartInfo.UseShellExecute = false;

p.StartInfo.RedirectStandardOutput = true;

p.StartInfo.CreateNoWindow = true;

p.StartInfo.RedirectStandardError = true;

p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~");

p.StartInfo.FileName = HttpContext.Current.Server.MapPath("~/PDF2SWF/PDF2SWF.exe");

p.StartInfo.Arguments = "-F " + "\"" +HttpContext.Current.Server.MapPath("~/PDF2SWF/FONTS") + "\"" + " -p " + pageNumber + " " + fileName + " -o " + fileName + pageNumber + ".swf";

//Start the process

p.Start();
p.WaitForExit();
p.Close();

The above code will create an instance of the Process class, Set the working directory to the root application folder, set the filename to the exe file and send arguments to the process. you can check the tool's website to know more about the arguments list.
Now after the above code will finish executing, a new file called 11.swf will be saved in the folder which will you can use to display it in your webform.

Hope this helps,

Published 14 March 2008 07:14 PM by haissam

Comments

# alessandro said on 14 March, 2008 02:01 PM

Pingback from  alessandro

# php code and scripts » Blog Archive » Convert PDF to SWF in ASP.NET said on 14 March, 2008 05:03 PM

Pingback from  php code and scripts  » Blog Archive   » Convert PDF to SWF in ASP.NET

# jarnail said on 31 October, 2008 08:49 AM

Can this be possible in PHP. If this is possible pls help me. I hardly needed it

# Shine said on 13 August, 2009 01:46 AM

Can u provide the PHP Script !

# Akhilesh Tiwari said on 01 October, 2009 01:18 AM

No doubt, It is very helpful. But how can we set the dimension of swf on run time according to requirement.

I will very greatful if you will be provide the solution.

# Dotnet Slacker said on 28 December, 2009 05:20 AM

hi,

this is one of the dotnet slacker. I m trying to convert pdf to swf file. the code is running fine without any error but i m not seeing any swf file created.

Could you help me on this.

Thanks,

small dotnetslacker

# laynechin said on 16 September, 2010 11:13 PM

This code to open PDF in HTML

<Iframe

src = "test.pdf" width = "500" height = "800" align = "middle"> </ iframe>

This code to open PDF in Flash

on(release){getURL("mypdf.pdf", "_blank");}

Layne Chin

www.pdf-to-flash-magazine.com

# laynechin said on 16 September, 2010 11:13 PM

This code to open PDF in HTML

<Iframe

src = "test.pdf" width = "500" height = "800" align = "middle"> </ iframe>

This code to open PDF in Flash

on(release){getURL("mypdf.pdf", "_blank");}

Layne Chin

www.pdf-to-flash-magazine.com

# kmlos said on 19 September, 2011 02:04 PM

Hola:

Estoy haciendo en asp.net una aplicacion, y necesito leer los pdf de una forma mas amigable, por lo que he seguido las recomendaciones, y he utilizado swftools, a continuacion pongo el codigo, que corre, pero no convierte nada,

si me pudieran ayduar se lo agradeceria,

NOta: Esto es de vida o muerte

int numPagina = 1;

                          string cadena_archivo = "~/App_Data/11-Creating an Action.pdf";

                           System.Diagnostics.Process p = new System.Diagnostics.Process ();

                           p.StartInfo.UseShellExecute = false;

                           p.StartInfo.RedirectStandardOutput = true;

                           p.StartInfo.CreateNoWindow = true;

                           p.StartInfo.RedirectStandardError = true;

                           p.StartInfo.WorkingDirectory =Server.MapPath ("~");

                           p.StartInfo.FileName = (@"C:\swftools\pdf2swf.exe");

                           p.StartInfo.Arguments = "-F" + "\" "+ Server.MapPath (" ~/PDF2SWF/fonts ") +"\" -p" + numPagina + "" + cadena_archivo + "-o" + cadena_archivo+""+numPagina+ "swf.";

                           // Inicia el proceso

                           p.Start ();

                           p.WaitForExit ();

                           p.Close ();

# kmlos said on 19 September, 2011 02:05 PM

Me podrian ayudar en decirme cual es el error

int numPagina = 1;

                          string cadena_archivo = "~/App_Data/11-Creating an Action.pdf";

                           System.Diagnostics.Process p = new System.Diagnostics.Process ();

                           p.StartInfo.UseShellExecute = false;

                           p.StartInfo.RedirectStandardOutput = true;

                           p.StartInfo.CreateNoWindow = true;

                           p.StartInfo.RedirectStandardError = true;

                           p.StartInfo.WorkingDirectory =Server.MapPath ("~");

                           p.StartInfo.FileName = (@"C:\swftools\pdf2swf.exe");

                           p.StartInfo.Arguments = "-F" + "\" "+ Server.MapPath (" ~/PDF2SWF/fonts ") +"\" -p" + numPagina + "" + cadena_archivo + "-o" + cadena_archivo+""+numPagina+ "swf.";

                           // Inicia el proceso

                           p.Start ();

                           p.WaitForExit ();

                           p.Close ();

This site

Search

Go

This Blog

Syndication

Sponsors

  • MaximumASP