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

New Post: Null reference at StartProcessing method on remote servce

$
0
0
Hello,

I am using this Ghostscript to convert pdf to png, the code almost identical as first method in this sample .
It works perfectly on my local machine, but it failed when I deploy it to the windows azure. As i mentioned in title I am getting null reference exception in StartProcessing method.

Ghostscript is installed on a server and I able to verify this using
GhostscriptVersionInfo.GetLastInstalledVersion
This wrapper is pretty new and I can't find anything meaningful across the internet.

Any directions where to look for the issue would be helpful. I am appreciate your time and thank you for the amazing job.

Thank you, Andrew.

New Post: Null reference at StartProcessing method on remote servce

$
0
0
Hi Andrew,

Can you please let me know if GhostscriptProcessor sample works on windows azure for you?

Meanwhile i will implement better exception handling for the next release.

Cheers,
Josip

New Post: Null reference at StartProcessing method on remote server [windows azure]

$
0
0
Hi Josip,

Thank you for the reply.

What I eventually did is wrote very simple console app that works on windows azure:
          static void Main(string[] args)
          {
           var pathToPdfFile = args[0];
            var outputPath = args[1];

            var lastInstalledVersion = GhostscriptVersionInfo.GetLastInstalledVersion(
                  GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);
            Console.WriteLine(lastInstalledVersion);

            var dev = new GhostscriptPngDevice(GhostscriptPngDeviceType.Png256);
            dev.ResolutionXY = new GhostscriptImageDeviceResolution(76, 76);
            dev.InputFiles.Add(pathToPdfFile);
            dev.Pdf.FirstPage = 1;
            dev.Pdf.LastPage = 1;
            dev.OutputPath = outputPath;
            dev.BackgroundColor = Color.White;
            dev.Process();
         } 
When I created this simple console app based on .net 4.5 it failed to work on my local machine with same null reference exception as on azure.
Just for fun I switched it to .net 4.0 and it's worked. Bingo! I did the same with my mvc 4 api, but no luck :(

Because of time concerns, my azure deployment running above console app and everything work, but I still don't understand what is causing this issue.
Perhaps there is issue with .net 4.5. I'd love to continue my investigation, but running out of time at the moment.

P.S. I'll be watching updates!

Thank you, Andrew.

New Post: postscript to file only

$
0
0
Does anyone have a sample of code that simply creates a pdf file from a ps file without displaying it?

New Post: postscript to file only

New Post: postscript to file only

$
0
0
Hi,

Take a look at this sample:
    using Ghostscript.NET.Processor;


    List<string> switches = new List<string>();
    switches.Add("-empty");
    switches.Add("-dQUIET");
    switches.Add("-dSAFER");
    switches.Add("-dBATCH");
    switches.Add("-dNOPAUSE");
    switches.Add("-dNOPROMPT");
    switches.Add("-sDEVICE=pdfwrite");
    switches.Add("-sOutputFile=" + @"E:\testoutput.pdf");
    switches.Add("-f");
    switches.Add(@"E:\testinput.ps");

    using (GhostscriptProcessor processor = new GhostscriptProcessor())
    {
        processor.StartProcessing(switches.ToArray(), null);
    }

New Post: open PDF from Memorystream?

$
0
0
Hi! Is this possibility already available? (+1 for this) Thx.

New Post: open PDF from Memorystream?

$
0
0
Hi all,

I did a little research, and the thing is that the PDF language, unlike the PostScript language, inherently requires random access to the file. If you provide PDF directly to Standard Input or via PIPE, Ghostscript will copy it to a temporary file before interpreting the PDF. So, there is no point of passing PDF as MemoryStream (or byte array) as it will anyway end up on the disk before it will be interpreted.

Cheers,
Josip

Source code checked in, #28382

