ArtifexSoftware / Ghostscript.NET

Ghostscript.NET - managed wrapper around the Ghostscript library (32-bit & 64-bit)
https://ghostscript.com
GNU Affero General Public License v3.0
391 stars 152 forks source link

Missing elements/colors when converting PDF to image #103

Open ivocoumans opened 2 years ago

ivocoumans commented 2 years ago

I am converting a PDF to an image using Ghostscript.NET. The process completes seemingly successful, however, some elements/colors are missing from the final image. Converting the PDF to an image using the gs command line, the image looks exactly as the original PDF.

When I use the Ghostscript.NET Viewer, I get the same result as Rasterizer.GetPage, which is missing elements. In the debug window, I can see Ghostscript has output several errors to STDOUT (not to STDERR) (see below for full output): **** Error reading a content stream. The page may be incomplete. Output may be incorrect.

I am trying to obtain more information about how the PDF was generated, but since it seems to work just fine with gs commandline and in several PDF readers I've tried, it looks like there's an issue with Ghostscript.NET. Note that I have already tried several versions of Ghostscript, including 9.54.0, 9.55.0 and 9.56.0 (using the workaround mentioned in #102). Due to that workaround I reverted to 9.55.0, but the resulting image is the same in all versions - the command line will produce a correct image, and using Ghostscript.NET will result in missing elements/colors.

I am happy to share the PDF privately if necessary, but due to its size and somewhat sensitive content, I would rather not post it publicly.

I've attached 3 files that show the missing elements/colors. The original PDF: 1_original_pdf

The output from gswin64c -sDevice=jpg -sOutputFile="c:\temp\output.jpg" c:\temp\input.pdf 2_gs_output

The output from Ghostscript.NET (as seen in the Viewer; see below for full debug output) 3_ghostscriptnet_output

The full output from the Viewer Debug window:

StdOut:
---------------------------------------------------------------------------
@GSNET_VIEWER -> COMMAND -> OPEN
GPL Ghostscript 9.55.0 (2021-09-27)
Copyright (C) 2021 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
%GSNET_VIEWER_PDF_PAGES: 1 1
%GSNET_VIEWER_PDF_PAGE: 1
%GSNET_VIEWER_PDF_MEDIA: [0 0 4648.82 2383.94]
%GSNET_VIEWER_PDF_CROP: [0 0 4648.82 2383.94]
%GSNET_VIEWER_PDF_ROTATE: 0
    **** Error reading a content stream. The page may be incomplete. Output may be incorrect.
    -many repetitions of above error-
    **** Error reading a content stream. The page may be incomplete. Output may be incorrect.
Loading NimbusSans-Italic font from %rom%Resource/Font/NimbusSans-Italic... 11847400 10145390 7751640 5551518 3 done.
Loading NimbusSans-Regular font from %rom%Resource/Font/NimbusSans-Regular... 12034712 10337341 7812240 5604431 3 done.
    **** Error reading a content stream. The page may be incomplete. Output may be incorrect.
    -many repetitions of above error-
    **** Error reading a content stream. The page may be incomplete. Output may be incorrect.
>>showpage, press <return> to continue<<

===========================================================================
StdErr:
---------------------------------------------------------------------------

===========================================================================