2

如何使用 GhostScript DLL 将 PDF 转换为 PDF/A。我知道我必须调用名为 gsapi_init_with_args 的 gsdll32.dll 的导出函数,但我如何传递正确的参数?顺便说一句,我正在使用 C#。

4

3 回答 3

3

请尝试从命令行运行它以测试它是否正在执行您需要的操作。

gswin32.exe -dPDFA -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=PDFA.pdf 1.pdf

Ghostscript 的简单 C# 包装器

于 2009-11-13T04:03:10.900 回答
1

我已经使用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”
  • ...
于 2010-11-30T22:51:11.107 回答
0

取决于您的检查工具报告的与标准的确切偏差...您可能需要更改您的工具PDFA_def.ps以适应您的环境(并且您可能需要为每个新的 PDF/A 转换动态地重写该文件)。这是一个简短的文件,并且评论很好。

尝试添加-Ic:/path/to/gsinstalldir/lib并直接调用PDFA_def.ps命令行 serge 建议:

gswin32c.exe ^
    -Ic:/path/to/gsinstalldir/lib ^
    -dPDFA ^
    -分贝^
    -dNOPAUSE ^
    -dUseCIEColor ^
    -sDEVICE=pdfwrite ^
    -sOutputFile=输出-PDFA.pdf ^
    PDFA_def.gs ^
    输入.pdf

或者

gswin32c.exe ^
    -Ic:/path/to/gsinstalldir/lib ^
    -dPDFA ^
    -分贝^
    -dNOPAUSE ^
    -dUseCIEColor ^
    -sDEVICE=pdfwrite ^
    -sOutputFile=输出-PDFA.pdf ^
    c:/path/to/customized/PDFA_def.gs ^
    输入.pdf

首先测试命令行,然后按照 serge 的建议进行操作。

于 2010-06-05T21:46:07.777 回答