Reference
Using Ghostscript.net;
Using Ghostscript.NET.Rasterizer;
Need to install EXE file
public static Ghostscriptversioninfo _lastinstalledversion = null;
public static Ghostscriptrasterizer _rasterizer = null;
Pdftoimages (String Pdfinputpath, String imageoutputpath)
{
Degree of resolution
int desired_x_dpi = Convert.ToInt32 (96);
int desired_y_dpi = Convert.ToInt32 (96);
Log.writelog ("Generate Temp folder");
var destfile = GetFilePath (Pdfinputpath);
Log.writelog ("Copy PDF material");
System.IO.File.Copy (Pdfinputpath, DestFile, true);
Log.writelog ("Copy PDF Data complete");
if (System.IO.File.Exists (destfile))
{
Try
{
_lastinstalledversion = Ghostscriptversioninfo.getlastinstalledversion ( GHOSTSCRIPTLICENSE.GPL | GHOSTSCRIPTLICENSE.AFPL, GHOSTSCRIPTLICENSE.GPL);
_rasterizer = new Ghostscriptrasterizer ();
_rasterizer. Open (DestFile, _lastinstalledversion, false);
for (var i = 1; I <= endpagenum; i++)
{
String pagefilepath = Path.Combine (Imageoutputpath, ImageName + "_" + i.tostring () + "." + imageformat.tostring ());
Image img = _rasterizer. GetPage (desired_x_dpi, desired_y_dpi, i);
Img. Save (Pagefilepath, imageformat.jpeg);
}
_rasterizer. Dispose ();
}
catch (Exception ex)
{
Log.writelog ("Exception:" + ex.) ToString ());
System.IO.File.Delete (DestFile);
}
Finally
{
Log.writelog ("Finally: delete data");
System.IO.File.Delete (DestFile);
System.IO.Direc
}
<summary>
Get the newly renamed file path based on the source file path
</summary>
<param name= "FilePath" ></param>
<returns></returns>
static string GetFilePath (String filePath)
{
if (string. Isnullorwhitespace (FilePath))
{
return string. Empty;
}
Else
{
return string. Format ("{0}{1}{2}", Filepath.substring (0, filepath.lastindexof (' \ \ ') + 1), Guid.NewGuid (). ToString ("N"). Replace ("-", ""), Filepath.substring (Filepath.lastindexof ('. ')));
}
}
C#pdf cut into pictures