C#pdf cut into pictures

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.