校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁(yè) > 知識(shí)庫(kù) > pdf轉(zhuǎn)換成jpg示例分享

pdf轉(zhuǎn)換成jpg示例分享

熱門(mén)標(biāo)簽:百度地圖怎樣做地圖標(biāo)注 征途美甲店地圖標(biāo)注 昆明語(yǔ)音電銷(xiāo)機(jī)器人價(jià)格 400電話如何申請(qǐng)取消 電銷(xiāo)語(yǔ)音機(jī)器人型號(hào)參數(shù) 騰訊地圖標(biāo)注手機(jī) 太原400電話上門(mén)辦理 柳州電銷(xiāo)機(jī)器人公司 浦發(fā)電話機(jī)器人提醒還款

復(fù)制代碼 代碼如下:

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> 
        [DllImport("gsdll32.dll", EntryPoint="gsapi_init_with_args")] 
        private static extern int gsapi_init_with_args (IntPtr instance, int argc, IntPtr argv); 
        /// summary> 
        /// Exit the interpreter. This must be called on shutdown if gsapi_init_with_args() has been called, and just before gsapi_delete_instance().  
        /// /summary> 
        /// param name="instance">/param> 
        /// returns>/returns> 
        [DllImport("gsdll32.dll", EntryPoint="gsapi_exit")] 
        private static extern int gsapi_exit (IntPtr instance); 
        /// summary> 
        /// Destroy an instance of Ghostscript. Before you call this, Ghostscript must have finished. If Ghostscript has been initialised, you must call gsapi_exit before gsapi_delete_instance.  
        /// /summary> 
        /// param name="instance">/param> 
        [DllImport("gsdll32.dll", EntryPoint="gsapi_delete_instance")] 
        private static extern void gsapi_delete_instance (IntPtr instance); 
        #endregion 
        #region Variables 
        private string _sDeviceFormat; 
        private int _iWidth; 
        private int _iHeight; 
        private int _iResolutionX; 
        private int _iResolutionY; 
        private int _iJPEGQuality; 
        private Boolean _bFitPage; 
        private IntPtr _objHandle; 
        #endregion 
        #region Proprieties 
        public string OutputFormat 
        { 
            get { return _sDeviceFormat; } 
            set { _sDeviceFormat = value; } 
        } 
        public int Width 
        { 
            get { return _iWidth; } 
            set { _iWidth = value; } 
        } 
        public int Height 
        { 
            get { return _iHeight; } 
            set { _iHeight = value; } 
        } 
        public int ResolutionX 
        { 
            get { return _iResolutionX; } 
            set { _iResolutionX = value; } 
        } 
        public int ResolutionY 
        { 
            get { return _iResolutionY; } 
            set { _iResolutionY = value; } 
        } 
        public Boolean FitPage 
        { 
            get { return _bFitPage; } 
            set { _bFitPage = value; } 
        } 
        /// summary>Quality of compression of JPG/summary> 
        public int JPEGQuality 
        { 
            get { return _iJPEGQuality; } 
            set { _iJPEGQuality = value; } 
        } 
        #endregion 
        #region Init 
        public PDFConvert(IntPtr objHandle) 
        { 
            _objHandle = objHandle; 
        } 
        public PDFConvert() 
        { 
            _objHandle = IntPtr.Zero; 
        } 
        #endregion 
        private byte[] StringToAnsiZ(string str) 
        { 
            //' Convert a Unicode string to a null terminated Ansi string for Ghostscript. 
            //' The result is stored in a byte array. Later you will need to convert 
            //' this byte array to a pointer with GCHandle.Alloc(XXXX, GCHandleType.Pinned) 
            //' and GSHandle.AddrOfPinnedObject() 
            int intElementCount; 
            int intCounter; 
            byte[] aAnsi; 
            byte bChar; 
            intElementCount = str.Length; 
            aAnsi = new byte[intElementCount+1]; 
            for(intCounter = 0; intCounter intElementCount;intCounter++) 
            { 
                bChar = (byte)str[intCounter]; 
                aAnsi[intCounter] = bChar; 
            } 
            aAnsi[intElementCount] = 0; 
            return aAnsi; 
        } 
        /// summary>Convert the file!/summary> 
        public void Convert(string inputFile,string outputFile, 
            int firstPage, int lastPage, string deviceFormat, int width, int height) 
        { 
            //Avoid to work when the file doesn't exist 
            if (!System.IO.File.Exists(inputFile)) 
            { 
                System.Windows.Forms.MessageBox.Show(string.Format("The file :'{0}' doesn't exist",inputFile)); 
                return; 
            } 
            int intReturn; 
            IntPtr intGSInstanceHandle; 
            object[] aAnsiArgs; 
            IntPtr[] aPtrArgs; 
            GCHandle[] aGCHandle; 
            int intCounter; 
            int intElementCount; 
            IntPtr callerHandle; 
            GCHandle gchandleArgs; 
            IntPtr intptrArgs; 
            string[] sArgs = GetGeneratedArgs(inputFile,outputFile, 
                firstPage, lastPage, deviceFormat, width, height); 
            // Convert the Unicode strings to null terminated ANSI byte arrays 
            // then get pointers to the byte arrays. 
            intElementCount = sArgs.Length; 
            aAnsiArgs = new object[intElementCount]; 
            aPtrArgs = new IntPtr[intElementCount]; 
            aGCHandle = new GCHandle[intElementCount]; 
            // Create a handle for each of the arguments after  
            // they've been converted to an ANSI null terminated 
            // string. Then store the pointers for each of the handles 
            for(intCounter = 0; intCounter intElementCount; intCounter++) 
            { 
                aAnsiArgs[intCounter] = StringToAnsiZ(sArgs[intCounter]); 
                aGCHandle[intCounter] = GCHandle.Alloc(aAnsiArgs[intCounter], GCHandleType.Pinned); 
                aPtrArgs[intCounter] = aGCHandle[intCounter].AddrOfPinnedObject(); 
            } 
            // Get a new handle for the array of argument pointers 
            gchandleArgs = GCHandle.Alloc(aPtrArgs, GCHandleType.Pinned); 
            intptrArgs = gchandleArgs.AddrOfPinnedObject(); 
            intReturn = gsapi_new_instance(out intGSInstanceHandle, _objHandle); 
            callerHandle = IntPtr.Zero; 
            try 
            { 
                intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs); 
            } 
            catch (Exception ex) 
            { 
                //System.Windows.Forms.MessageBox.Show(ex.Message); 

            } 
            finally 
            { 
                for (intCounter = 0; intCounter intReturn; intCounter++) 
                { 
                    aGCHandle[intCounter].Free(); 
                } 
                gchandleArgs.Free(); 
                gsapi_exit(intGSInstanceHandle); 
                gsapi_delete_instance(intGSInstanceHandle); 
            } 
        } 
        private string[] GetGeneratedArgs(string inputFile, string outputFile, 
            int firstPage, int lastPage, string deviceFormat, int width, int height) 
        { 
            this._sDeviceFormat = deviceFormat; 
            this._iResolutionX = width; 
            this._iResolutionY = height; 
            // Count how many extra args are need - HRangel - 11/29/2006, 3:13:43 PM 
            ArrayList lstExtraArgs = new ArrayList(); 
            if ( _sDeviceFormat=="jpg" _iJPEGQuality > 0 _iJPEGQuality 101) 
                lstExtraArgs.Add("-dJPEGQ=" + _iJPEGQuality); 
            if (_iWidth > 0 _iHeight > 0) 
                lstExtraArgs.Add("-g" + _iWidth + "x" + _iHeight); 
            if (_bFitPage) 
                lstExtraArgs.Add("-dPDFFitPage"); 
            if (_iResolutionX > 0) 
            { 
                if (_iResolutionY > 0) 
                    lstExtraArgs.Add("-r" + _iResolutionX + "x" + _iResolutionY); 
                else 
                    lstExtraArgs.Add("-r" + _iResolutionX); 
            } 
            // Load Fixed Args - HRangel - 11/29/2006, 3:34:02 PM 
            int iFixedCount = 17; 
            int iExtraArgsCount = lstExtraArgs.Count; 
            string[] args = new string[iFixedCount + lstExtraArgs.Count]; 
            /*
            // Keep gs from writing information to standard output
        "-q",                     
        "-dQUIET",

        "-dPARANOIDSAFER", // Run this command in safe mode
        "-dBATCH", // Keep gs from going into interactive mode
        "-dNOPAUSE", // Do not prompt and pause for each page
        "-dNOPROMPT", // Disable prompts for user interaction           
        "-dMaxBitmap=500000000", // Set high for better performance

        // Set the starting and ending pages
        String.Format("-dFirstPage={0}", firstPage),
        String.Format("-dLastPage={0}", lastPage),   

        // Configure the output anti-aliasing, resolution, etc
        "-dAlignToPixels=0",
        "-dGridFitTT=0",
        "-sDEVICE=jpeg",
        "-dTextAlphaBits=4",
        "-dGraphicsAlphaBits=4",
            */ 
            args[0]="pdf2img";//this parameter have little real use 
            args[1]="-dNOPAUSE";//I don't want interruptions 
            args[2]="-dBATCH";//stop after 
            //args[3]="-dSAFER"; 
            args[3] = "-dPARANOIDSAFER"; 
            args[4]="-sDEVICE="+_sDeviceFormat;//what kind of export format i should provide 
            args[5] = "-q"; 
            args[6] = "-dQUIET"; 
            args[7] = "-dNOPROMPT"; 
            args[8] = "-dMaxBitmap=500000000"; 
            args[9] = String.Format("-dFirstPage={0}", firstPage); 
            args[10] = String.Format("-dLastPage={0}", lastPage); 
            args[11] = "-dAlignToPixels=0"; 
            args[12] = "-dGridFitTT=0"; 
            args[13] = "-dTextAlphaBits=4"; 
            args[14] = "-dGraphicsAlphaBits=4"; 
            //For a complete list watch here: 
            //http://pages.cs.wisc.edu/~ghost/doc/cvs/Devices.htm 
            //Fill the remaining parameters 
            for (int i=0; i iExtraArgsCount; i++) 
            { 
                args[15+i] = (string) lstExtraArgs[i]; 
            } 
            //Fill outputfile and inputfile 
            args[15 + iExtraArgsCount] = string.Format("-sOutputFile={0}",outputFile); 
            args[16 + iExtraArgsCount] = string.Format("{0}",inputFile); 
            return args; 
        } 
        public void pdf2jpgTest() 
        {             
            this.Convert(@"C://tmp//pdfimg//test1.pdf",@"C://tmp//pdfimg//out.jpg",1,1,"jpeg",100,100); 
            //this.Convert(@"C://tmp//pdfimg//test.pdf", @"C://tmp//pdfimg//out2.jpg", 291, 291, "jpeg", 800, 800); 
        } 
    } 

