. NET PDF to Picture

Source: Internet
Author: User

With a cracked version of the O2S.Components.PDFRender4NET.dll plugin, simple reference can be

     Public Static classPdftoimage { Public StaticMemoryStream Getpdfimagepagestream (stringPdfinputpath,intPageIndex, ImageFormat format,intwidth = the,intHeight =2560,intQuality =Ten)        {            Try            {                //PDF Processing PluginPdffile Pdffile =Pdffile.open (Pdfinputpath); intTotal =Pdffile.pagecount; #regionPrevent exception parametersif(PageIndex <0) {PageIndex=0; }                if(PageIndex >Total ) {PageIndex= Total-1; }                if(Quality <1) {Quality=1; }                if(Quality >Ten) {Quality=Ten; }                if(Width <=0) {width=1; }                if(Height <=0) {Height=1; }                #endregion                //PDF Conversion PicturesSizeF pageSize =pdffile.getpagesize (PageIndex); Bitmap Pageimage= Pdffile.getpageimage (PageIndex, About*quality); MemoryStream Ms=NewMemoryStream ();                Pageimage.save (MS, format); //OriginalImage img = Image.fromstream (MS,true); DoubleRatio = (Double) Width/(Double) height; DoubleOratio = (Double) img. Width/(Double) img.                Height; intSbwidth =0; intSbheight =0; intOutX =0; intOuty =0; if(Oratio <ratio) {Sbwidth= (int) (IMG. Width * (Double) Height/(Double) (IMG.                    Height)); Sbheight=height; OutX= (width-sbwidth)/2; }                Else{sbheight= (int) (IMG. Height * (Double) Width/(Double) (IMG.                    Width)); Sbwidth=width; Outy= (height-sbheight)/2; }                //ZoomImage sbimg =NewBitmap (Sbwidth, sbheight); Graphics Sbgra=graphics.fromimage (SBIMG); Sbgra.interpolationmode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; Sbgra.smoothingmode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;                Sbgra.clear (Color.White); Sbgra.drawimage (IMG,NewSystem.Drawing.Rectangle (0,0, Sbwidth, Sbheight),NewSystem.Drawing.Rectangle (0,0, IMG. Width, IMG.                Height), System.Drawing.GraphicsUnit.Pixel); //FillerImage outimg =NewSystem.Drawing.Bitmap (width, height); Graphics Outgra=System.Drawing.Graphics.FromImage (OUTIMG); Outgra.interpolationmode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; Outgra.smoothingmode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;                Outgra.clear (Color.White); Outgra.drawimage (sbimg,NewSystem.Drawing.Rectangle (OutX, Outy, Sbwidth, Sbheight),NewSystem.Drawing.Rectangle (0,0, Sbwidth, sbheight), System.Drawing.GraphicsUnit.Pixel); MemoryStream Outms=NewMemoryStream ();                Outimg.save (OUTMS, format);                Sbimg.dispose ();                Outimg.dispose (); Img.                Dispose (); returnOutms; }            Catch(Exception ex) {}return NewMemoryStream (); }         Public StaticMemoryStream Getpdfimagepagestream (Stream stream,intPageIndex, ImageFormat format,intwidth = the,intHeight =2560,intQuality =Ten)        {            Try            {                //PDF Processing PluginPdffile Pdffile =Pdffile.open (stream); intTotal =Pdffile.pagecount; #regionPrevent exception parametersif(PageIndex <0) {PageIndex=0; }                if(PageIndex >Total ) {PageIndex= Total-1; }                if(Quality <1) {Quality=1; }                if(Quality >Ten) {Quality=Ten; }                if(Width <=0) {width=1; }                if(Height <=0) {Height=1; }                #endregion                //PDF Conversion PicturesSizeF pageSize =pdffile.getpagesize (PageIndex); Bitmap Pageimage= Pdffile.getpageimage (PageIndex, About*quality); MemoryStream Ms=NewMemoryStream ();                Pageimage.save (MS, format); //OriginalImage img = Image.fromstream (MS,true); DoubleRatio = (Double) Width/(Double) height; DoubleOratio = (Double) img. Width/(Double) img.                Height; intSbwidth =0; intSbheight =0; intOutX =0; intOuty =0; if(Oratio <ratio) {Sbwidth= (int) (IMG. Width * (Double) Height/(Double) (IMG.                    Height)); Sbheight=height; OutX= (width-sbwidth)/2; }                Else{sbheight= (int) (IMG. Height * (Double) Width/(Double) (IMG.                    Width)); Sbwidth=width; Outy= (height-sbheight)/2; }                //ZoomImage sbimg =NewBitmap (Sbwidth, sbheight); Graphics Sbgra=graphics.fromimage (SBIMG); Sbgra.interpolationmode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; Sbgra.smoothingmode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;                Sbgra.clear (Color.White); Sbgra.drawimage (IMG,NewSystem.Drawing.Rectangle (0,0, Sbwidth, Sbheight),NewSystem.Drawing.Rectangle (0,0, IMG. Width, IMG.                Height), System.Drawing.GraphicsUnit.Pixel); //FillerImage outimg =NewSystem.Drawing.Bitmap (width, height); Graphics Outgra=System.Drawing.Graphics.FromImage (OUTIMG); Outgra.interpolationmode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; Outgra.smoothingmode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;                Outgra.clear (Color.White); Outgra.drawimage (sbimg,NewSystem.Drawing.Rectangle (OutX, Outy, Sbwidth, Sbheight),NewSystem.Drawing.Rectangle (0,0, Sbwidth, sbheight), System.Drawing.GraphicsUnit.Pixel); MemoryStream Outms=NewMemoryStream ();                Outimg.save (OUTMS, format);                Sbimg.dispose ();                Outimg.dispose (); Img.                Dispose (); returnOutms; }            Catch(Exception ex) {}return NewMemoryStream (); }    }
View Code

. NET PDF to Picture

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.