FlexPaper pdf文档转换swf

本次转换是使用mvc3

 

FlexPaper下载地址 http://flexpaper.devaldi.com/download/

Swftool下载地址 http://www.swftools.org/download.html

 

运行官方的DEMO及Flexpaper的用法

 打开刚刚下载好的Flexpaper文件夹,打开里面的例子 index.html,

 (1)运行官方的例子,不能加载任何的.swf(包括例子中的swf)(如果能正常显示的话,请跳过这一步)

运行官方例子的时起,连所带的Paper.swf都不能加载成功,只见到右上角的圈圈一直在动,处于等待的状态。如下图:

 这种情况,是由于Flexpaper还没获得Adobe Flash的信任,这时你可以前住http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065 为FlexPaper添加信任.进入网页之后 ,点击左边的 Global Security Settings papel 这个选项,然后在右边(如下图)

为你的例子所在的文件夹添加信任。然后你再运行官方的例子,就会发现可以运行成功啦。

下图为文件存放的路径

pdf2swf 在SWFTOOl文件中

控制器中的代码

using System.IO;
using System.Diagnostics;

 

public ActionResult Upload()
        {
            foreach (string upload in Request.Files)
            {
                if (!HasFiles.HasFile(Request.Files[upload])) continue;

       string filename = Path.GetFileName(Request.Files[upload].FileName);
                string path = AppDomain.CurrentDomain.BaseDirectory + "files\\";
                string cmdStr = AppDomain.CurrentDomain.BaseDirectory  + "FlexPaper\\pdf2swf.exe";
                string sourcePath = @"""" + Path.Combine(path, filename) + @"""";
                string targetPath = @"""" + path + filename.Substring(0, filename.LastIndexOf(".")) + ".swf" + @"""";

//版本8无法正常显示,所有使用命令行转换为9版本
                string argsStr = "  -t " + sourcePath + " -s flashversion=9 -o " + targetPath;
                //调用新进程 进行转换
                Process p = new Process();
                ProcessStartInfo psi = new ProcessStartInfo(cmdStr, argsStr);
                p.StartInfo = psi;
                p.Start();
                p.WaitForExit();
            }
        }

页面

@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div id="files">
    <input type="file" name="FileUpload" />
    </div>
    <input type="submit" name="Submit" id="Submit" value="上传" />
}


<script type="text/javascript" src="@Url.Content("~/FlexPaper/js/flexpaper_flash.js")" ></script>
<script type="text/javascript" src="@Url.Content("~/FlexPaper/js/flexpaper_flash_debug.js")" ></script>
<script type="text/javascript" src="@Url.Content("~/FlexPaper/js/jquery.js")" ></script>

<a id="viewerPlaceHolder" style="width: 600px; height: 480px; display: block;"></a>

        <script type="text/javascript">
            //var fileURL = "使用ASP.net发送和接收消息.swf";
                var fp = new FlexPaperViewer(
            'FlexPaper/FlexPaperViewer',
            'viewerPlaceHolder',
            { config: {
                SwfFile: escape('files/使用ASP.net发送和接收消息.swf'),
                Scale: 0.6,
                ZoomTransition: 'easeOut',
                ZoomTime: 0.5,
                ZoomInterval: 0.2,
                FitPageOnLoad: true,
                FitWidthOnLoad: false,
                FullScreenAsMaxWindow: false,
                ProgressiveLoading: false,
                MinZoomSize: 0.2,
                MaxZoomSize: 5,
                SearchMatchAll: false,
                InitViewMode: 'Portrait',
                PrintPaperAsBitmap: false,

                ViewModeToolsVisible: true,
                ZoomToolsVisible: true,
                NavToolsVisible: true,
                CursorToolsVisible: true,
                SearchToolsVisible: true,

                localeChain: 'en_US'
                //localeChain: 'zh_CN'//没有解析 无用
            }
        });
        </script>

主要会出现的错误:

1.pdf2swf.exe无法转换,最新的版本可能会出现这个问题,可以换低点的版本

2.不支持中文名称;

你可能感兴趣的:(FlexPaper)