我收到一个错误:CS0116 namspace无法直接包含第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);
    }
}
}

解决方法

您需要加载ghostcript nuget软件包。

点击工具。
Nuget软件包管理器。
管理Nuget软件包以获取解决方案。
点击Browse标签
通过Stephan Jimane搜索GhostScript.NetCore
安装