publicstaticvoidConvertPdf2Img(string input,string outputPath,refList<string> output,refstring status) {GhostscriptJpegDevice dev &#61;newGhostscriptJpegDevice();output &#61;newList<string>();try{using(GhostscriptRasterizer ra &#61;newGhostscriptRasterizer()){ra.Open(input);var cnt &#61; ra.PageCount;for(int pageNumber &#61;1; pageNumber <&#61; cnt; pageNumber&#43;&#43;){var pageFilePath &#61; Path.Combine(outputPath, Guid.NewGuid().ToString()&#43;".jpg");var img &#61; ra.GetPage(300,300, pageNumber);img.Save(pageFilePath, ImageFormat.Jpeg);output.Add(pageFilePath);img.Dispose();}}}catch(Exception ex){status &#61; ex.Message;dev &#61;null/* TODO Change to default(_) if this is not a reference type */;} }
List<Image> img &#61;newList<Image>();foreach(string str in fileList)img.Add(Image.FromFile(str));
本地运行报错&#xff0c;服务器上不报错&#xff0c;将代码优化一下
//gsdll64.dll拷贝到项目版本 var _lastInstalledVersion &#61;newGhostscriptVersionInfo($"{System.Environment.CurrentDirectory}\\gsdll64.dll"); _rasterizer.Open(inputPdfPath, _lastInstalledVersion,false);