I have a function that uses GhostScript.NET to print PDF documents. Everything works correctly if one user is trying to print, however when multiple users try to print simultaneously it doesn't print all of the documents. I recognize that I will have create multiple instances of ghostscript in order to achieve multiple-simultaneous printing. I came accross this question:
Ghostscript.NET Multithreading Issue
One of the users says to create a parallel forloop, but I'm honestly not sure how to structure one so that it creates the correct amount of instances of GhostScript.
I have the main function:
public static void PrintFormPdfData(byte[] formPdfData, string printer)
{
var filename = @"C:\TEMP\report.pdf";
using (var file = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite))
{
file.Write(formPdfData, 0, formPdfData.Length);
using (GhostscriptProcessor processor = new GhostscriptProcessor())
{
List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-dPrinted=false");
switches.Add("-dBATCH");
switches.Add("-dPDFFitPage");
switches.Add("-dNOPAUSE");
switches.Add("-dNOSAFER");
switches.Add("-dNumRenderingThreads=3");
switches.Add("-dNumCopies=1");
switches.Add("-sDEVICE=mswinpr2");
switches.Add("-sOutputFile=%printer%" + printer);
switches.Add(filename);
try
{
processor.StartProcessing(switches.ToArray(), null);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
File.Delete(filename);
}
}
}
}
Any help would be greatly appreciated.