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

New Post: Get the CMYK Color Values from a PDF using GhostScript.NET ?

$
0
0
Hi,

I need to get the CMYK values used for rendering from the PDF.
I think they are the values range 0 - 1.0 under the C1 key. Anyone knows how to get them ?

Thanks.

Adi

New Post: Regarding conversion of PDF files

$
0
0
Well, this should be possible. As a rule of thumb: Everything you can do with Ghostscript can also be done with ghostscript.net
So you should first try out Ghostscript itself ;-)

Make yourself familiar with its command line syntax as this is exactly what you need when using ghostscript.net for the same task.

New Post: save pdf as image tiff ccitg4

$
0
0
               var desiredDpi = 150;

                var dtStartAnalysis = DateTime.Now;
                using (var rasterizer = new GhostscriptRasterizer())
                {
                    var ms = new MemoryStream(request.DocumentBytes);
                    rasterizer.Open(ms);

                    var codec = ImageCodecInfo.GetImageEncoders().Where(ice => ice.MimeType == "image/tiff").ElementAt(0);
                    var encoderParams = new EncoderParameters(1);
                    encoderParams.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4); 

                    for (var pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
                    {
                        var img = rasterizer.GetPage(desiredDpi, desiredDpi, pageNumber);
                        var newImg = new Bitmap(img.Width, img.Height);

                        //this section converts the image to grayscale prior to slapping it down
                        var g = Graphics.FromImage(newImg);
                        var colorMatrix = new ColorMatrix(
                            new[]
                            {
                                new[] {.3f, .3f, .3f, 0, 0},
                                new[] {.59f, .59f, .59f, 0, 0},
                                new[] {.11f, .11f, .11f, 0, 0},
                                new[] {0f, 0, 0, 1, 0},
                                new[] {0f, 0, 0, 0, 1}
                            });

                        var attributes = new ImageAttributes();
                        attributes.SetColorMatrix(colorMatrix);
                        attributes.SetThreshold(0.8f); //threshold for switching gray to black or white
                        g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attributes);
                        g.Dispose();

                        using (var targetStream = new MemoryStream())
                        {
                            newImg.Save(targetStream, codec, encoderParams);
                        }
                    }
                }

                Trace.WriteLine(string.Format("Converted PDF to TIFF images in {0}", (DateTime.Now - dtStartAnalysis).TotalMilliseconds));
Here's how I'm converting pdf to tiff currently. Specifically to tiff, if you're using CCITT4 you want to make sure your pdf image is converted to bitonal, otherwise you will have loss of any image that's lightly drawn on the page.

The ColorMatrix and the SetThreshold() settings work in my specific case but anyone trying this on their own PDF documents should be aware that you may have to mess with those settings (at least with the threshold).

-DM

New Post: save pdf as image tiff ccitg4

$
0
0
The only concern I have is the speed at which this line is executed:
var img = rasterizer.GetPage(desiredDpi, desiredDpi, pageNumber);
On a pdf with ~1MB page size and 150 DPI it's ~1.5-2 seconds and I have some PDFs with 35 or more pages+. It takes me between 45 and 60 seconds to convert a 35-page PDF.

I'm actually using this to downconvert the pdfs into something more manageable. Unfortunately changing the size of the source PDF at this point is not going to happen.

Is there anything I can do to optimize the GetPage() process? DPI has to stay at 150, any lower and the pdf becomes unreadable.

Thanks.

New Post: How to append postscript code to command line (-c)?

$
0
0
Hi!

I've spent a few hours trying to get StartProcessing accept a "-c" command line switch but somehow, it always ends up in an -100 exception.

In general, I'm trying the following:
With cmdline
                .Add("-empty")
                .Add("-dNOPAUSE")
                .Add("-dBATCH")
                .Add("-dQUIET")
                .Add("-dSAFER")
                .Add("-dNOPROMPT")
                .Add("-q")
                .Add("-o test.tif")
                .Add("-sDEVICE=tiff24nc")
                .Add("-r600")
                .Add(" -c ""<</Install {-14 -14 translate}>> setpagedevice""")
                .Add("-fTEST.pdf")