$
0
0
Fixed GhostscriptPipedOutput.Data property get accesor in order to prevent a race condition. (thanks to "Marc Klenotic"). Added GhostscriptPipedOutput class as part of the Ghostscript.NET library. Fixed GhostscriptException error code text message resolving. Implemented better methods parameters checking and exception handling. Changed ImageMemoryHelper class from public to internal. Implemented opening files represented as MemoryStream from GhostscriptRasterizer and GhostscriptViewer. (that was some users request although there is no point of passing PDF as MemoryStream (or byte array) as it will anyway end up on the disk before it will be interpreted as PDF language, unlike the PostScript language, inherently requires random access to the file).

Released: Ghostscript.NET v.1.1.2. (Dec 13, 2013)

$
0
0
v.1.1.2.
  • fixed GhostscriptPipedOutput.Data property get accesor in order to prevent a race condition. (thanks to "Marc Klenotic").
  • added GhostscriptPipedOutput class as part of the Ghostscript.NET library.
  • fixed GhostscriptException error code text message resolving.
  • implemented better methods parameters checking and exception handling.
  • changed ImageMemoryHelper class from public to internal.
  • implemented opening files represented as MemoryStream from GhostscriptRasterizer and GhostscriptViewer. (that was some users request although there is no point of passing PDF as MemoryStream (or byte array) as it will anyway end up on the disk before it will be interpreted as PDF language, unlike the PostScript language, inherently requires random access to the file).

v.1.1.1.
  • fixed problem in GhostscriptRasterizer and GhostscriptViewer when MediaBox contains negative llx or lly values. (problem reported by "Prasenjit Das").
  • added GhostscriptPngDevice, a friendly output device class with all png devices related switches. (GhostscriptPngDevice supports: png16m, pngalpha, pnggray, png256, png16, pngmono, pngmonod).
  • added GhostscriptJpegDevice, a friendly output device class with all jpeg devices related switches. (GhostscriptJpegDevice supports: jpeg, jpeggray).
  • extended GhostscriptProcessor.StartProcessing method to support GhostscriptDevice base class as StartProcessing parameter.
  • for each constructor / method that requires GhostscriptVersionInfo parameter, now there is one more constructor / method available with a same functionality but without a need to pass GhostscriptVersionInfo parameter. This new constructors and methods automatically retrieves and use last installed Ghostscript version.
  • added new samples to the Ghostscript.NET.Samples project (AddWatermarkSample, ProcessorSample, DeviceUsageSample).

v.1.1.0.
  • added GhostscriptViewer state handling (SaveState, RestoreState)
  • GhostscriptRasterizer constructor is extended in order to support usage of the existing GhostscriptViewer instance.
  • fixed problem while using a 32-bit assembly with 32-bit version of Ghostscript on 64-bit Windows: It couldn't find a registry key of installed Ghostscript. Reported and fixed by "r0land".

v.1.0.9.
  • implemented EPS (Encapsulated PostScript) support for the GhostscriptViewer.
  • added GhostscriptRasterizer class which provides ability to easily export PDF pages, PostScript pages and EPS files to the System.Drawing.Image object in the memory. For each page different x and y dpi settings can be set.
  • fixed gsapi_stdin callback and it's value passing to the ghostscript library.
  • added ProgressiveUpdate property to the GhostscriptViewer class so progressive update can be controlled outside the library.

v.1.0.8.
  • implemented StopProcessing method in the GhostscriptProcessor class which allows us to terminate gsapiinitwith_args call in the multithread environment.
  • fixed GhostscriptViewer ZoomIn and ZoomOut problem on the systems where windows region and language settings has number decimal symbol set to comma.
  • added page navigation and zoom checker properties to the GhostscriptViewer class.
  • fixed problem in GhostscriptViewer class when trying to view PostScript files without DSC header.
  • GhostscriptProcessor.Process method name changed to StartProcessing.
