Quantcast
Channel: Ghostscript.NET
Viewing all 393 articles
Browse latest View live

New Post: Additional information: An error occured when call to 'gsapi_new_instance' is made: -100

$
0
0
The initial error "gsapi_new_instance": -100 says that Ghostscript instance could not be created.

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

New Post: GhostScript dll

$
0
0
Is there any way to work around this, and be able to link to the ghostscript dll without having to install ghostscript on the machine?

New Post: GhostScript dll

New Post: problem with GhostscriptRasterizer reading from MemoryStream and the solution

$
0
0
Just to keep others up-to-date.

With help from Chanan this problem is fixed. Now EPS files with the preview header signature are also supported.

Untill next release (1.1.3) here is the code that has to be replaced in Ghostscript.NET->Viewer->GhostscriptViewer.cs:
#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

New Post: GhostScript dll

$
0
0
Is Ghostscript.NET a wrapper around GSDLL32.DLL the self-sufficient (stand-alone) binary implementation downloaded from the 'Ghostscript Downloads Page'? The full Ghostscript product does NOT need to be installed on the rollout machine in order to use this from a .NET 2003 application. I've tested this. Therefore, for .NET 2010, do we only need to rollout Ghostscript.NET.dll & GSDLL32.DLL with an app?

New Post: Error if there are no parameters on %%BoundingBox:

$
0
0
Get an exception error if there are no parameters on %%BoundingBox:

My next lines are always additional comment blocks.
I changed the code in GhostscriptViewPsFormatHandler.cs

The original code is: (Line 196)
if (llx.Text != "(atend)")

I changed my copy to :
if (llx.Text != "(atend)" && ! llx.Text.StartsWith("%"))

A change should probably done for the previous case statement as well
if (token.Text != "(atend)")

New Post: Threading issue on a web server?

$
0
0
Hello, I am trying to use Ghostscript.NET on a web server for back-end processing. It works fine under a single user, but when I kick off a process with multiple users the .StartProcessing call will fail with the following error:

An error occured when call to 'gsapi_new_instance' is made: -100

This looks to me like a threading or similar multi-user error, but I'm not sure how to resolve it. I am running GS 9.10 GPL, ASP.NET 4.5 and IIS 7. Is there something specific I need to configure for Ghostscript to make it work on a web server?

Thank you,
Shawn

Here is my source code:

GhostscriptVersionInfo _gs_version_info =
GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);
GhostscriptProcessor processor = new GhostscriptProcessor(_gs_version_info);

List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-dQUIET");
switches.Add("-dSAFER");
switches.Add("-dBATCH");
switches.Add("-dNOPAUSE");
switches.Add("-dEPSCrop");
switches.Add("-sDEVICE=pdfwrite");
switches.Add("-sOutputFile=" + variantPath);
switches.Add("-f");
switches.Add(originalPath);
processor.StartProcessing(switches.ToArray(), null);

New Post: Processing event of GhostscriptProcessor class


New Post: GhostScript dll

New Post: GhostScript dll

$
0
0
Correct, you can deploy only those two files and everything should work. The only issue you might run into with native Ghostscript library deployment is the Artifex Software Inc. licensing model (GPL).

New Post: Processing event of GhostscriptProcessor class

New Post: Threading issue on a web server?

$
0
0
Hi, sorry for the delay,

Try to create GhostscriptProcessor instance like this:

GhostscriptProcessor processor = new GhostscriptProcessor(_gs_version_info, true);

Where second parameter 'true' tells the GhostscriptProcessor to create the instance in it's own memory space. By default in your sample this parameter is set to 'false'.

Cheers,
Josip

New Post: Error if there are no parameters on %%BoundingBox:

$
0
0
Great,

I'm glad that you reported this bug and found the solution and shared it with us.

I will for sure include it in the next release.

Cheers,
Josip

New Post: Threading issue on a web server?

$
0
0
Hi Josip, this worked great. Thank you!

I was using a workaround where I created a single instance of the processor object and stored it in Application scope, then used the lock() command to lock the processor each time it was called. While that seemed to resolve the issue I'm not sure that would be healthy long term.

Thank you again for your response.
Shawn

New Post: How to know given PDF file is color pdf or graypdf

$
0
0
Hi
Is it possible to know given PDF is color pdf or gray pdf using Ghostscript.NET?
Is it possible to extract information form /colorSpace object using Ghostscript.NET?

Thanks in Advanced

New Post: How to know given PDF file is color pdf or graypdf

$
0
0
Hi,

Ghostscript device called inkcov can detect whether a PDF page uses color or not. It displays the ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally).

