文件转pdf ---pdf转swf --swf在页面显示 http://pan.baidu.com/s/1o88NSaI

1 using Aspose.Cells;//引用 2 using Aspose.Slides;//引用 3 using Aspose.Words;//引用 4 using System; 5 using System.Collections.Generic; 6 using System.IO; 7 using System.Linq; 8 using System.Text; 9 using System.Web; 10 11 namespace PDF3 12 { 13 public class ConverOffice 14 { 15 /// <summary> 16 /// doc转其他格式 17 /// </summary> 18 /// <param name="file">doc全路径:F:\FlexPaper未整理资源\PDF\Pdf3\Office\c.doc</param> 19 /// <param name="fileName">pdf全部径:F:\FlexPaper未整理资源\PDF\Pdf3\Office\c.pdf</param> 20 /// <param name="format">格式</param> 21 /// <returns></returns> 22 public static bool CoverDocByFormat(string file, string fileName, Aspose.Words.SaveFormat format) 23 { 24 bool isSus = false; 25 try 26 { 27 if (IsExists(file)) 28 { 29 Document doc = new Document(file); 30 doc.Save(fileName, format); 31 isSus = true; 32 } 33 } 34 catch (Exception ex) 35 { 36 37 } 38 return isSus; 39 } 40 /// <summary> 41 /// xls\xlsx转pdf 42 /// </summary> 43 /// <param name="file"></param> 44 /// <param name="fileName"></param> 45 /// <returns></returns> 46 public static bool ExcelToPdf(string file, string fileName) 47 { 48 bool isSus = false; 49 try 50 { 51 if (IsExists(file)) 52 { 53 Workbook excel = new Workbook(file); 54 excel.Save(fileName, Aspose.Cells.SaveFormat.Pdf); isSus = true; 55 } 56 } 57 catch (Exception ex) 58 { 59 60 } 61 return isSus; 62 } 63 /// <summary> 64 /// ppt转pdf 65 /// </summary> 66 /// <param name="file"></param> 67 /// <param name="fileName"></param> 68 /// <returns></returns> 69 public static bool PPtToPdf(string file, string fileName) 70 { 71 bool isSus = false; 72 try 73 { 74 if (IsExists(file)) 75 { 76 77 Workbook excel = new Workbook(file); 78 excel.Save(fileName, Aspose.Cells.SaveFormat.Pdf); 79 } 80 } 81 catch (Exception ex) 82 { 83 84 } 85 return isSus; 86 } 87 /// <summary> 88 /// ppt转pdf 89 /// </summary> 90 /// <param name="file"></param> 91 /// <param name="fileName"></param> 92 /// <returns></returns> 93 public static bool PPtToPdf2(string file, string fileName) 94 { 95 bool isSus = false; 96 try 97 { 98 if (IsExists(file)) 99 { 100 Presentation ppt = new Presentation(file); 101 ppt.Save(fileName, Aspose.Slides.Export.SaveFormat.Pdf); 102 } 103 } 104 catch (Exception ex) 105 { 106 107 } 108 return isSus; 109 } 110 public static bool IsExists(string path) 111 { 112 if (File.Exists(path)) 113 { 114 return true; 115 } 116 return false; 117 } 118 } 119 public class SwfHelp 120 { 121 /// <summary> 122 /// 123 /// </summary> 124 /// <param name="pdfPath">pdf全路径:F:\FlexPaper未整理资源\PDF\Pdf3\Office\c.pdf</param> 125 /// <param name="swfPath">swf全路径:F:\FlexPaper未整理资源\PDF\Pdf3\Office\c.swf</param> 126 /// <param name="page">未知?? </param> 127 /// <param name="type">转换在类型</param> 128 /// <returns></returns> 129 public static bool ConvertToSwf(string pdfPath, string swfPath, int page, string type) 130 { 131 try 132 { 133 string exe = null; 134 StringBuilder sb = new StringBuilder(); 135 if (type == ".pdf") 136 { 137 exe = HttpContext.Current.Server.MapPath("~/Bin/SWFTools/pdf2swf.exe"); 138 //exe = @"F:\PDF\Word\bin\swftools\pdf2swf.exe"; 139 sb.Append(" -o \"" + swfPath + "\"");//output 140 sb.Append(" -z"); 141 sb.Append(" -s flashversion=9");//flash version 142 sb.Append(" -s disablelinks");//禁止PDF里面的链接 143 //sb.Append(" -p " + "1" + "-" + page);//page range 144 sb.Append(" -T 9"); 145 sb.Append(" -j 100");//Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85) 146 sb.Append(" \"" + pdfPath + "\"");//input 147 } 148 else if (type == ".png") 149 { 150 //exe = HttpContext.Current.Server.MapPath("~/Bin/png2swf.exe"); 151 sb.Append(" \"" + pdfPath + "\""); 152 sb.Append(" -o \"" + swfPath + "\""); 153 sb.Append(" -T 9"); 154 sb.Append(" -j 100"); 155 } 156 else if (type == ".jpg") 157 { 158 //exe = HttpContext.Current.Server.MapPath("~/Bin/jpeg2swf.exe"); 159 sb.Append(" \"" + pdfPath + "\""); 160 sb.Append(" -o \"" + swfPath + "\""); 161 sb.Append(" -T 9"); 162 sb.Append(" -j 100"); 163 } 164 else if (type == ".gif") 165 { 166 //exe = HttpContext.Current.Server.MapPath("~/Bin/gif2swf.exe"); 167 sb.Append(" \"" + pdfPath + "\""); 168 sb.Append(" -o \"" + swfPath + "\""); 169 sb.Append(" -T 9"); 170 sb.Append(" -j 100"); 171 } 172 if (!File.Exists(exe)) 173 { 174 throw new ApplicationException("Can not find: " + exe); 175 } 176 System.Diagnostics.Process proc = new System.Diagnostics.Process(); 177 proc.StartInfo.FileName = exe; 178 proc.StartInfo.Arguments = sb.ToString(); 179 proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 180 proc.Start(); 181 proc.WaitForExit(); 182 proc.Close(); 183 return true; 184 185 } 186 catch (Exception ex) 187 { 188 return false; 189 190 } 191 192 193 } 194 } 195 }
需要文件资源:
Aspose.Cells.dll Aspose.Slides.dll Aspose.Words.dll
前台:FlexPaper相关文件

浙公网安备 33010602011771号