如何使用 Ghostscript DLL 将 PDF 转换为 PDF/A

发布于 2024-08-11 05:11:29 字数 123 浏览 5 评论 0原文

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

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, i'm using C#.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧情勿念 2024-08-18 05:11:29

请尝试从命令行运行它来测试它是否满足您的需要。

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

Ghostscript 的简单 C# 包装器< /a>

pls, try to run this from the command line to test if it's doing what you need.

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

A Simple C# Wrapper for Ghostscript

半世晨晓 2024-08-18 05:11:29

我已经使用 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”
  • ...

I've had it working using the following from 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 will be a array of strings like:

  • "-sDEVICE=pdfwrite"
  • "-dPDFA"
  • ...
养猫人 2024-08-18 05:11:29

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

尝试添加 -Ic:/path/to/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

首先测试命令行,然后执行以下操作塞尔日推荐。

Depends on what exact deviation from the standard your checker tools do report... You may need to alter your PDFA_def.ps to fit your environment (and you may need to dynamically re-write that file for every new PDF/A conversion). It's a short file, and well commented.

Try to add -Ic:/path/to/gsinstalldir/lib and the direct invocation of PDFA_def.ps to the commandline serge suggested:

 gswin32c.exe ^
    -Ic:/path/to/gsinstalldir/lib ^
    -dPDFA ^
    -dBATCH ^
    -dNOPAUSE ^
    -dUseCIEColor ^
    -sDEVICE=pdfwrite ^
    -sOutputFile=output-PDFA.pdf ^
    PDFA_def.gs ^
    input.pdf

or

 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

Test commandline first, then do as serge recommended.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文