End With
GSProc.StartProcessing(cmdline.ToArray(), Nothing)
But this always leads to an -100 exception unless I remove the -c part of the command line. Somehow I guess that it has something to do with the escaping of the quotation marks around the postscript code but I didn't find any other way to build the string.

Stepping through the code, I see that the string gets converted to
" -c \"<</Install {-14 -14 translate}>> setpagedevice\""
which seems to look absolutely okay when talking about C# ... but somehow, Ghostscript refuses to accept it that way.

Is there anything I can do?

Any help would be greatly appreciated ;-)

New Post: How to append postscript code to command line (-c)?

$
0
0
This works:
    Sub Main()
        Dim gp As GhostscriptProcessor = New GhostscriptProcessor()
        Dim cmdline As List(Of String) = New List(Of String)

        With cmdline
            .Add("-empty")
            .Add("-dNOPAUSE")
            .Add("-dBATCH")
            .Add("-dQUIET")
            .Add("-dSAFER")
            .Add("-dNOPROMPT")
            .Add("-q")
            .Add("-sDEVICE=tiff24nc")
            .Add("-r600")
            .Add("-sOutputFile=E:\__test_data\out\test.tif")
            .Add("-c")
            .Add("<</Install {-14 -14 translate}>> setpagedevice")
            .Add("-f")
            .Add("E:\__test_data\in\test.pdf")
        End With

        gp.StartProcessing(cmdline.ToArray(), Nothing)
        gp.Dispose()
    End Sub
Cheers,
Josip

New Post: Print PDF file?

New Post: Get the CMYK Color Values from a PDF using GhostScript.NET ?


New Post: How to append postscript code to command line (-c)?

$
0
0
Great!

As always, thanks for your fantastic work ;-)

Created Release: Ghostscript.NET v.1.2.0. (Feb 05, 2015)

$
0
0
v.1.2.0.
  • fixed problem with checking for pdf file header signature in pdf files that has extra bytes at the beginning of the file before the actual signature.
  • fixed problem with the page rasterized to Image object which is kept in memory being disposed after the GhostscriptRasterizer is closed.
  • added ability to set custom switches for GhostscriptRasterizer and GhostscriptViewer.
  • added more usage examples.

v.1.1.9.
  • fixed problem with the PDF invisible layers (the optional content groups which will be left unmarked if processtrailerattrs is not executed).
  • fixed text rasterization problem for some pdf's, it seems that the 'pdfopen begin' did not initialize everything required to render pdf properly so we replaced it with the 'runpdfopen' method which corrects everything (problem reported by "xatabhk").
  • changed GhostscriptRasterizer methods to support Stream insted of the MemoryStream.
  • fixed handling files without the extension in GhostscriptViewer and Rasterizer.

v.1.1.8.
  • fixed incompatibility problem with 'gsapisetarg_encoding' function in Ghostscript releases prior to 9.10. (this function was introduced in 9.10 release)
  • fixed older versions incompatibility problem with '-dMaxBitmap=1g' switch bugfix which in some cases turns on text antialiasing for Ghostscript 9.14
  • added better initialization checking

v.1.1.7.
  • implemented Ghostscript native library verification with a friendly error message that will clear out the confusion when used native Ghostscript library is not compatibile with the running process.
  • fixed the pipe client handle disposal bug when the GhostscriptPipedOutput is used.
  • fixed problem with the applying PDF page orientation for the GhostscriptViewer and the GhostscriptRasterizer.

v.1.1.6.
  • simplified GetInstalledVersions and GetLastInstalledVersion functions
  • fixed problem with the CropBox in the GhostscriptViewer and GhostscripRasterizer (reported by "mahbuburrahman").
  • license changed to AGPL

v.1.1.5.
  • fixed the default cropping to the BoundingBox problem for the EPS file format in the GhostscriptViewer and GhostscriptRasterizer (reported by "midora").
  • exposed GhostscriptViewer.EPSClip and GhostscriptRasterizer.EPSClip properties with a default value set to true (affects only EPS format).
  • fixed problem with the paths that contains diacritics (reported by "GambitRicky")
  • added GhostscriptProcessor.Started and GhostscriptProcessor.Completed events (requested by "Ray H.").
  • all methods that works with MemoryStream are changed to use a generic Stream type (suggested by "midora").

