日期:2014-05-17 浏览次数:20517 次
public IList<string> GenerateThumbnailImage(string InputFile, bool deletePDF, string filename) { return GenerateImage(InputFile, deletePDF, filename, "-dSAFER -dBATCH -dNOPAUSE -r150 -sDEVICE=jpeg -dGraphicsAlphaBits=4"); } private IList<string> GenerateImage(string InputFile, bool deletePDF, string filename,string Arguments) { IList<string> result = new List<string>(); PDFLibrary myPDFLibrary = new PDFLibrary(); int PDFPageCount = myPDFLibrary.GetPageCount(InputFile); if (PDFPageCount==0) { return result; } string OutputFile = filename; string ExtOut = Path.GetExtension(OutputFile); string partOut = OutputFile.Remove(OutputFile.Length - ExtOut.Length, ExtOut.Length); if (PDFPageCount == 1) { OutputFile=partOut+ ".jpg"; result.Add(OutputFile); if (File.Exists(OutputFile)) { File.Delete(OutputFile); } } else { for (int i = 0; i < PDFPageCount; i++) { string eachFileName = partOut + (i + 1).ToString() + ".jpg"; result.Add(eachFileName); if (File.Exists(eachFileName)) { File.Delete(eachFileName); } } OutputFile = OutputFile.Remove(OutputFile.Length - ExtOut.Length, ExtOut.Length); OutputFile += "%d.jpg"; } ProcessStartInfo info = new ProcessStartInfo(); info.CreateNoWindow = true; info.WindowStyle = ProcessWindowStyle.Hidden; info.WorkingDirectory = System.Configuration.ConfigurationManager.AppSettings["GhostScriptView"]; info.Arguments =Arguments+ @" -sOutputFile=" + OutputFile + " " + InputFile; info.FileName = @"gswin32c.exe"; Process subProcess = new Process(); subProcess.StartInfo = info; subProcess.Start(); subProcess.WaitForExit(int.MaxValue); if (deletePDF) { System.IO.File.Delete(InputFile); } return result; }