#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);
}
}
}
I am getting a errors: CS0116 A namspace cannot directly contain members such as fields or methods on Line 3
180 views Asked by Chris At
1
You need to load the ghostcript nuget package.
Click on tools.
Nuget package manager.
Manage Nuget Packages for solution.
Click
Browse
TabSearch for GhostScript.NetCore by Stephan Jimane
Install