I've added a GhostScript.NET to my application, and have been able to successfully print PDFs using GSPrint on my local machine. Unfortunately, after deploying the updated application to the server as well as installing GSView (includes GSPrint), the function to print just hangs without any errors.
My first guess is that since I am writing to the filesystem in order for GSPrint to print the file, is that it has something to do with access security rights. I'm using IIS 8 on windows server 2012. If anyone has any experience with deploying GSPrint or on how to troubleshoot this issue, I'd appreciate it.
Here's the code:
public static void PrintingQueue(Queue<byte[]> printQueue, string printer, int copies)
{
Parallel.ForEach(printQueue, (currentFile) =>
{
PrintWithGSPrint(currentFile, printer, copies);
});
printQueue.Clear();
}
private static void PrintWithGSPrint(byte[] pdfFormBytes, string printer, int copies)
{
try
{
var fileName = Path.GetTempFileName();
using (var file = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
{
file.Write(pdfFormBytes, 0, pdfFormBytes.Length);
//this uses GSPrint, which console commands are different from vanilla ghostscript.
var gsArguments = $"-noquery -portrait -printer\"{printer}\" \"{fileName}\"";
var gsLocation = @"C:\Program Files\Ghostgum\gsview\gsprint.exe";
var gsProcessInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = gsLocation,
Arguments = gsArguments
};
var gsProcess = Process.Start(gsProcessInfo);
gsProcess.WaitForExit();
file.Close();
}
File.Delete(fileName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}