v.1.1.4.
  • fixed problem with applying GraphicsAlphaBits and TextAlphaBits which improved antialiasing in GhostscriptViewer and GhostscriptRasterizer.
  • fixed problem with output through main stderr callback handler.
  • added support for MemoryStream in the GhostscriptPdfInfo.GetInkCoverage method.
  • added GraphicsAlphaBits and TextAlphaBits properties in GhostscriptViewer and GhostscriptRasterizer so antialiasing can now be changed from the outside...

v.1.1.3.
  • added GhostscriptPdfInfo.GetInkCoverage function which has ability to return ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally). This function can be used to check if the pdf is grayscale or color.
  • fixed problem with opening MemoryStream EPS files which contains "EPS Preview Header" (reported by "Chanan Eli")
  • fixed problem with empty %%BoundingBox value when handling PostScript files (thanks to by "Shane_S")
  • fixed problem with rasterizing EPS files created with Adobe Illustrator (reported by "Chanan Eli")
  • fixed problem with retrieving exported function handle in DynamicNativeLibrary noticed on the Server 2012 R2 with large amount of memory (thanks to "antonyoni")
  • assembly is now signed with a strong name key (requested by "netmajor")

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 native Ghostscript library (32-bit & 64-bit), an interpreter for the PostScript language, PDF, related software and documentation.

Source code here is not up-to-date. Latest source code and binaries (v.1.2.0) can be found onGitHubhttps://github.com/jhabjan/Ghostscript.NET

Contains:

  • GhostscriptViewer - View PDF, EPS or multi-page PostScript files on the screen
  • GhostscriptRasterizer - Rasterize PDF, EPS or multi-page PostScript files to any common image format.
  • GhostscriptProcessor - An easy way to call a Ghostscript library with a custom arguments / switches.
  • GhostscriptInterpreter - The PostScript interpreter.

Other features:

  • allows you to rasterize files in memory without storing the output to disk.
  • supports zoom-in and zoom-out.
  • supports progressive update.
  • allows you to run multiple Ghostscript instances simultaneously within a single process.
  • compatible with 32-bit and 64-bit Ghostscript native library.


If you have found Ghostscript.NET useful and has contributed to your projectconsider donating. Donating helps support Ghostscript.NET.

Click here to lend your support to: Ghostscript.NET and make a donation at pledgie.com !

 

NuGet: PM> Install-Package Ghostscript.NET

 

Used in the Ghostscript Studio (Ghostscript IDE)

                                                       

Samples built on the top of the Ghostscript.NET library:

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

  Ghostscript.NET.Viewer 

Direct postscript interpretation via Ghostscript.NET.

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

Released: Ghostscript.NET v.1.2.0. (Feb 05, 2015)

$
0
0
If you have found Ghostscript.NET useful and has contributed to your project consider donating.

My Image

v.1.2.0.
  • fixed problem with checking for pdf file header signature in pdf files that has extra bytes at the beginning of the file before the actual signature.
  • fixed problem with the page rasterized to Image object which is kept in memory being disposed after the GhostscriptRasterizer is closed.
  • added ability to set custom switches for GhostscriptRasterizer and GhostscriptViewer.
  • added more usage examples.

v.1.1.9.
  • fixed problem with the PDF invisible layers (the optional content groups which will be left unmarked if processtrailerattrs is not executed).
  • fixed text rasterization problem for some pdf's, it seems that the 'pdfopen begin' did not initialize everything required to render pdf properly so we replaced it with the 'runpdfopen' method which corrects everything (problem reported by "xatabhk").
  • changed GhostscriptRasterizer methods to support Stream insted of the MemoryStream.
  • fixed handling files without the extension in GhostscriptViewer and Rasterizer.

v.1.1.8.
  • fixed incompatibility problem with 'gsapisetarg_encoding' function in Ghostscript releases prior to 9.10. (this function was introduced in 9.10 release)
  • fixed older versions incompatibility problem with '-dMaxBitmap=1g' switch bugfix which in some cases turns on text antialiasing for Ghostscript 9.14
  • added better initialization checking

v.1.1.7.
  • implemented Ghostscript native library verification with a friendly error message that will clear out the confusion when used native Ghostscript library is not compatibile with the running process.
  • fixed the pipe client handle disposal bug when the GhostscriptPipedOutput is used.
  • fixed problem with the applying PDF page orientation for the GhostscriptViewer and the GhostscriptRasterizer.

