Imageresizer:如何在将PDF转换为PNG时修复GhostScript异常

时间:2014-03-20 02:49:44

标签: c# asp.net pdf ghostscript imageresizer

尝试使用ImageResizer(3.4.2)将PDF转换为PNG缩略图时,如下所示:

https://somehost.com/file.pdf?format=png&width=1024&height=1024&autorotate=true

有些PDF工作正常。其他人给出类似以下的例外情况:

ImageResizer.Plugins.PdfRenderer.Ghostscript.GhostscriptException: <pdf> <fileNameData><value>67</value><value>58</value><value>92</value><value>87</value><value>105</value><value>110</value><value>100</value><value>111</value><value>119</value><value>115</value><value>92</value><value>84</value><value>69</value><value>77</value><value>80</value><value>92</value><value>116</value><value>109</value><value>112</value><value>54</value><value>49</value><value>53</value><value>56</value><value>46</value><value>116</value><value>109</value><value>112</value></fileNameData> <pageCount>1</pageCount> <pages> <page number="1"> <mediaBox height="792" width="612" top="0" left="0"/> Error: /stackunderflow in --dup-- Operand stack: Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --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-- 2 1 1 --nostringval-- %for_pos_int_continue --nostringval-- Dictionary stack: --dict:1172/1684(ro)(G)-- --dict:1/20(G)-- --dict:84/200(L)-- --dict:84/200(L)-- --dict:109/127(ro)(G)-- --dict:292/300(ro)(G)-- --dict:26/32(L)-- Current allocation mode is local Current file position is 3951

Generated: Fri, 07 Mar 2014 17:14:21 GMT

ImageResizer.Plugins.PdfRenderer.Ghostscript.GhostscriptException: <pdf>
<fileNameData><value>67</value><value>58</value><value>92</value><value>87</value><value>105</value><value>110</value><value>100</value><value>111</value><value>119</value><value>115</value><value>92</value><value>84</value><value>69</value><value>77</value><value>80</value><value>92</value><value>116</value><value>109</value><value>112</value><value>54</value><value>49</value><value>53</value><value>56</value><value>46</value><value>116</value><value>109</value><value>112</value></fileNameData>
<pageCount>1</pageCount>
<pages>
<page number="1">
<mediaBox height="792" width="612" top="0" left="0"/>
Error: /stackunderflow in --dup--
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --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--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--
Dictionary stack:
   --dict:1172/1684(ro)(G)--   --dict:1/20(G)--   --dict:84/200(L)--   --dict:84/200(L)--   --dict:109/127(ro)(G)--   --dict:292/300(ro)(G)--   --dict:26/32(L)--
Current allocation mode is local
Current file position is 3951

   at ImageResizer.Plugins.PdfRenderer.Ghostscript.GhostscriptEngine.Execute(GhostscriptSettings settings)
   at ImageResizer.Plugins.PdfRenderer.PdfRendererPlugin.GetPdfInfo(String path)
   at ImageResizer.Plugins.PdfRenderer.PdfRendererPlugin.DecodeStream(Stream s, ResizeSettings settings, String optionalPath)
   at ImageResizer.Resizing.AbstractImageProcessor.DecodeStream(Stream s, ResizeSettings settings, String optionalPath)
   at ImageResizer.ImageBuilder.DecodeStream(Stream s, ResizeSettings settings, String optionalPath)
   at ImageResizer.ImageBuilder.LoadImage(Object source, ResizeSettings settings, Boolean restoreStreamPos)
   at ImageResizer.ImageBuilder.BuildJob(ImageJob job)
   at ImageResizer.ImageBuilder.Build(ImageJob job)
   at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings, Boolean disposeSource, Boolean addFileExtension)
   at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings, Boolean disposeSource)
   at ImageResizer.ImageBuilder.Build(Object source, Object dest, ResizeSettings settings)
   at ImageResizer.InterceptModule.<>c__DisplayClass3.<HandleRequest>b__2(Stream stream)
   at ImageResizer.Plugins.DiskCache.CustomDiskCache.<>c__DisplayClasse.<TryWriteFile>b__d()
   at ImageResizer.Plugins.DiskCache.LockProvider.TryExecute(String key, Int32 timeoutMs, LockCallback success)
   at ImageResizer.Plugins.DiskCache.CustomDiskCache.TryWriteFile(CacheResult result, String physicalPath, String relativePath, ResizeImageDelegate writeCallback, DateTime sourceModifiedUtc, Int32 timeoutMs, Boolean recheckFS)
   at ImageResizer.Plugins.DiskCache.CustomDiskCache.GetCachedFile(String keyBasis, String extension, ResizeImageDelegate writeCallback, DateTime sourceModifiedUtc, Int32 timeoutMs, Boolean asynchronous)
   at ImageResizer.Plugins.DiskCache.DiskCache.Process(IResponseArgs e)
   at ImageResizer.Plugins.DiskCache.DiskCache.Process(HttpContext context, IResponseArgs e)
   at ImageResizer.InterceptModule.HandleRequest(HttpContext context, String virtualPath, NameValueCollection queryString, IVirtualFile vf)
   at ImageResizer.InterceptModule.CheckRequest_PostAuthorizeRequest(Object sender, EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

我尝试了几种不同版本的Ghostscript,包括Imageresizer自动下载的版本以及sourceforge(9.10)的最新版本。

2 个答案:

答案 0 :(得分:1)

stackunderflow基本上告诉你PostScript无效。在这种情况下,程序试图复制(&#39; dup&#39;)堆栈上的对象,显然堆栈上没有对象,因此stackunderflow。

要调查我需要您正在使用的PDF副本以及传递给Ghostscript的确切命令行。如果您可以提供这两个,那么您应该通过从shell执行所述命令行来快速测试问题,如果它仍然出错,那么您可以在bugs.ghostscript.com上打开错误报告

答案 1 :(得分:0)

我遇到了同样的错误,我下载了PdfRenderer插件的sourcecode。在那里,您将在Ghostscript / Resources /目录中的ImageResizer.Plugins.PdfRenderer项目中找到PostScript(pdfInfo.ps)文件。

您可以修改此PostScript并保留以下部分:

% CropBox
dup /CropBox pget {
  aload pop   % NOTE: Elements are reversed when popping from stack 
  (<cropBox) print 
  ( height=") print =print (") print
  ( width=") print =print (") print
  ( top=") print =print (") print
  ( left=") print =print (") print
  (/>\n) print flush
} if

当然,您必须构建项目并使用输出dll。