If you want and you can give me access to your machine via TeamViewer I can debug it directly on your machine, that would save us both a lot of time. You can let me know via habjan@gmail.com.
Cheers,
Josip
#region StoreMemoryStreamToTemporaryFile
private string StoreMemoryStreamToTemporaryFile(MemoryStream stream)
{
if (stream.Length < 4)
{
throw new InvalidDataException();
}
byte[] test = new byte[4];
stream.Read(test, 0, 4);
stream.Position = 0;
string extension = string.Empty;
if (test[0] == 0x25 && test[1] == 0x21) // standard ps or eps signature
{
extension = ".ps";
if (stream.Length > 23)
{
test = new byte[23];
stream.Read(test, 0, 23);
stream.Position = 0;
string tmp = System.Text.Encoding.ASCII.GetString(test);
if (tmp.ToUpper().Contains("EPS"))
{
extension = ".eps";
}
}
}
else if (test[0] == 0xc5 && test[1] == 0xd0 && test[2] == 0xd3 && test[3] == 0xc6) // eps with preview header signature / magic number (always C5D0D3C6)
{
extension = ".eps";
}
else if (test[0] == 0x25 && test[1] == 0x50 && test[2] == 0x44 && test[3] == 0x46) // pdf signature
{
extension = ".pdf";
}
else
{
throw new FormatException("Stream format is not valid! Please make sure it's PDF, PS or EPS.");
}
string path = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + extension);
File.WriteAllBytes(path, stream.ToArray());
_fileCleanupHelper.Add(path);
return path;
}
#endregion
GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);
GhostscriptProcessor processor = new GhostscriptProcessor(_gs_version_info); /// <summary>
/// Supported only in Ghostscript v9.05 or newer.
/// </summary>
public static string GetInkCoverage(string file)
{
GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");
List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-q");
switches.Add("-o" + outputPipeHandle);
switches.Add("-sDEVICE=inkcov");
switches.Add(file);
GhostscriptProcessor proc = new GhostscriptProcessor();
proc.StartProcessing(switches.ToArray(), null);
byte[] data = gsPipedOutput.Data;
return System.Text.Encoding.ASCII.GetString(data);
}
So, for PDF with 6 pages you will get the output similar to this one:Ghostscript.NET (written in C#) is the most completedmanaged wrapper library around the Ghostscript library (32-bit & 64-bit), an interpreter for the PostScript language, PDF, related software and documentation.
All other .NET Ghostscript wrappers that you can find on the internet this days does not allow you to render PDF page directly to the screen without exporting the pages to the disk first. This wrapper does not require exporting to the disk, it can render PDF pages to the screen directly from the Ghostscript interpreter.
Used in Ghostscript Studio (Ghostscript IDE)
Features of the Ghostscript.NET are:
Plans:
Sample applications screenshots below (built on top of the Ghostscript.NET library):
Ghostscript.NET.Viewer: (supports viewing of PDF and multi-page PS files)
Example of direct postscript rasterizing via Ghostscript.NET.
Cheers,
Josip Habjan
http://habjan.blogspot.com
GhostscriptVersionInfo gvi = new GhostscriptVersionInfo(new Version(0, 0, 0), @"e:\myapp\gsdll32.dll", string.Empty, GhostscriptLicense.GPL);
ghostscriptRasterizer.Open(@"e:\mytest.pdf", gvi);
orGhostscriptProcessor ghostscriptProccessor = new GhostscriptProcessor(gvi);
orghostscriptViewer.Open(@"e:\mytest.pdf", gvi);
or you can pass dll as byte array like this:string pathToGsDll = @"e:\myapp\gsdll32.dll";
byte[] gsDllBinary = System.IO.File.ReadAllBytes(pathToGsDll);
ghostscriptRasterizer.Open(@"e:\mytest.pdf", gsDllBinary);
orGhostscriptProcessor ghostscriptProccessor = new GhostscriptProcessor(gsDllBinary);
ghostscriptProccessor.StartProcessing(...)
orghostscriptViewer.Open(@"e:\mytest.pdf", gsDllBinary);
I hope this helps.