Problem with some PDF files

May 20, 2014 at 9:24 AM
I am using Ghostscript.net to convert PDF files to tiff files and most files are converted with no problem, but I have some files that are all created by the same scanner that Ghostscript.Net fails while converting. In some cases the Bitmaps returned are about 14 000 pixels wide, other times it fails when it tries to create a bitmap with 0 width and height.

Any suggestions on how to solve it?
Coordinator
May 21, 2014 at 7:20 AM
Hi,

Can you please upload sample PDF that creates bad result so I can test and debug it?

Cheers,
Josip
May 21, 2014 at 7:36 AM
I prefer not to upload it onto an publicly available location. Do you have a more direct way that i can use to sending it? (like an email)
Coordinator
May 21, 2014 at 8:13 AM
Sure, you can send it to my email address: habjan (at) gmail.com
Coordinator
May 21, 2014 at 12:09 PM
Ok, I got your files ( original and the one Acrobat changed ). I was testing this with Ghostscript.NET 1.1.8 and both PDF's shows correctly. Are you sure you sent correct files?

What version of Ghostscript.NET and native Ghostscript libraries you use ?
Which class from the Ghostscript.NET are you using to convert PDF to bitmap? GhostscriptRasterizer or GhostscriptProcessor or any other?

What DPIX and DPIY values are you using?

Cheers,
Josip
May 21, 2014 at 12:48 PM
The exact results are a bit unpredictable. I get different results when i run it on different computers (Windows Server 2008 R2 and Windows 7).

Using Latest versions of both.

On the windows server, it is using 64 bits Ghostscript, on the Windows 7 it is using the 32bit version.


The code for converting is:

(The stream is just a filestream)
            using (var rasterizer = new GhostscriptRasterizer())
            using (var memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);

                rasterizer.Open(memoryStream, gsversion, false);

                return this.CreateTiffFile(color, rasterizer);
            }
Snippet from CreateTiffFile
var page = rasterizer.GetPage(300, 300, i)
This fails with an ArgumentException at on my Windows 7 computer:
System.Drawing.dll!System.Drawing.Bitmap.Bitmap(int width, int height, System.Drawing.Imaging.PixelFormat format)   Unknown
Ghostscript.NET.dll!Ghostscript.NET.Viewer.GhostscriptViewerImage.GhostscriptViewerImage(int width, int height, int stride, System.Drawing.Imaging.PixelFormat format)  Unknown
Ghostscript.NET.dll!Ghostscript.NET.Viewer.GhostscriptViewerImage.Create(int width, int height, int stride, System.Drawing.Imaging.PixelFormat format)  Unknown
Ghostscript.NET.dll!Ghostscript.NET.Viewer.GhostscriptViewerDisplayHandler.Presize(System.IntPtr handle, System.IntPtr device, int width, int height, int raster, uint format)  Unknown
Ghostscript.NET.dll!Ghostscript.NET.GhostscriptDisplayDeviceHandler.display_presize(System.IntPtr handle, System.IntPtr device, int width, int height, int raster, uint format) Unknown
[Native to Managed Transition]  
[Managed to Native Transition]  
Ghostscript.NET.dll!Ghostscript.NET.Interpreter.GhostscriptInterpreter.Run(string str)  Unknown
Ghostscript.NET.dll!Ghostscript.NET.Viewer.GhostscriptViewer.ShowPage(int pageNumber, bool refresh) Unknown
Ghostscript.NET.dll!Ghostscript.NET.Rasterizer.GhostscriptRasterizer.GetPage(int xDpi, int yDpi, int pageNumber)    Unknown
If i debug with the soruce for Ghostscript.Net available i see that it is because it tries to create a document with zero height and width.
Coordinator
May 26, 2014 at 9:46 AM
That's strange. I'm using Windows 7 (64 bit) and I cannot reproduce this problem.

If you take a look at the https://github.com/jhabjan/Ghostscript.NET/blob/master/Ghostscript.NET/Viewer/FormatHandlers/GhostscriptViewerPdfFormatHandler.cs you will see that page size is read out from the PDF_MEDIA_TAG and / or PDF_CROP_TAG. If you put breakpoints to that bits of code, can you check what values are read out?

Other solution would be to try to use other classes from the Ghostscript to rasterize PDF's to image: https://github.com/jhabjan/Ghostscript.NET/blob/master/Ghostscript.NET.Samples/Samples/DeviceUsageSample.cs

Cheers,
Josip