首页 > 解决方案 > 我收到一个错误:CS0116 A namspace cannot directly contain members,例如第 3 行的字段或方法

问题描述

#nullable enable

using System.Text;

using Ghostscript.NET;
using Ghostscript.NET.Processor;

namespace Metro.MbaProcessing.Core
{
internal static class PdfToText
{
    private const string HandleTag = "%handle%";
    private const string HandleFormat = "X2";


    internal static string Process(string filePath, Encoding encoding)
    {
        GhostscriptVersionInfo gsv = GhostscriptVersionInfo.GetLastInstalledVersion();
        using var processor = new GhostscriptProcessor(gsv);
        using var pipedOutput = new GhostscriptPipedOutput();

        string outputPipeHandle = $"{HandleTag}{int.Parse(pipedOutput.ClientHandle).ToString(HandleFormat)}";
        string[] switches =
        {
            $"-o{outputPipeHandle}",
            "-empty",
            "-dQUIET",
            "-dSAFER",
            "-dBATCH",
            "-dNOPAUSE",
            "-dNOPROMPT",
            "-sDEVICE=txtwrite",
            //$"-o{outputPipeHandle}",
            "-q",
            "-f",
            filePath
        };
        processor.StartProcessing(switches, null);

        return encoding.GetString(pipedOutput.Data);
    }
}
}

标签: c#ghostscript.net

解决方案


您需要加载 ghostcript nuget 包。

点击工具。
Nuget 包管理器。
管理 Nuget 包以获取解决方案。
单击Browse选项卡
搜索由 Stephan Jimane
安装的 GhostScript.NetCore


推荐阅读