v.1.1.6.
  • simplified GetInstalledVersions and GetLastInstalledVersion functions
  • fixed problem with the CropBox in the GhostscriptViewer and GhostscripRasterizer (reported by "mahbuburrahman").
  • license changed to AGPL

v.1.1.5.
  • fixed the default cropping to the BoundingBox problem for the EPS file format in the GhostscriptViewer and GhostscriptRasterizer (reported by "midora").
  • exposed GhostscriptViewer.EPSClip and GhostscriptRasterizer.EPSClip properties with a default value set to true (affects only EPS format).
  • fixed problem with the paths that contains diacritics (reported by "GambitRicky")
  • added GhostscriptProcessor.Started and GhostscriptProcessor.Completed events (requested by "Ray H.").
  • all methods that works with MemoryStream are changed to use a generic Stream type (suggested by "midora").

v.1.1.4.
  • fixed problem with applying GraphicsAlphaBits and TextAlphaBits which improved antialiasing in GhostscriptViewer and GhostscriptRasterizer.
  • fixed problem with output through main stderr callback handler.
  • added support for MemoryStream in the GhostscriptPdfInfo.GetInkCoverage method.
  • added GraphicsAlphaBits and TextAlphaBits properties in GhostscriptViewer and GhostscriptRasterizer so antialiasing can now be changed from the outside...

v.1.1.3.
  • added GhostscriptPdfInfo.GetInkCoverage function which has ability to return ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally). This function can be used to check if the pdf is grayscale or color.
  • fixed problem with opening MemoryStream EPS files which contains "EPS Preview Header" (reported by "Chanan Eli")
  • fixed problem with empty %%BoundingBox value when handling PostScript files (thanks to by "Shane_S")
  • fixed problem with rasterizing EPS files created with Adobe Illustrator (reported by "Chanan Eli")
  • fixed problem with retrieving exported function handle in DynamicNativeLibrary noticed on the Server 2012 R2 with large amount of memory (thanks to "antonyoni")
  • assembly is now signed with a strong name key (requested by "netmajor")

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 Release: Ghostscript.NET v.1.2.0. (Feb 05, 2015)

$
0
0
If you have found Ghostscript.NET useful and has contributed to your project consider donating.

My Image

v.1.2.0.
  • fixed problem with checking for pdf file header signature in pdf files that has extra bytes at the beginning of the file before the actual signature.
  • fixed problem with the page rasterized to Image object which is kept in memory being disposed after the GhostscriptRasterizer is closed.
  • added ability to set custom switches for GhostscriptRasterizer and GhostscriptViewer.
  • added more usage examples.

v.1.1.9.
  • fixed problem with the PDF invisible layers (the optional content groups which will be left unmarked if processtrailerattrs is not executed).
  • fixed text rasterization problem for some pdf's, it seems that the 'pdfopen begin' did not initialize everything required to render pdf properly so we replaced it with the 'runpdfopen' method which corrects everything (problem reported by "xatabhk").
  • changed GhostscriptRasterizer methods to support Stream insted of the MemoryStream.
  • fixed handling files without the extension in GhostscriptViewer and Rasterizer.

v.1.1.8.
  • fixed incompatibility problem with 'gsapisetarg_encoding' function in Ghostscript releases prior to 9.10. (this function was introduced in 9.10 release)
  • fixed older versions incompatibility problem with '-dMaxBitmap=1g' switch bugfix which in some cases turns on text antialiasing for Ghostscript 9.14
  • added better initialization checking

v.1.1.7.
  • implemented Ghostscript native library verification with a friendly error message that will clear out the confusion when used native Ghostscript library is not compatibile with the running process.
  • fixed the pipe client handle disposal bug when the GhostscriptPipedOutput is used.
  • fixed problem with the applying PDF page orientation for the GhostscriptViewer and the GhostscriptRasterizer.

v.1.1.6.
  • simplified GetInstalledVersions and GetLastInstalledVersion functions
  • fixed problem with the CropBox in the GhostscriptViewer and GhostscripRasterizer (reported by "mahbuburrahman").
  • license changed to AGPL

