Preface
This blog post on creating PDF files in itext briefly introduces how to create a PDF file. In order to display the PDF file on a Web page, I also need to use the swftools tool to convert the PDF file to a SWF file, the SWF file is then displayed on the web page. This is a simple use of swftools. You can download the tool and install it on the http://www.swftools.org/download.html webpage. But pay attention to the downloaded version. I developed it in win7, so the Installation tool is shown in
2swf.exe is generated after installation. Add an object to the PDF folder in advance.
, This PDF file is also generated in the previous section.
Step 1
I first created a winform application.ProgramAnd then configure two paths in the configuration file. One is the PDF file path, and the other is the generated SWF file path.
App. config configuration fileCode
<? XML version = "1.0"?> <Configuration> <etettings> <! -- Store the PDF directory --> <add key = "pdfpath" value = "D: \ pdffiles \"/> <! -- Store the converted SWF directory --> <add key = "swfpath" value = "D: \ swffiles \ "/> </appsettings> <startup> <supportedruntime version =" v4.0 "SKU = ". netframework, version = v4.0 "/> </startup> </configuration>
Step 2
Search for PDF files in the PDF folder
// Scan the PDF file private string searchpdf () {string pdffile = ""; string pdfpath = appconfiguration. pdfpath; If (! Directory. exists (pdfpath) {directory. createdirectory (pdfpath);} string [] files = directory. getfiles (pdfpath); For (INT I = 0; I <files. length; I ++) {If (files [I]. endswith (". PDF ") {pdffile = files [I]; break ;}} return pdffile ;}
First, you can obtain the PDF folder of the configuration file. If you do not have this folder, you need to create one and search for the PDF files in this folder.
Step 3
Find or generate the corresponding SWF folder Based on the PDF folder
// Obtain the SWF storage directory private string getsavepathfromname (string pdffile) {string swfbasepath = appconfiguration. swfpath; string swfpath = swfbasepath + pdffile. split ('\\'). last (). replace (". PDF "," ") +" \ "; if (! Directory. exists (swfpath) {directory. createdirectory (swfpath);} return swfpath ;}
Step 4
Execute the following command to generate a SWF file by passing through ipv2swf.exe.
Private void execute (string cmd, string ARGs) {using (PROCESS p = new process () {P. startinfo. filename = cmd; p. startinfo. arguments = ARGs; p. startinfo. useshellexecute = false; // The standard output stream provided by this class is only 2 K. Do not redirect p. startinfo. redirectstandardoutput = false; p. startinfo. createnowindow = true; p. start (); p. priorityclass = processpriorityclass. normal; p. waitforexit ();}}
String cmd = "cmd2swf.exe"; string ARGs = "-T \" "+ pdffile +" \ "-O \" "+ savepath + pdffile. split ('\\'). last (). replace (". PDF "," ") +" 2.16.swf \ "-S drawonlyshapes-s flashversion = 9"; execute (CMD, argS );
Then, the file generated in the corresponding folder is as follows.
Simply convert the PDF file to the SWF file.
Of course, it is very important to use the swf.exe file. Here I put this file and the winform EXE file in the same directory for calling.
Sample Code