首页 > 编程 > .NET > 正文

pdf转换成jpg示例分享

2024-07-10 12:43:24
字体:
来源:转载
供稿:网友

代码如下:
using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Runtime.InteropServices; 
using System.Collections; 
/**
Convert PDF to Image Format(JPEG) using Ghostscript API

convert a pdf to jpeg using ghostscript command line:
gswin32c -q -dQUIET -dPARANOIDSAFER  -dBATCH -dNOPAUSE  -dNOPROMPT -dMaxBitmap=500000000 -dFirstPage=1 -dAlignToPixels=0 -dGridFitTT=0 -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r100x100 -sOutputFile=output.jpg test.pdf
see also:http://www.mattephraim.com/blog/2009/01/06/a-simple-c-wrapper-for-ghostscript/
and: http://www.codeproject.com/KB/cs/GhostScriptUseWithCSharp.aspx
Note:copy gsdll32.dll to system32 directory before using this ghostscript wrapper.
 * 
 */ 
namespace ConvertPDF 

    /// <summary> 
    ///  
    /// Class to convert a pdf to an image using GhostScript DLL 
    /// Credit for this code go to:Rangel Avulso 
    /// i only fix a little bug and refactor a little 
    /// http://www.hrangel.com.br/index.php/2006/12/04/converter-pdf-para-imagem-jpeg-em-c/ 
    /// </summary> 
    /// <seealso cref="http://www.hrangel.com.br/index.php/2006/12/04/converter-pdf-para-imagem-jpeg-em-c/"/> 
    class PDFConvert 
    { 
        #region GhostScript Import 
        /// <summary>Create a new instance of Ghostscript. This instance is passed to most other gsapi functions. The caller_handle will be provided to callback functions. 
        ///  At this stage, Ghostscript supports only one instance. </summary> 
        /// <param name="pinstance"></param> 
        /// <param name="caller_handle"></param> 
        /// <returns></returns> 
        [DllImport("gsdll32.dll", EntryPoint="gsapi_new_instance")] 
        private static extern int gsapi_new_instance (out IntPtr pinstance, IntPtr caller_handle); 
        /// <summary>This is the important function that will perform the conversion</summary> 
        /// <param name="instance"></param> 
        /// <param name="argc"></param> 
        /// <param name="argv"></param> 
        /// <returns></returns> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表