v.1.1.5.
  • fixed the default cropping to the BoundingBox problem for the EPS file format in the GhostscriptViewer and GhostscriptRasterizer (reported by "midora").
  • exposed GhostscriptViewer.EPSClip and GhostscriptRasterizer.EPSClip properties with a default value set to true (affects only EPS format).
  • fixed problem with the paths that contains diacritics (reported by "GambitRicky")
  • added GhostscriptProcessor.Started and GhostscriptProcessor.Completed events (requested by "Ray H.").
  • all methods that works with MemoryStream are changed to use a generic Stream type (suggested by "midora").

v.1.1.4.
  • fixed problem with applying GraphicsAlphaBits and TextAlphaBits which improved antialiasing in GhostscriptViewer and GhostscriptRasterizer.
  • fixed problem with output through main stderr callback handler.
  • added support for MemoryStream in the GhostscriptPdfInfo.GetInkCoverage method.
  • added GraphicsAlphaBits and TextAlphaBits properties in GhostscriptViewer and GhostscriptRasterizer so antialiasing can now be changed from the outside...

v.1.1.3.
  • added GhostscriptPdfInfo.GetInkCoverage function which has ability to return ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally). This function can be used to check if the pdf is grayscale or color.
  • fixed problem with opening MemoryStream EPS files which contains "EPS Preview Header" (reported by "Chanan Eli")
  • fixed problem with empty %%BoundingBox value when handling PostScript files (thanks to by "Shane_S")
  • fixed problem with rasterizing EPS files created with Adobe Illustrator (reported by "Chanan Eli")
  • fixed problem with retrieving exported function handle in DynamicNativeLibrary noticed on the Server 2012 R2 with large amount of memory (thanks to "antonyoni")
  • assembly is now signed with a strong name key (requested by "netmajor")

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.

New Post: Cannot display correct Khmer (Cambodia Language) after convert by GS

$
0
0
I am now working for a Cambodia VB.Net project which required user to fill in data in the web form and then display the value in a pdf form. After that, the pdf need to convert to jpg file. Currently, I can capture Khmer in the .Net front end and then use dynamic pdf to fill in the data into the pdf file. However, when I using the Ghostscript.NET.dll (vers 1.1.4.0) to convert the pdf to jpg, the Khmer language will become incorrect.

New Post: Cannot display correct Khmer (Cambodia Language) after convert by GS

$
0
0
Hi,

You are using a bit old version of Ghostscript.NET. Latest version released couple of days a go is Ghostscript.NET v.1.2.0. What native Ghostscript library version do you use? Ghostscript v.9.15 ?

It would be good if you could email me a sample pdf that gives you the bad result after converting to jpg so I can debug it.

You can email it to: habjan@gmail.com

Cheers,
Josip

New Post: Open methoed of GhostscriptRasterizer failes

$
0
0
I been looking to try this library with vb.net

I have this code:
        Dim s As String = "C:\Users\AlbertKallal\Desktop\Deskhold\2013_salaryreport.pdf"

        Dim gVER As GhostscriptVersionInfo
        gVER = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL, GhostscriptLicense.GPL)

        Dim gPDF As New GhostscriptRasterizer
        gPDF.Open(s)
I keep getting this exception:

An error occurred when call to 'gsapi_init_with_args' is made: -15"

I also tried this for the open method:

gPDF.Open(s, gVER, False)

I installed this via NuGet into vs2013 (Ghostscript.NET.1.2.0).

I tried setting the project framework to 4.5, 4, and also set target CPU to x86. (none of these changes made any difference)

Any tips or suggestions to get the above code to run?
My first goal would be to simply obtain the number of pages in the pdf file. (gPDF.PageCount), but I cannot get past the “open” command. Do I need to set any of the custom switches before attempting the open method?

Regards,
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada

New Post: Send output to variable in place of file

