国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

pdf文件顯示

2019-11-17 03:16:29
字體:
來源:轉載
供稿:網友

pdf文件顯示

由于項目需要在.net下將pdf轉換為普通圖像格式,在網上搜了好久終于找到一個解決方案,于是采用拿來主義直接用。來源見代碼中注釋,感謝原作者。

[c-sharp] view plaincopyPRint?
  1. usingSystem;
  2. usingSystem.Collections.Generic;
  3. usingSystem.Text;
  4. usingSystem.Runtime.InteropServices;
  5. usingSystem.Collections;
  6. /**
  7. ConvertPDFtoImageFormat(JPEG)usingGhostscriptAPI
  8. convertapdftojpegusingghostscriptcommandline:
  9. gswin32c-q-dQUIET-dPARANOIDSAFER-dBATCH-dNOPAUSE-dNOPROMPT-dMaxBitmap=500000000-dFirstPage=1-dAlignToPixels=0-dGridFitTT=0-sDEVICE=jpeg-dTextAlphaBits=4-dGraphicsAlphaBits=4-r100x100-sOutputFile=output.jpgtest.pdf
  10. seealso:http://www.mattephraim.com/blog/2009/01/06/a-simple-c-wrapper-for-ghostscript/
  11. and:http://www.codeproject.com/KB/cs/GhostScriptUseWithCSharp.aspx
  12. Note:copygsdll32.dlltosystem32directorybeforeusingthisghostscriptwrapper.
  13. *
  14. */
  15. namespaceConvertPDF
  16. {
  17. ///<summary>
  18. ///
  19. ///ClasstoconvertapdftoanimageusingGhostScriptDLL
  20. ///Creditforthiscodegoto:RangelAvulso
  21. ///ionlyfixalittlebugandrefactoralittle
  22. ///http://www.hrangel.com.br/index.php/2006/12/04/converter-pdf-para-imagem-jpeg-em-c/
  23. ///</summary>
  24. ///<seealsocref="http://www.hrangel.com.br/index.php/2006/12/04/converter-pdf-para-imagem-jpeg-em-c/"/>
  25. classPDFConvert
  26. {
  27. #regionGhostScriptImport
  28. ///<summary>CreateanewinstanceofGhostscript.Thisinstanceispassedtomostothergsapifunctions.Thecaller_handlewillbeprovidedtocallbackfunctions.
  29. ///Atthisstage,Ghostscriptsupportsonlyoneinstance.</summary>
  30. ///<paramname="pinstance"></param>
  31. ///<paramname="caller_handle"></param>
  32. ///<returns></returns>
  33. [DllImport("gsdll32.dll",EntryPoint="gsapi_new_instance")]
  34. privatestaticexternintgsapi_new_instance(outIntPtrpinstance,IntPtrcaller_handle);
  35. ///<summary>Thisistheimportantfunctionthatwillperformtheconversion</summary>
  36. ///<paramname="instance"></param>
  37. ///<paramname="argc"></param>
  38. ///<paramname="argv"></param>
  39. ///<returns></returns>
  40. [DllImport("gsdll32.dll",EntryPoint="gsapi_init_with_args")]
  41. privatestaticexternintgsapi_init_with_args(IntPtrinstance,intargc,IntPtrargv);
  42. ///<summary>
  43. ///Exittheinterpreter.Thismustbecalledonshutdownifgsapi_init_with_args()hasbeencalled,andjustbeforegsapi_delete_instance().
  44. ///</summary>
  45. ///<paramname="instance"></param>
  46. ///<returns></returns>
  47. [DllImport("gsdll32.dll",EntryPoint="gsapi_exit")]
  48. privatestaticexternintgsapi_exit(IntPtrinstance);
  49. ///<summary>
  50. ///DestroyaninstanceofGhostscript.Beforeyoucallthis,Ghostscriptmusthavefinished.IfGhostscripthasbeeninitialised,youmustcallgsapi_exitbeforegsapi_delete_instance.
  51. ///</summary>
  52. ///<paramname="instance"></param>
  53. [DllImport("gsdll32.dll",EntryPoint="gsapi_delete_instance")]
  54. privatestaticexternvoidgsapi_delete_instance(IntPtrinstance);
  55. #endregion
  56. #regionVariables
  57. privatestring_sDeviceFormat;
  58. privateint_iWidth;
  59. privateint_iHeight;
  60. privateint_iResolutionX;
  61. privateint_iResolutionY;
  62. privateint_iJPEGQuality;
  63. privateBoolean_bFitPage;
  64. privateIntPtr_objHandle;
  65. #endregion
  66. #regionProprieties
  67. publicstringOutputFormat
  68. {
  69. get{return_sDeviceFormat;}
  70. set{_sDeviceFormat=value;}
  71. }
  72. publicintWidth
  73. {
  74. get{return_iWidth;}
  75. set{_iWidth=value;}
  76. }
  77. publicintHeight
  78. {
  79. get{return_iHeight;}
  80. set{_iHeight=value;}
  81. }
  82. publicintResolutionX
  83. {
  84. get{return_iResolutionX;}
  85. set{_iResolutionX=value;}
  86. }
  87. publicintResolutionY
  88. {
  89. get{return_iResolutionY;}
  90. set{_iResolutionY=value;}
  91. }
  92. publicBooleanFitPage
  93. {
  94. get{return_bFitPage;}
  95. set{_bFitPage=value;}
  96. }
  97. ///<summary>QualityofcompressionofJPG</summary>
  98. publicintJPEGQuality
  99. {
  100. get{return_iJPEGQuality;}
  101. set{_iJPEGQuality=value;}
  102. }
  103. #endregion
  104. #regionInit
  105. publicPDFConvert(IntPtrobjHandle)
  106. {
  107. _objHandle=objHandle;
  108. }
  109. publicPDFConvert()
  110. {
  111. _objHandle=IntPtr.Zero;
  112. }
  113. #endregion
  114. privatebyte[]StringToAnsiZ(stringstr)
  115. {
  116. //'ConvertaUnicodestringtoanullterminatedAnsistringforGhostscript.
  117. //'Theresultisstoredinabytearray.Lateryouwillneedtoconvert
  118. //'thisbytearraytoapointerwithGCHandle.Alloc(XXXX,GCHandleType.Pinned)
  119. //'andGSHandle.AddrOfPinnedObject()
  120. intintElementCount;
  121. intintCounter;
  122. byte[]aAnsi;
  123. bytebChar;
  124. intElementCount=str.Length;
  125. aAnsi=newbyte[intElementCount+1];
  126. for(intCounter=0;intCounter<intElementCount;intCounter++)
  127. {
  128. bChar=(byte)str[intCounter];
  129. aAnsi[intCounter]=bChar;
  130. }
  131. aAnsi[intElementCount]=0;
  132. returnaAnsi;
  133. }
  134. ///<summary>Convertthefile!</summary>
  135. publicvoidConvert(stringinputFile,stringoutputFile,
  136. intfirstPage,intlastPage,stringdeviceFormat,intwidth,intheight)
  137. {
  138. //Avoidtoworkwhenthefiledoesn'texist
  139. if(!System.IO.File.Exists(inputFile))
  140. {
  141. System.Windows.Forms.MessageBox.Show(string.Format("Thefile:'{0}'doesn'texist",inputFile));
  142. return;
  143. }
  144. intintReturn;
  145. IntPtrintGSInstanceHandle;
  146. object[]aAnsiArgs;
  147. IntPtr[]aPtrArgs;
  148. GCHandle[]aGCHandle;
  149. intintCounter;
  150. intintElementCount;
  151. IntPtrcallerHandle;
  152. GCHandlegchandleArgs;
  153. IntPtrintptrArgs;
  154. string[]sArgs=GetGeneratedArgs(inputFile,outputFile,
  155. firstPage,lastPage,deviceFormat,width,height);
  156. //ConverttheUnicodestringstonullterminatedANSIbytearrays
  157. //thengetpointerstothebytearrays.
  158. intElementCount=sArgs.Length;
  159. aAnsiArgs=newobject[intElementCount];
  160. aPtrArgs=newIntPtr[intElementCount];<
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临夏市| 新和县| 驻马店市| 班戈县| 如皋市| 汝南县| 精河县| 肇州县| 开化县| 秦安县| 句容市| 沾化县| 安庆市| 华安县| 丽水市| 阿拉善左旗| 宁都县| 历史| 桃江县| 余江县| 柳江县| 定远县| 千阳县| 蚌埠市| 普格县| 泰来县| 铜川市| 新田县| 南投市| 大丰市| 华蓥市| 华亭县| 米脂县| 衡山县| 子洲县| 泽库县| 遵义市| 贵溪市| 香格里拉县| 鹤庆县| 枣阳市|