dampee / ImageProcessor.Plugins.Pdf

A PDF fileformat for ImageProcessor
MIT License
15 stars 10 forks source link

Page number is not in pages number range! #10

Open ghost opened 4 years ago

ghost commented 4 years ago

Just ran into your blogpost and awesome solution. Installed the plugin using NuGet, pulled the latest Ghostscript 9.50 (gsdll64.dll) assembly into the bin folder and used the following Razor to generate the image url: @Url.GetCropUrl(item, furtherOptions: "&format=jpg&width=500")

So far, so good but when viewing the image url, the following (not so good) exception is shown:

[GhostscriptException: Page number is not in pages number range!] Ghostscript.NET.Viewer.GhostscriptViewerPdfFormatHandler.InitPage(Int32 pageNumber) +206 Ghostscript.NET.Viewer.GhostscriptViewer.ShowPage(Int32 pageNumber, Boolean refresh) +160 Ghostscript.NET.Rasterizer.GhostscriptRasterizer.GetPage(Int32 xDpi, Int32 yDpi, Int32 pageNumber) +39 ImageProcessor.Plugins.Pdf.PdfRasterizer.Rasterize(Stream pdfStream, Int32 pageNumber) +54 ImageProcessor.ImageFactory.Load(Stream stream) +129 ImageProcessor.Web.HttpModules.<ProcessImageAsync>d__31.MoveNext() +4497 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar) +64 System.Web.AsyncEventExecutionStep.InvokeEndHandler(IAsyncResult ar) +209 System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +156

I don't have a clue as to what to do with the page number. Have I missed something?

ghost commented 4 years ago

Ok. Sort of resolved this, after running into this SO thread. It appears that since version 9.27 of Ghostscript, the GhostScriptRasterizer always returns 0 on PageCount. Replacing the gsdll64.dll with Ghostscript version 9.26 the image is returned properly.

So for anyone running into this, when adding the Ghostscript dll make sure you do not use any version after 9.26.

sebdigit commented 3 years ago

Apparently fixed here : https://github.com/jhabjan/Ghostscript.NET/issues/62#issuecomment-773243781