$
0
0
I have the following code that simply converts the first page of a pdf to text.
        Dim gVER As GhostscriptVersionInfo = _
                    GhostscriptVersionInfo.GetLastInstalledVersion(Ghostscript.NET.GhostscriptLicense.GPL, _
                                                                   Ghostscript.NET.GhostscriptLicense.GPL)

        Dim gP As New Ghostscript.NET.Processor.GhostscriptProcessor(gVER, True)

        Dim Myargs As New List(Of String)
        With Myargs
            .Add("-q")
            .Add("-dSAFER")
            .Add("-dBATCH")
            .Add("-dNOPAUSE")
            .Add("-dNOPROMPT")
            .Add("-dFirstPage=1")
            .Add("-dLastPage=1")
            .Add("-sDEVICE=txtwrite")
            .Add("-sOutputFile=c:\MyFolder\output.txt")
            .Add("-fc:\MyFolder\hello.pdf")
        End With

        gP.Process(Myargs.ToArray)
After above is done, I have to read the output file back into a string variable.

Is there anyway to send the output into some kind of file stream variable in place of sending out to a text file? (I actually don’t need to keep nor want the text file).

Open to any suggestions.

Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada

New Post: Send output to variable in place of file

$
0
0
Hi Albert,

You can achieve that by using pipes. Here is C# example:
using Ghostscript.NET.Processor;

namespace Ghostscript.NET.Samples
{
    /// <summary>
    /// Sample that demonstrates how to tell Ghostscript to write the output result to 
    /// an anonymous pipe (memory) instead of the writing it to the disk.
    /// </summary>
    public class PipedOutputSample : ISample
    {
        public void Start()
        {
            string inputFile = @"E:\__test_data\test2.pdf";

            GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();

            // pipe handle format: %handle%hexvalue
            string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");

            using (GhostscriptProcessor processor = new GhostscriptProcessor())
            {
                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=txtwrite");
                switches.Add("-o" + outputPipeHandle);
                switches.Add("-q");
                switches.Add("-f");
                switches.Add(inputFile);

                try
                {
                    processor.StartProcessing(switches.ToArray(), null);

                    byte[] rawDocumentData = gsPipedOutput.Data;

                    string txtOutput = System.Text.Encoding.UTF8.GetString(rawDocumentData);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    gsPipedOutput.Dispose();
                    gsPipedOutput = null;
                }
            }
        }
    }
}
I hope that helps.

Cheers,
Josip

New Post: Open methoed of GhostscriptRasterizer failes

$
0
0
Hi Albert,

Sorry for a late response.

Error -15 means "rangecheck" error. But since you used Ghostscript 8.15 (which is a bit old version) it's not surprising as Ghostscript.NET is tested with native Ghostscript library 9.0 and on.

If you want to use Ghostscript.NET in both x86 and x64 environments and your projecct target CPU is 'Any', you need to install both native Ghostscript libraries:

x86; gs915w32 -> http://downloads.ghostscript.com/public/gs915w32.exe
x64: gs915w64-> http://downloads.ghostscript.com/public/gs915w64.exe

Cheers,
Josip

New Post: Send output to variable in place of file

$
0
0
That does indeed work. Thank you VERY kindly for this.

I do have a number of pdf files that errors out if I don’t restrict the page range 1 to 1.

I will see if I can follow up if they are just bad pdf files (and thus really a GS issue, not your code)

And for the readers, here is the vb.net version.
        Dim strPDF As String = "c:\MyFolder\b.pdf"

        Dim gP As New Ghostscript.NET.Processor.GhostscriptProcessor()
        Dim gpH As New Ghostscript.NET.GhostscriptPipedOutput
        Dim outputPieHande As String = "%handle%" + CInt(gpH.ClientHandle).ToString("X2")

        Dim Myargs As New List(Of String)
        With Myargs
            .Add("-empty")
            .Add("-dSAFER")
            .Add("-dBATCH")
            .Add("-dNOPAUSE")
            .Add("-dNOPROMPT")
            .Add("-dFirstPage=1")
            .Add("-dLastPage=1")
            .Add("-sDEVICE=txtwrite")
            .Add("-o" & outputPieHande)
            .Add("-q")
            .Add("-f")
            .Add(strPDF)
        End With

        gP.StartProcessing(Myargs.ToArray, Nothing)

        Dim raw As Byte() = gpH.Data
        Dim strOut = System.Text.Encoding.UTF8.GetString(raw)
        gpH.Dispose()

        MsgBox(strOut)
Once again, a real kind thumbs up for your short example, as I am sure many will benefit from this.

Regards,
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
Viewing all 393 articles
Browse latest View live


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