Convert PDF to SwF using swftools

Source: Internet
Author: User

Package com. Iori. webapp. util;

Import java. Io. bufferedreader;
Import java. Io. ioexception;
Import java. Io. inputstream;
Import java. Io. inputstreamreader;

Public class extends 2swfutil {
 
/**
* Use the swftools tool to convert a PDF file to a SWF file. The converted SWF file has the same name as the PDF file.
* @ Author Iori
* @ Param filedir file storage path (including file name)
* @ Param exepath converter installation path
* @ Throws ioexception
*/
Public static synchronized void %2swf (string filedir, string exepath) throws ioexception {
// File path
String filepath = filedir. substring (0, filedir. lastindexof ("/"));
// File name without suffix
String filename = filedir. substring (filepath. Length () + 1), filedir. lastindexof ("."));
Process pro = NULL;
If (iswindowssystem ()){
// For Windows
// Command line
String cmd = exepath + "/" "+ filedir +"/"-O/" "+ filepath +"/"+ filename +". SWF /"";
// Return the created process object after runtime execution
Pro = runtime.getruntime(cmd.exe C (CMD );
} Else {
// In Linux, the path cannot contain spaces and must not contain double quotation marks. Otherwise, the process cannot be created.
String [] cmd = new string [3];
CMD [0] = exepath;
CMD [1] = filedir;
CMD [2] = filepath + "/" + filename + ". SWF ";
// Return the created process object after runtime execution
Pro = runtime.getruntime(cmd.exe C (CMD );
}
// Read the CMD output once, or do not flush the file (multi-thread)
New dooutput (PRO. getinputstream (). Start ();
New dooutput (PRO. geterrorstream (). Start ();
Try {
// Call the waitfor method to block the current process until the CMD execution is complete.
Pro. waitfor ();
} Catch (interruptedexception e ){
E. printstacktrace ();
}
}
 
/**
* Determine if it is a Windows Operating System
* @ Author Iori
* @ Return
*/
Private Static Boolean iswindowssystem (){
String P = system. getproperty ("OS. Name ");
Return P. tolowercase (). indexof ("Windows")> = 0? True: false;
}
 
/**
* Multithreading internal class
* Read the standard output stream and error output stream of the CMD process during conversion. This is done because if the process does not read the stream, it will be deadlocked.
* @ Author Iori
*/
Private Static class dooutput extends thread {
Public inputstream is;

// Constructor
Public dooutput (inputstream is ){
This. Is = is;
}

Public void run (){
Bufferedreader BR = new bufferedreader (New inputstreamreader (this. Is ));
String STR = NULL;
Try {
// The stream content is not processed here, but it is read once.
While (STR = Br. Readline ())! = NULL );
} Catch (ioexception e ){
E. printstacktrace ();
} Finally {
If (BR! = NULL ){
Try {
BR. Close ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
}
}
}
 
/**
* Test the main method.
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Converter installation path
String exepath = "C:/swftools/ipv2swf.exe ";
Try {
Listen 2swfutil%2swf ("C:/test%", exepath );
} Catch (ioexception e ){
System. Err. println ("Conversion error! ");
E. printstacktrace ();
}
}
}

 

 

 

 

//// // PHP code

 

PHP code <? Php <br/>/* <br/> * created on 2010-11-17 <br/> * to change the template for this generated file go to <br/> * window-preferences-phpeclipse-PHP-code templates <br/> */<br/> // obtain the directory where the file is located <br/> $ dir = dirname (_ file __ ); <br/> // Delete the test file <br/> @ unlink ($ dir. "// test.swf"); <br/> // use the export 2swf conversion command <br/> $ command = "D:/swftools/export 2swf.exe-T /"". $ dir. "// testbench/"-O /"". $ dir. "// test.swf /"- S flashversion = 9 "; <br/> // create a shell object <br/> $ wshshell = new COM (" wscript. shell "); <br/> // run the CMD command <br/> $ oexec = $ wshshell-> Run (" CMD/C ". $ command, 0, true); <br/>?> 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.