引言
之前总结了在线预览几种常见解决方案,可以戳这里:
http://www.cnblogs.com/wolf-sun/p/3569960.html
http://www.cnblogs.com/wolf-sun/p/3525437.html
http://www.cnblogs.com/wolf-sun/p/3574278.html
客户突然给了比较大的文档,赫然崩溃,项目中采用的是flexpaper+swftools方式实现的,发现在pdf-》swf的时候,转了100页之后,就会出现问题,很无奈,可能客户上传的word文档有问题,客户给的文档,页面方向有横向的,也有纵向的。没办法只能想办法解决了。
最后想到了将他们一页一页的转,说实话我都疯了,几百页的文档,抽支烟回来才转完,你不疯不行啊。
之后想了用其他几种解决方案,由于客户要求文档不能被下载,被复制,要有保密性,这需求,你想保密,想安全,就别放在网上啊,别人只要想要,一张一张的截图,也能给你的文档扣下来,想当年,考研那会儿,我都干过这事,考题都是从网上一张一张截图搞下来的。现在想想,当时真sb。
单页pdf转swf
这里还是使用这篇文章中的demo:http://www.cnblogs.com/wolf-sun/p/3525437.html
然后修改PSD2SwfHelper类下的方法PDF2SWF和GetPageCount,将私有改为公有:
/// <summary>
/// PDF格式转为SWF
/// </summary>
/// <param name="pdfPath">PDF文件地址</param>
/// <param name="swfPath">生成后的SWF文件地址</param>
/// <param name="beginpage">转换开始页</param>
/// <param name="endpage">转换结束页</param>
public static bool PDF2SWF(string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
{
//swftool,首先先安装,然后将安装目录下的东西拷贝到tools目录下
string exe = HttpContext.Current.Server.MapPath("~/Bin/tools/pdf2swf.exe");
pdfPath = HttpContext.Current.Server.MapPath(pdfPath);
swfPath = HttpContext.Current.Server.MapPath(swfPath);
if (!System.IO.File.Exists(exe) || !System.IO.File.Exists(pdfPath) || System.IO.File.Exists(swfPath))
{
return false;
}
StringBuilder sb = new StringBuilder();
sb.Append(" \"" + pdfPath + "\"");
sb.Append(" -o \"" + swfPath + "\"");
sb.Append(" -s flashversion=9");
if (endpage > GetPageCount(pdfPath)) endpage = GetPageCount(pdfPath);
sb.Append(" -p " + "\"" + beginpage + "" + "-" + endpage + "\"");
sb.Append(" -j " + photoQuality);
string Command = sb.ToString();
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = exe;
p.StartInfo.Arguments = Command;
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
return true;
}
使用:
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pdfPath="PDFFile/王牌2_C#_控件查询手册.pdf"; int pageCount = PSD2swfHelper.GetPageCount(Server.MapPath(pdfPath));
for (int i = ; i <=pageCount; i++)
{
//i to i 当前页
PSD2swfHelper.PDF2SWF(pdfPath, "SWFFile/" + i.ToString() + ".swf", i, i, );
}
//这里需要虚拟路径
// PSD2swfHelper.PDF2SWF("PDFFile/王牌2_C#_控件查询手册.pdf", "SWFFile/王牌2_C#_控件查询手册.swf");
}
}
结果:
修改预览页面,flexpaper配置信息:
参考文章:http://www.blogjava.net/jforeverg/archive/2011/07/06/353813.html
http://blog.csdn.net/mishidezhu/article/details/7094490
var flashvars = {
SwfFile: "{/SWFFile/[*,0].swf,52}",//这里需要修改
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: "en_US"
};
总结
这里只是将工作中遇到的问题,记录一下,这种方式,转换速度太慢了,也许你有更好的解决方案,不妨分享一下你的解决方案,不胜感激。