如何使用Ghostscript DLL将PDF转换为PDF / A.
如何使用GhostScript DLL将PDF转换为PDF / A. 我知道我必须调用gsdll32.dll的导出函数,其名称为gsapi_init_with_args,但我如何传递正确的参数? 顺便说一下,我正在使用C#。
请尝试从命令行运行此命令以测试它是否正在执行您需要的操作。
gswin32.exe -dPDFA -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=PDFA.pdf 1.pdf
Ghostscript的简单C#包装器
我使用ghostscriptsharp中的以下工作:
[DllImport("gsdll32.dll", EntryPoint = "gsapi_new_instance")] private static extern int CreateAPIInstance(out IntPtr pinstance, IntPtr caller_handle); [DllImport("gsdll32.dll", EntryPoint = "gsapi_init_with_args")] private static extern int InitAPI(IntPtr instance, int argc, string[] argv); [DllImport("gsdll32.dll", EntryPoint = "gsapi_exit")] private static extern int ExitAPI(IntPtr instance); [DllImport("gsdll32.dll", EntryPoint = "gsapi_delete_instance")] private static extern void DeleteAPIInstance(IntPtr instance); private static void CallAPI(string[] args) { IntPtr gsInstancePtr; lock (resourceLock) { CreateAPIInstance(out gsInstancePtr, IntPtr.Zero); try { int result = InitAPI(gsInstancePtr, args.Length, args); if (result < 0) { throw new ExternalException("Ghostscript conversion error", result); } } finally { Cleanup(gsInstancePtr); } } } private static object resourceLock = new object(); private static void Cleanup(IntPtr gsInstancePtr) { ExitAPI(gsInstancePtr); DeleteAPIInstance(gsInstancePtr); }
args
将是一个字符串数组,如:
- “-sDEVICE = pdfwrite”
- “-dPDFA”
- ...
取决于您的检查工具报告的标准的准确偏差…您可能需要更改PDFA_def.ps
以适应您的环境(并且您可能需要为每个新的PDF / A转换动态地重写该文件)。 这是一个简短的文件,并且评论很好。
尝试添加-Ic:/ path /到/ gsinstalldir / lib并将PDFA_def.ps
直接调用到命令行serge建议:
gswin32c.exe ^ -Ic:/ path / to / gsinstalldir / lib ^ -dPDFA ^ -dBATCH ^ -dNOPAUSE ^ -dUseCIEColor ^ -sDEVICE = pdfwrite ^ -sOutputFile = output-PDFA.pdf ^ PDFA_def.gs ^ input.pdf
要么
gswin32c.exe ^ -Ic:/ path / to / gsinstalldir / lib ^ -dPDFA ^ -dBATCH ^ -dNOPAUSE ^ -dUseCIEColor ^ -sDEVICE = pdfwrite ^ -sOutputFile = output-PDFA.pdf ^ c:/path/to/customized/PDFA_def.gs ^ input.pdf
首先测试命令行,然后执行serge推荐。