文件转换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
public DataResult TransformFile(string filename)
{
if (string.IsNullOrEmpty(filename))
{
return new DataResult(false, ErrorMsg: "文件名称为空!");
}

try
{
Office2Pdf office2pdf = new Office2Pdf();
string savePath = Sys.Common.Environment.SysEnvironment.GetBaseDirectory();
string sourcePath = savePath + filename;
string a = System.IO.Path.GetExtension(sourcePath); //后缀名
string folder = System.IO.Path.GetDirectoryName(sourcePath); //目录
string fname = System.IO.Path.GetFileNameWithoutExtension(sourcePath);
string pdf_targetPath = folder+"\\"+fname + ".pdf";

bool flag = true;
if (a == ".doc" || a == ".docx")
{
if (!office2pdf.DOCConvertToPDF(sourcePath, pdf_targetPath))
{
flag = false;
}
}
else if (a == ".ppt" || a == ".pptx")
{
if (!office2pdf.PPTConvertToPDF(sourcePath, pdf_targetPath))
{
flag = false;
}
}
else if (a == ".xlsx" || a == ".xls")
{
if (!office2pdf.XLSConvertToPDF(sourcePath, pdf_targetPath))
{
flag = false;
}
}
else
{
flag = false;
}

if (flag)
{
//return new DataResult { IsSuccess = true, InfoMsg = "转换成功!" };
try
{
//转flash
string cmdStr = HttpContext.Current.Server.MapPath("~/tools/pdf2swf.exe");
string pdf_sourcePath = pdf_targetPath;
string swf_targetPath = folder+"\\"+fname + ".swf";

string argsStr = " -t " + pdf_sourcePath + " -s flashversion=9 -o " + swf_targetPath;
ExcutedCmd(cmdStr, argsStr);
return new DataResult { IsSuccess = true, InfoMsg = "附件预览完成转换!" };
}
catch (Exception e1)
{
return new DataResult { IsSuccess = false, ErrorMsg = "转换swf失败!"+e1.StackTrace };
}

}
else
{
return new DataResult { IsSuccess = false, ErrorMsg = "转换pdf失败!" };
}
}
catch (Exception ee)
{
return new DataResult { IsSuccess=false, ErrorMsg=ee.StackTrace };

}

}

转Flash

1
2
3
4
5
6
7
8
9
10
private static void ExcutedCmd(string cmd, string args)
{
using (Process p = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo(cmd, args);
p.StartInfo = psi;
p.Start();
p.WaitForExit();
}
}

Js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var fp = new FlexPaperViewer(     
'FlexPaperViewer',
'viewerPlaceHolder', {
config : {
SwfFile : escape('<%=swfFilePath%>'),
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 : 'SinglePage',

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

localeChain: 'zh_CN'
}
});