測(cè)試WinForm:

可以采用下面的方式測(cè)試調(diào)用上面的功能,如:

復(fù)制代碼 代碼如下:

 PDFConvert convertor = new PDFConvert();
 convertor.pdf2jpgTest();
 

復(fù)制代碼 代碼如下:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using ConvertPDF; 
namespace PDF2Img 

    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 

        } 
        private void button1_Click(object sender, EventArgs e) 
        { 
            PDFConvert convertor = new PDFConvert(); 
            convertor.pdf2jpgTest(); 
            Image img = Image.FromFile(@"C://tmp//pdfimg//out.jpg"); 
            myBitmap = new Bitmap(img); 

            Graphics G = this.CreateGraphics(); 
            GraphicsUnit GU = G.PageUnit; 
            BMPContainer = myBitmap.GetBounds(ref GU); //X,Y = 0 

           // Graphics g = this.CreateGraphics(); 
            //g.DrawImage(myBitmap, 1, 1); 
            this.Invalidate(); 
        } 
        private Bitmap myBitmap; 
        private RectangleF BMPContainer; 
        protected override void OnPaint(PaintEventArgs e) 
        { 
            Graphics G = e.Graphics; 
            if (myBitmap != null) 
            {            
                G.DrawImage(myBitmap, BMPContainer); 
            } 
            base.OnPaint(e); 
        } 
    } 
}