Also check out Ghostscript Studio (http://ghostscriptstudio.codeplex.com/)

v.1.0.7.
  • implemented multi-page PostScript support for the GhostscriptViewer
  • included Microsoft.WinAny.Helper code files in order to have a single dll for the deployment
  • added Processing event to the GhostscriptProcessor class (with CurrentPage and TotalPages info)
  • added zoom-in and zoom-out functionality
  • fixed ImageMemoryHelper.Set24bppRgbImageColor function when stride size is not multiple of 3 bytes
  • fixed displayed page size
v.1.0.6.
  • implemented progressive display update while ghostscript is drawing / rasterizing, now a custom update interval can be set in GhostscriptViewer class.
  • fixed problem when using 64-bit ghostscript library where raster (stride) line size is not equal to 32-bit ghostscript library raster line size.
  • changed GhostscriptViewer class event logic.
  • changed Ghostscript.NET.Viewer application in order to show progressive update.
  • modified Ghostscript.NET.DisplayTest, now it uses GhostscriptViewer class with ability to interpret postscript and display standard input output messages.

Created Release: Ghostscript.NET v.1.1.2. (Dec 13, 2013)

$
0
0
v.1.1.2.
  • fixed GhostscriptPipedOutput.Data property get accesor in order to prevent a race condition. (thanks to "Marc Klenotic").
  • added GhostscriptPipedOutput class as part of the Ghostscript.NET library.
  • fixed GhostscriptException error code text message resolving.
  • implemented better methods parameters checking and exception handling.
  • changed ImageMemoryHelper class from public to internal.
  • implemented opening files represented as MemoryStream from GhostscriptRasterizer and GhostscriptViewer. (that was some users request although there is no point of passing PDF as MemoryStream (or byte array) as it will anyway end up on the disk before it will be interpreted as PDF language, unlike the PostScript language, inherently requires random access to the file).

v.1.1.1.
  • fixed problem in GhostscriptRasterizer and GhostscriptViewer when MediaBox contains negative llx or lly values. (problem reported by "Prasenjit Das").
  • added GhostscriptPngDevice, a friendly output device class with all png devices related switches. (GhostscriptPngDevice supports: png16m, pngalpha, pnggray, png256, png16, pngmono, pngmonod).
  • added GhostscriptJpegDevice, a friendly output device class with all jpeg devices related switches. (GhostscriptJpegDevice supports: jpeg, jpeggray).
  • extended GhostscriptProcessor.StartProcessing method to support GhostscriptDevice base class as StartProcessing parameter.
  • for each constructor / method that requires GhostscriptVersionInfo parameter, now there is one more constructor / method available with a same functionality but without a need to pass GhostscriptVersionInfo parameter. This new constructors and methods automatically retrieves and use last installed Ghostscript version.
  • added new samples to the Ghostscript.NET.Samples project (AddWatermarkSample, ProcessorSample, DeviceUsageSample).

v.1.1.0.
  • added GhostscriptViewer state handling (SaveState, RestoreState)
  • GhostscriptRasterizer constructor is extended in order to support usage of the existing GhostscriptViewer instance.
  • fixed problem while using a 32-bit assembly with 32-bit version of Ghostscript on 64-bit Windows: It couldn't find a registry key of installed Ghostscript. Reported and fixed by "r0land".

v.1.0.9.
  • implemented EPS (Encapsulated PostScript) support for the GhostscriptViewer.
  • added GhostscriptRasterizer class which provides ability to easily export PDF pages, PostScript pages and EPS files to the System.Drawing.Image object in the memory. For each page different x and y dpi settings can be set.
  • fixed gsapi_stdin callback and it's value passing to the ghostscript library.
  • added ProgressiveUpdate property to the GhostscriptViewer class so progressive update can be controlled outside the library.

v.1.0.8.
  • implemented StopProcessing method in the GhostscriptProcessor class which allows us to terminate gsapiinitwith_args call in the multithread environment.
  • fixed GhostscriptViewer ZoomIn and ZoomOut problem on the systems where windows region and language settings has number decimal symbol set to comma.
  • added page navigation and zoom checker properties to the GhostscriptViewer class.
  • fixed problem in GhostscriptViewer class when trying to view PostScript files without DSC header.
  • GhostscriptProcessor.Process method name changed to StartProcessing.
Also check out Ghostscript Studio (http://ghostscriptstudio.codeplex.com/)

v.1.0.7.
  • implemented multi-page PostScript support for the GhostscriptViewer
  • included Microsoft.WinAny.Helper code files in order to have a single dll for the deployment
  • added Processing event to the GhostscriptProcessor class (with CurrentPage and TotalPages info)
  • added zoom-in and zoom-out functionality
  • fixed ImageMemoryHelper.Set24bppRgbImageColor function when stride size is not multiple of 3 bytes
  • fixed displayed page size
v.1.0.6.
  • implemented progressive display update while ghostscript is drawing / rasterizing, now a custom update interval can be set in GhostscriptViewer class.
  • fixed problem when using 64-bit ghostscript library where raster (stride) line size is not equal to 32-bit ghostscript library raster line size.
  • changed GhostscriptViewer class event logic.
  • changed Ghostscript.NET.Viewer application in order to show progressive update.
  • modified Ghostscript.NET.DisplayTest, now it uses GhostscriptViewer class with ability to interpret postscript and display standard input output messages.

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.

NuGet: PM> Install-Package Ghostscript.NET

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

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 postscrtip rasterizing via Ghostscript.NET.

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

 

Website counter

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 postscrtip rasterizing via Ghostscript.NET.

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

 

Website counter

New Post: Processing event of GhostscriptProcessor class

$
0
0
I am having difficulty subscribing to the Processing event of GhostscriptProcessor class. Any help would be greatly appreciated. Here's my code.

Public Class PostscriptToPDFConverter
Inherits Ghostscript.NET.Processor.GhostscriptProcessor

Public Event UpdateExtraInfo(ByRef lstrInfo As String, ByVal lblnLog As Boolean)

Public Sub Convert(lstrInputPSFile As String)

    Dim lstrOutputPDF As String = System.IO.Path.ChangeExtension(lstrInputPSFile, ".pdf")
    Dim lstrInfo As String = String.Empty

    lstrInfo = String.Format("Convert {0} to {1}", System.IO.Path.GetFileName(lstrInputPSFile), System.IO.Path.GetFileName(lstrOutputPDF))
    RaiseEvent UpdateExtraInfo(lstrInfo, True)

    Dim switches As New List(Of String)()
    switches.Add("-empty")
    switches.Add("-dQUIET")
    switches.Add("-dSAFER")
    switches.Add("-dBATCH")
    switches.Add("-dNOPAUSE")
    switches.Add("-dNOPROMPT")
    switches.Add("-sDEVICE=pdfwrite")
    switches.Add(String.Format("-sOutputFile={0}", lstrOutputPDF))
    switches.Add("-f")
    switches.Add(lstrInputPSFile)

    AddHandler MyBase.Processing, AddressOf GSProcessing
    MyBase.StartProcessing(switches.ToArray(), Nothing)
    RemoveHandler MyBase.Processing, AddressOf GSProcessing

End Sub

Private Sub GSProcessing(sender As Object, e As Ghostscript.NET.Processor.GhostscriptProcessorProcessingEventArgs)
    Dim lstrInfo As String = String.Format("Page: {0} out of {1}", e.CurrentPage, e.TotalPages)
    RaiseEvent UpdateExtraInfo(lstrInfo, True)
End Sub
End Class

New Post: Processing event of GhostscriptProcessor class

$
0
0
Hi,

Remove "switches.Add("-dQUIET")" as this switch suppresses routine information comments on standard output which Processing event relays on.

Cheers,
Josip

New Post: Processing event of GhostscriptProcessor class

$
0
0
Thanks for the prompt response, but it hasn't made any difference. I also tried commenting out all the switches below to see if they had any effect but still no event:-
' switches.Add("-dQUIET")
' switches.Add("-dSAFER")
' switches.Add("-dBATCH")
' switches.Add("-dNOPAUSE")
' switches.Add("-dNOPROMPT")

New Post: Processing event of GhostscriptProcessor class

$
0
0
Hi,

I did not saw earlier that you are converting PostScript to PDF. I spoke with the developers of the Ghostscript native library and they said that the thing is that a PDF file is a structured format which includes (amongst other things) a definition of the number of pages. PostScript is a streamable simple format and does not contain that information. Some PostScript files contain 'DSC' comments which declare the number of pages in the document. However these can include the not terribly useful 'atend' value, which means that the number of pages is defined at the end of the program. By which time, of course, an interpreter knows how many pages there are, because its processed them all.

That means that by default for the PostScript files there is no way to get back information from the Ghostscript which PostScript page is processing.

Cheers,
Josip

New Post: System.NullReferenceException when loading GhostscriptRasterizer from memory on Server 2012 R2

$
0
0
Hi,

First - thanks for the great library, it works very well on my win7 machine. I use it to convert PDFs to images, and the load from memory feature is particularly handy as it enables me to thread my application.

I've been trying to deploy this code onto a Windows Server 2012 R2 machine, but have been running into a problem when trying to load the GS library from memory.

To test - I've built the provided 'Ghostscript.NET.Samples' targeting x64 and .NET 4.5. The only thing that I changed in the whole project is the input/output path, and this line:
_rasterizer.Open(inputPdfPath, _lastInstalledVersion, true);
The built application works fine on a windows 7 x64 machine, with .NET 4.5 installed, but fails on a Server 2012 R2 x64 machine with the following stack trace:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Ghostscript.NET.Interpreter.GhostscriptInterpreter.Initialize() in c:\dev\Ghostscript.NET.v.1.1.2\Ghostscript.NET\Interpreter\GhostscriptInterpreter.cs:li
ne 152
   at Ghostscript.NET.Interpreter.GhostscriptInterpreter..ctor(GhostscriptVersionInfo version, Boolean fromMemory) in c:\dev\Ghostscript.NET.v.1.1.2\Ghostscript
.NET\Interpreter\GhostscriptInterpreter.cs:line 94
   at Ghostscript.NET.Viewer.GhostscriptViewer.Open(String path, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory) in c:\dev\Ghostscript.NET.v.1.1.2\Ghostscript.NET\Viewer\GhostscriptViewer.cs:line 282
   at Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open(String path, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory) in c:\dev\Ghostscript.NET.v.1.1.2\Ghostscript.NET\Rasterizer\GhostscriptRasterizer.cs:line 192
   at Ghostscript.NET.Samples.RasterizerSample.Start() in c:\dev\Ghostscript.NET.v.1.1.2\Ghostscript.NET.Samples\Samples\RasterizerSample.cs:line 67
   at Ghostscript.NET.Samples.Program.Main(String[] args) in c:\dev\Ghostscript.NET.v.1.1.2\Ghostscript.NET.Samples\Program.cs:line 55
If I change the above line to:
_rasterizer.Open(inputPdfPath, _lastInstalledVersion, false);
then everything works without any problems. However, then I can't thread the application.

I saw here that there might be an issue with .NET 4.5?

Any suggestions for a solution/workaround would be greatly appreciated.

I'm using ghostscript 9.10 and have tried the above with both versions 1.1.1 and 1.1.2 of Ghostscript.NET.

Many thanks,
Antony

New Post: Processing event of GhostscriptProcessor class

$
0
0
Makes sense. However couldn't it still trigger the event and just populate the e.CurrentPage property whilst leaving the e.TotalPages property at zero or minus one or something, just so we can show some on-screen activity during processing?

New Post: GhostscriptPipedInput needed

$
0
0
I want to render a pdf-file to a png-file but i want to do it in memory only.

The GhostscriptProcessor example uses the GhostscriptPipedOutput class. Are there any plans to implement a GhostscriptPipedInput class?

Cheers,
Seyko
Viewing all 393 articles
Browse latest View live


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