I am getting a errors: CS0116 A namspace cannot directly contain members such as fields or methods on Line 3

172 views Asked by At
#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);
    }
}
}
1

There are 1 answers

1
Chris Catignani On

You need to load the ghostcript nuget package.

Click on tools.
Nuget package manager.
Manage Nuget Packages for solution.
Click Browse Tab
Search for GhostScript.NetCore by Stephan Jimane
Install