我爱Ghostscript.您可以使用它将pdf转换为图形文件,拆分和/或合并pdf文件,制作缩略图以及一大堆其他内容.而且,它是免费的开源软件!
网站上有大量帖子关于如何从命令行使用Ghostscript用于各种平台.但是,我永远找不到一个简单的 vb.net dll包装器,它使用Ghostscript dll(gsdll32.dll)而不是启动进程来运行Ghostscript命令行应用程序.
所以,我想出了这段代码.我在这里发帖,希望其他人可以避免我想要寻找简单直接的挫折感.它避免了你在某些代码中看到的那些愚蠢的字节数组对象数组.它具有最小的错误处理,但可以添加以适合您的应用程序.
将此代码放在名为"GhostscriptDllLib"的模块中.
Option Explicit On
Imports System.Runtime.InteropServices
'--- Simple VB.Net wrapper for Ghostscript gsdll32.dll
' (Tested using Visual Studio 2010 and Ghostscript 9.06)
Module GhostscriptDllLib
Private Declare Function gsapi_new_instance Lib "gsdll32.dll" _
(ByRef instance As IntPtr, _
ByVal caller_handle As IntPtr) As Integer
Private Declare Function gsapi_set_stdio Lib "gsdll32.dll" _
(ByVal instance As IntPtr, _
ByVal gsdll_stdin As StdIOCallBack, _
ByVal gsdll_stdout As StdIOCallBack, _
ByVal gsdll_stderr As StdIOCallBack) As Integer
Private Declare Function …Run Code Online (Sandbox Code Playgroud)