1: Tool preparation
swftools.exe download
http://www.swftools.org/download.html
Install to D drive
SWFTools provides a series of tools for converting various files into swf:
font2swf.exe
gif2swf.exe
jpeg2swf.exe
pdf2swf.exe
png2swf.exe
wav2swf.exe
Here we only use pdf2swf.exe
flexpaper download
http://code.google.com/p/flexpaper/
Here we use the compiled flash version of FlexPaper
2: Sample language, here are the two development environments I use as examples.
PHP example generates swf file from pdf
Copy the code code as follows:
<?php
/*
* Created on 2010-11-17
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
//Get the directory where the file is located
$dir=dirname(__FILE__) ;
//delete test file
@unlink( $dir."//test.swf" );
//Use pdf2swf conversion command
$command= "D:/SWFTools/pdf2swf.exe -t /"".$dir."//test.pdf/" -o /"".$dir."//test.swf/" -s flashversion= 9 ";
//Create shell object
$WshShell = new COM("WScript.Shell");
//Execute cmd command
$oExec = $WshShell->Run("cmd /C ". $command, 0, true);
?>
java example
Copy the code code as follows:
<%
/*
* Created on 2010-11-17
*/
//Get the directory where the file is located
String path=request.getRealPath("/");
//Use pdf2swf conversion command
String command= "D:/SWFTools/pdf2swf.exe -t /""+path+"//test.pdf/" -o /""+path+"//test.swf/" -s flashversion=9 ";
//Execute cmd command
Runtime.getRuntime().exec("cmd /c "+command);
%>
The above is how php and java convert pdf to swf. What about display? In this way we will use flexpaper. The following is the use of flexpaper. Use flexpaper to display swf.
Copy the code code as follows:
<script type="text/javascript" src="js/swfobject/swfobject.js"></script>
<script type="text/javascript">
var swfVersionStr = "10.0.0";
var xiSwfUrlStr = "playerProductInstall.swf";
var flashvars = {
SwfFile: escape("test.swf"),
Scale: 0.6,
ZoomTransition: "easeOut",
ZoomTime: 0.5,
ZoomInterval: 0.1,
FitPageOnLoad : false,
FitWidthOnLoad: true,
PrintEnabled : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : true,
PrintToolsVisible : true,
ViewModeToolsVisible : true,
ZoomToolsVisible : true,
FullScreenVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : true,
localeChain: "zh_CN"
};
var params = {
}
params.quality = "high";
params.bgcolor = "#ffffff";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
var attributes = {};
attributes.id = "FlexPaperViewer";
attributes.name = "FlexPaperViewer";
swfobject.embedSWF(
"FlexPaperViewer.swf", "flashContent",
"650", "500",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>
<body>
<div style="position:absolute;left:10px;top:10px;">
<div id="flashContent">
</div>
</div>
</body>
Through the above method, we can convert pdf into the corresponding swf file and display it through flexpaper to prevent users from downloading or copying.
The detailed parameter description of pdf2swf can be found on Baidu or Google, but it is best to specify flashversion as 9 to prevent some unexpected errors.
Not all pdfs can be converted in pdf2swf, and encrypted pdfs cannot be converted by pdf2swf.
For detailed description of flexpaper parameters, please refer to http://code.google.com/p/flexpaper/wiki/Parameters
Flexpaper commonly used API http://code.google.com/p/flexpaper/wiki/API
If there is a problem with garbled characters, it may be caused by the character set. There are many related solutions on the Internet that you can check [I have not encountered the problem of character set blocking].
There are also pictures in the pdf that may not be clear after being converted to swf.
Word, wps, txt and other documents can also be converted in this way, but the tool is not necessarily swftools
The uploaded flexpaper attachment already contains the relevant files in flexpaper. There is no need to download it again. Just download swftools and install it.
The flexpaper attachment contains two files, pdf2swf.jsp and pdf2swf.php, and flexpaper-related components that can be run in a java or php environment.