標(biāo)簽:江蘇 陽(yáng)泉 新疆 張家界 蘭州 德陽(yáng) 白山 天門(mén)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《pdf轉(zhuǎn)換成jpg示例分享》,本文關(guān)鍵詞  pdf,轉(zhuǎn),換成,jpg,示例,分享,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《pdf轉(zhuǎn)換成jpg示例分享》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于pdf轉(zhuǎn)換成jpg示例分享的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃
    欧美大尺度电影在线| 中文字幕精品三区| 日韩国产在线观看| 色8久久精品久久久久久蜜| 国产日韩v精品一区二区| 久久国产人妖系列| 日韩欧美一区二区免费| 日本欧美一区二区三区| 欧美人牲a欧美精品| 亚洲一二三区视频在线观看| 在线免费观看日本欧美| 亚洲色图在线视频| 91免费版pro下载短视频| 亚洲欧美韩国综合色| 日本电影欧美片| 亚洲精品久久7777| 欧美优质美女网站| 亚洲成人激情自拍| 91精品国产乱| 免费在线一区观看| 久久久久成人黄色影片| 国产成人综合精品三级| 国产精品毛片无遮挡高清| 成人久久视频在线观看| 亚洲三级在线免费观看| 91成人免费电影| 亚洲成av人片一区二区梦乃| 日韩一级精品视频在线观看| 麻豆视频一区二区| 国产午夜亚洲精品不卡| 99久久久无码国产精品| 亚洲一区二区在线播放相泽| 制服丝袜中文字幕亚洲| 精品在线一区二区三区| 日本一区二区三区免费乱视频| 成人av资源下载| 夜夜爽夜夜爽精品视频| 欧美精品电影在线播放| 狠狠色狠狠色合久久伊人| 中文字幕精品一区 | 亚洲成a人在线观看| 777色狠狠一区二区三区| 精品一区二区在线看| 国产丝袜在线精品| 91蜜桃在线观看| 日本午夜精品一区二区三区电影| 久久久亚洲精华液精华液精华液 | 欧美午夜精品久久久久久超碰| 偷拍一区二区三区四区| 精品免费视频.| 不卡一区二区中文字幕| 亚洲午夜免费福利视频| 精品日韩在线一区| 97se亚洲国产综合在线| 天天亚洲美女在线视频| 国产午夜久久久久| 91麻豆自制传媒国产之光| 五月激情综合网| 久久久99精品久久| 欧美日韩一级片网站| 国产在线一区二区综合免费视频| 综合久久久久综合| 91精品国产一区二区三区| 成人免费黄色在线| 天堂久久一区二区三区| 久久一日本道色综合| 在线观看欧美精品| 国产一区999| 亚洲一区二区三区免费视频| 久久久久久免费| 欧美日本高清视频在线观看| 丁香天五香天堂综合| 亚洲mv在线观看| 国产精品国产三级国产三级人妇| 3d成人动漫网站| 色综合咪咪久久| 精品一区二区三区免费| 亚洲一本大道在线| 欧美激情中文字幕| 日韩欧美在线一区二区三区| 色综合色狠狠综合色| 国产精品1区2区3区在线观看| 亚洲va韩国va欧美va精品| 中文字幕欧美国产| 日韩一卡二卡三卡四卡| 一本到不卡精品视频在线观看| 国产毛片精品视频| 日本亚洲一区二区| 一区二区不卡在线播放| 国产精品入口麻豆原神| 欧美mv日韩mv亚洲| 在线播放国产精品二区一二区四区 | 视频一区视频二区中文| 最新中文字幕一区二区三区| 欧美成人性战久久| 欧美夫妻性生活| 91久久精品一区二区| 懂色av一区二区三区蜜臀| 麻豆精品新av中文字幕| 亚洲成av人片在线| 一区二区三区四区乱视频| 国产免费成人在线视频| 精品国产91洋老外米糕| 欧美一区二区成人| 欧美在线观看视频一区二区三区| 97久久精品人人做人人爽 | 蜜桃视频一区二区三区在线观看 | 亚洲国产日日夜夜| 亚洲视频一二三区| 国产精品白丝在线| 国产欧美综合色| 久久精品人人爽人人爽| 精品国产伦一区二区三区观看体验| 欧美精品丝袜久久久中文字幕| 在线观看网站黄不卡| 99久久久无码国产精品| 成人av在线影院| 成人avav影音| 99综合影院在线| 97se亚洲国产综合自在线不卡| 成人av午夜电影| 白白色 亚洲乱淫| 99综合影院在线| 成人动漫一区二区在线| 成人深夜视频在线观看| 成人激情免费视频| 成人涩涩免费视频| 成人激情小说网站| 91香蕉视频黄| 色综合久久中文字幕| 一本大道久久a久久精品综合| 91视视频在线直接观看在线看网页在线看| 福利一区福利二区| 丁香天五香天堂综合| 成人三级在线视频| 成人av午夜影院| 91小宝寻花一区二区三区| 91黄视频在线| 欧美日韩视频第一区| 中文字幕一区二区视频| 亚洲欧美色一区| 一区二区三区丝袜| 午夜久久久久久电影| 日韩电影免费一区| 精品一区二区精品| 国产精品一区二区黑丝| 国产白丝网站精品污在线入口| 国产成人精品在线看| 99riav一区二区三区| 欧美丝袜丝nylons| 91精品国产高清一区二区三区蜜臀| 日韩你懂的在线播放| 精品电影一区二区| 欧美极品美女视频| 亚洲欧美日韩一区| 亚洲精品乱码久久久久久黑人| 亚洲成在线观看| 久草精品在线观看| 国产精品亚洲人在线观看| 成人毛片视频在线观看| 91久久免费观看| 欧美一级一级性生活免费录像| 欧美精品一区二区在线观看| 中文字幕精品一区二区三区精品| 亚洲裸体xxx| 日韩中文字幕亚洲一区二区va在线 | 激情小说亚洲一区| 成人国产精品免费观看视频| 欧美最新大片在线看| 日韩一级二级三级| 国产精品久久久一区麻豆最新章节| 亚洲尤物视频在线| 久久精品国产精品亚洲精品| 国产xxx精品视频大全| 在线观看中文字幕不卡| 日韩一区二区视频在线观看| 国产人妖乱国产精品人妖| 亚洲精品高清在线观看| 蜜桃在线一区二区三区| 成人av网站免费| 在线播放中文一区| 日本一区二区三区免费乱视频| 亚洲无线码一区二区三区| 视频在线在亚洲| 色老汉av一区二区三区| 91久久精品网| 欧美一区二区久久久| 欧美成人艳星乳罩| 亚洲欧美日韩电影| 麻豆国产一区二区| 91麻豆免费观看| 欧美刺激午夜性久久久久久久| 中文字幕一区不卡| 蜜臀av一级做a爰片久久| 99在线精品视频| 精品久久久久久无| 一区二区三区四区高清精品免费观看| 精品综合免费视频观看| 91高清在线观看| 久久久综合网站|