I wrote you a small routine that will return you ink coverage for each page:
    /// <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:

C (cyan) M (magenta) Y (yellow) K (black)

0.00000 0.00000 0.00000 0.01721 CMYK OK
0.00000 0.00000 0.00000 0.03788 CMYK OK
0.00000 0.00000 0.00000 0.04137 CMYK OK
0.00000 0.00000 0.00000 0.00621 CMYK OK
0.00000 0.00000 0.00000 0.01462 CMYK OK
0.00000 0.00000 0.00000 0.01103 CMYK OK

Where a value of 1.00000 maps to 100% ink coverage for the respective color channel. So 0.01721 in the first line of the result means 1.72 % of the first page area is covered by black ink.

I hope this helps.

Cheers,
Josip

New Post: Threading issue on a web server?

$
0
0
I'm glad I could help.

Workaround you made earlier is fine and will work long term if you don't need to convert multiple PDF's at a same time on a same machine.

Cheers,
Josip

Updated Wiki: Home

$
0
0

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.

Chat: https://jabbr.net/#/rooms/ghostscriptnet

NuGet: PM> Install-Package Ghostscript.NET

Used in Ghostscript Studio (Ghostscript IDE)

                                                       

Features of the Ghostscript.NET are:

  • It contains GhostscriptViewer class which allows you to easily render and navigate through PDF or PostScript files on the screen via code.  It can handle multi-page PostScript files.
  • GhostscriptViewer class contains progressive display update implementation. While Ghostscript is drawing / rasterizing you can see tiles drawing on the screen. Custom update interval can be set.
  • GhostscriptViewer class has Zoom-in and Zoom-out functionality.
  • It contains GhostscriptRasterizer class which provides ability to easily exportPDF pages, PostScript pages and EPS files to the System.Drawing.Image object in the  memory.
  • It allows you to run multiple instances of the Ghostscript library (dll) simultaneously within a single process (Ghostscript API does not support this out-of-the-box). This is achieved by using Microsoft.WinAny.Helper library and it's DynamicNativeLibrary class which allows you to load a native library from the memory instead from a disk. By doing this (loading from the memory), all Ghostscript instances are running in their own context.
  • It contains GhostscriptProcessor class which allows you to call Ghostscript library (dll) with a custom specified arguments / switches.
  • All Ghostscript functions which provides ability to rasterize / render postscript or pdf directly to the screen without a need to save it to the disk first are implemented.
  • It's completely compatible and tested with 32-bit and 64-bit Ghostscript library.

Plans:

  • Extending this library to be more "developer" friendly.

Sample applications screenshots below (built on top of the Ghostscript.NET library):

Ghostscript.NET.Viewer: (supports viewing of PDF and multi-page PS files)

  Ghostscript.NET.Viewer 

Example of direct postscript rasterizing via Ghostscript.NET.

Cheers,
Josip Habjan
http://habjan.blogspot.com

 

Website counter

New Post: GhostScript dll

$
0
0
I tried deploying Ghostscript.NET.dll & GSDLL32.DLL with a VB.NET 2010 application to a 32-bit Windows 7 workstation where I work, without installing the full Ghostscript product. It produces this error:-

'This managed library is running under 32-bit process and requires 32-bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html'

... but that's where I downloaded GSDLL32.DLL from in the first place? I'm confused. Any help would be greatly appreciated.

By the way it works if you install the full product on the roll-out machine, but I'm trying to avoid that.

New Post: GhostScript dll

$
0
0
I assume that you use GhostscriptVersionInfo.GetLastInstalledVersion() function to get installed ghostscript libraries. The error you get is because mentioned method looks into the registry to collect all installed Ghostscript locations. If you want to use specific ghostscript dll that you are shipping with your application I would recommend you to do something like this:
GhostscriptVersionInfo gvi = new GhostscriptVersionInfo(new Version(0, 0, 0), @"e:\myapp\gsdll32.dll", string.Empty, GhostscriptLicense.GPL);
ghostscriptRasterizer.Open(@"e:\mytest.pdf", gvi);
or
GhostscriptProcessor ghostscriptProccessor = new GhostscriptProcessor(gvi);
or
ghostscriptViewer.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);
or
GhostscriptProcessor ghostscriptProccessor = new GhostscriptProcessor(gsDllBinary);
ghostscriptProccessor.StartProcessing(...)
or
ghostscriptViewer.Open(@"e:\mytest.pdf", gsDllBinary);
I hope this helps.

Cheers,
Josip
Viewing all 393 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>