This project is read-only.

some PDFs cannot be converted

Mar 12, 2014 at 10:05 AM
I am using one of the samples to convert the first page of the selected PDF to PNG.

public void PDF2PNGFirstPage(string PdfFilePath, string OutputFilePath)
        int desired_x_dpi = 96;
        int desired_y_dpi = 96;

        _lastInstalledVersion =
                    GhostscriptLicense.GPL | GhostscriptLicense.AFPL,

        _rasterizer = new GhostscriptRasterizer();
        _rasterizer.Open(PdfFilePath, _lastInstalledVersion, true);

        Image img = _rasterizer.GetPage(desired_x_dpi, desired_y_dpi, 1);
        img.Save(OutputFilePath, ImageFormat.Png);
Practically the only thing I changed is that i fixed the pgae number for _rasterizer.GetPage, it is constantly set to 1.

The problem is that the code works only with some PDFs (it can be multipage PDF of course). Some PDF-s throw "input string was not in a correct format". Any ideas?

I have GhostScript 9.10 32bits installed.
Mar 12, 2014 at 10:09 AM
I uploaded one of the problematic PDFs: sandero.pdf
Mar 12, 2014 at 10:40 AM
Edited Mar 12, 2014 at 10:42 AM

I tried this pdf on both 32 bit and 64 bit Ghostscript.NET and it works. I have a feeling that this is due dacritics. Can you tell me does your 'PdfFilePath' contains any diacritics like 'ćšäö'?

If yes, can you try to encode your 'PdfFilePath' to UTF8 like this:
string PdfFilePath = @"e:\äbc.pdf"; 
PdfFilePath= System.Text.Encoding.Default.GetString(System.Text.Encoding.UTF8.GetBytes(PdfFilePath)); 
and then use it in
_rasterizer.Open(PdfFilePath, _lastInstalledVersion, true);
Mar 12, 2014 at 11:59 AM
Thank you for your quick reply. Obviously it contains diacritics, I will try your suggestion.
Mar 12, 2014 at 9:02 PM
I checked it. The path (or file) names with special characters definitely cause problems. I can covert the sample PDF I uploaded formerly, but still have issues ("object reference is not set...") with some files. I uploaded another problematic sample (placed it into the same directory from wehere I can succesfuly convert the first pdf). Would you please check this as well?

Sample #2
Mar 20, 2014 at 3:05 PM
Edited Mar 20, 2014 at 3:05 PM
Hi ibram84,

The problem for the second PDF sample ("Sample #2") is a bad PDF file (not generated properly).

That PDF reports this:
Error: /rangecheck in --setdash--
Operand stack:
   --dict:6/7(L)--   --dict:6/7(L)--   --dict:6/7(L)--   10.0   --nostringval--   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   false   1   %stopped_push   1932   1   3   %oparray_pop   1931   1   3   %oparray_pop   1915   1   3   %oparray_pop   1803   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   1804   6   8   %oparray_pop
Dictionary stack:
   --dict:1186/1684(ro)(G)--   --dict:1/20(G)--   --dict:119/200(L)--   --dict:113/127(ro)(G)--   --dict:292/300(ro)(G)--   --dict:27/32(L)--   --dict:6/8(L)--   --dict:28/40(L)--