Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • DonZalmrol 220 posts 833 karma points
    Apr 19, 2017 @ 13:53
    DonZalmrol
    0

    Preview PDF files as images on your website

    Hi all,

    I've found this neat article of Damiaan on his blog about displaying PDFs as an image on your website.

    http://blog.dampee.be/post/2017/01/09/Preview-PDF-files-as-images-on-your-website.aspx

    Damiaan already informed me that I can donwload the nuget file and extract it by changing the extension to .zip. Then you only need to add the DLL files to the /bin folder.

    But now how can I integrate this in my website directly from within Umbraco? (So without using Visual Studio).

    Thanks and kr,

    Laurens

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 19, 2017 @ 17:41
    Damiaan
    1

    Hi Laurens

    It's pretty easy. You just use the ImageProcessor plugin, which will call the plugin i've written.

    If you have an image just add ?width=800 in the image URL (or use GetCropUrl) and you'll get an image of 800 width. If the input is a PDF, the plugin will be called by ImageProcessor. You don't need to do anything else.

    Should work flawless

    Kind regards Damiaan

  • DonZalmrol 220 posts 833 karma points
    Apr 21, 2017 @ 14:40
    DonZalmrol
    0

    Hi Damiaan,

    Just imported the DLL to my bin folder of our dev environment. Sounds silly, but how can I call the pdf be shown as an image?

    Thanks,

    Laurens

    EDIT:

    Tried the following from https://github.com/dampee/ImageProcessor.Plugins.Pdf/

    /myfile.pdf?format=jpg&width=500

    And it fetches my pdf URL, but it doesn't displays it as an image. This leaves me to believe that the DLL isn't called.

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 21, 2017 @ 15:15
    Damiaan
    0

    If you try the same thing with a image, does it work?

    If so, the plug-in is not loaded into ImageProcessor (and we have to find out why).

    If not, then imageprocessor is not working for some reason.

  • DonZalmrol 220 posts 833 karma points
    Apr 21, 2017 @ 15:18
    DonZalmrol
    0

    The imageprocessor is installed by default right?

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 21, 2017 @ 15:19
    Damiaan
    0

    In umbraco? Yes it is.

  • DonZalmrol 220 posts 833 karma points
    Apr 21, 2017 @ 15:28
    DonZalmrol
    0

    Hmm ok, thought so :)

    This is how I load in the pdf:

    <img src="@Umbraco.TypedMedia(@temp.value).Url?format=jpg&width=500"/>
    

    @temp.value is the media ID of the PDF.

    And it pulls the correct URL, but doesn't load the image/ or plugin: /media/xxxx/2016-half-year-report-en.pdf

  • Sven Geusens 169 posts 881 karma points c-trib
    Apr 21, 2017 @ 15:45
    Sven Geusens
    0

    Hey, Damiaan's minion here

    try

    <img src="@(Umbraco.TypedMedia(@temp.value).Url)?format=jpg&width=500"/>
    

    Maybe razor is having problems with the ?

  • DonZalmrol 220 posts 833 karma points
    Apr 21, 2017 @ 15:48
    DonZalmrol
    0

    Hi Sven,

    Afraid it's not working :( I don't get any errors and the '?' shouldn't be a problem as I'm using it for Imagegen.

  • Sven Geusens 169 posts 881 karma points c-trib
    Apr 21, 2017 @ 15:51
    Sven Geusens
    0

    Did you supply a ghostscript dll as instructed on the github readme?

  • DonZalmrol 220 posts 833 karma points
    Apr 21, 2017 @ 15:52
    DonZalmrol
    0

    It's in the bin folder. Do I need to call it (or anything else) in the razor script?

    enter image description here enter image description here

  • Sven Geusens 169 posts 881 karma points c-trib
    Apr 21, 2017 @ 16:05
    Sven Geusens
    0

    Just to make sure.

    Files that should be present in your bin

    • Ghostscript.NET.dll
    • ImageProcessor.Plugins.Pdf.dll
    • ImageProcessor.dll
    • gsdll32.dll or gsdll64.dll

    If all those files are in your bin, it should work out of the box without any other configuration.

  • DonZalmrol 220 posts 833 karma points
    Apr 21, 2017 @ 16:11
    DonZalmrol
    0

    Those are in there. Added the Ghostscript.NET.dll after your previous reply.

    I have both the 32b or 64b. I'll disable one of them.

    EDIT1: Not working :( EDIT2: Switching doesn't change it neither.

    I have the feeling that the dll isn't called properly.

  • Sven Geusens 169 posts 881 karma points c-trib
    Apr 21, 2017 @ 16:14
    Sven Geusens
    0

    I will let Damiaan pick this up when he has the time as I am out of ideas. Sorry I couldn't get it to work.

    Edit: just out of curiosity, what actual url do you get on the html page when you use <img src="@Umbraco.TypedMedia(@temp.value).GetCropUrl(width:500)"/>

  • DonZalmrol 220 posts 833 karma points
    Apr 21, 2017 @ 16:17
    DonZalmrol
    0

    No problem, thanks for trying. :)

    I'm going to look from where it's coming as well. Could maybe be another plugin that's acting up.

    The DLL's are loaded in correctly from what I can see. If I find something, I will post it here as well!

  • DonZalmrol 220 posts 833 karma points
    Apr 21, 2017 @ 16:22
    DonZalmrol
    0

    Aha, getting there I believe. Seems I'm receiving this error when I call directly the URL of the PDF with the '?' parameters behind it.

    Server Error in '/' Application.
    This managed library is running under 32-bit process and requires 32-bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: Ghostscript.NET.GhostscriptLibraryNotInstalledException: This managed library is running under 32-bit process and requires 32-bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html
    
    Source Error:
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    
    Stack Trace:
    
    
    [GhostscriptLibraryNotInstalledException: This managed library is running under 32-bit process and requires 32-bit Ghostscript native library installation on this machine! To download proper Ghostscript native library please visit: http://www.ghostscript.com/download/gsdnld.html]
       Ghostscript.NET.GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense licenseType, GhostscriptLicense licensePriority) +265
       ImageProcessor.Plugins.Pdf.PdfRasterizer..ctor(Int32 xDpi, Int32 yDpi) +83
       ImageProcessor.Plugins.Pdf.PdfFormat.Load(Stream stream) +181
       ImageProcessor.ImageFactory.Load(Stream stream) +97
       ImageProcessor.Web.HttpModules.<ProcessImageAsync>d__34.MoveNext() +2399
       System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
       System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar) +71
       System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9770477
    
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 22, 2017 @ 12:19
    Dave Woestenborghs
    0

    Hi Laurens,

    I just had a look at the GhostScript.NET source code. The exception is thrown from the method Ghostscript.NET.GhostscriptVersionInfo.GetLastInstalledVersion. The source code for that you can find here : https://github.com/jhabjan/Ghostscript.NET/blob/93776b5f0c6284c27d69488227c07660b868734d/Ghostscript.NET/GhostscriptVersionInfo.cs#L288

    This method calls the method GetInstalledVersions which can be found here : https://github.com/jhabjan/Ghostscript.NET/blob/93776b5f0c6284c27d69488227c07660b868734d/Ghostscript.NET/GhostscriptVersionInfo.cs#L153

    If you look at the method it will search inside the machine registry for some keys. I think that is the issue.

    Can you run this code from your view to see if this returns installed versions :

    List<GhostscriptVersionInfo> gsVersions =
        GhostscriptVersionInfo.GetInstalledVersions()
    

    Dave

  • DonZalmrol 220 posts 833 karma points
    Apr 24, 2017 @ 07:56
    DonZalmrol
    0

    Hi Dave,

    Thanks!

    When I add this piece of code in my view it's resulting in an error.

    But I have installed the DLL's on my live environment and on that it's working without any issues.

    enter image description here

  • DonZalmrol 220 posts 833 karma points
    Apr 22, 2017 @ 08:50
    DonZalmrol
    0

    So I've updated the gsdll32.dll and gsdll64.dll in my /bin folder to be sure it's up to date.

    Restarted the IIS pool and still the same error stating it's not installed :/

    Any ideas what I might be overlooking?

    EDIT: Also to note, I have all the needed DLL's in my /bin folder.

    But it's like the gsdll64.dll is not called correctly or can't be found for some reason.

    It's maddening :p

  • DonZalmrol 220 posts 833 karma points
    Apr 24, 2017 @ 07:58
    DonZalmrol
    0

    Update:

    Uploaded the DLL's to my live site which is a true virtual machine. And installed the Ghostscript software on it as well.

    When I do a direct call and just use the code it is working without any problems.

    The current DEV environment is a Plesk box that run IIS and SQL. So I can't install software other then just adding DLL files to the webfolder's /bin.

  • DonZalmrol 220 posts 833 karma points
    Apr 24, 2017 @ 08:09
    DonZalmrol
    0

    So now it's working on my live environment, but I see the following problem.

    In the logs I see that the DLL is throwing an exception 0X8007000B. And according different sources its stating that I need to set my IIS pool to 32B.

    When I do that, the DLL works, but my homepage stops working!

    Logs:

    System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
       at GhostscriptSharp.GhostscriptWrapper.CreateAPIInstance(IntPtr& pinstance, IntPtr caller_handle)
       at GhostscriptSharp.GhostscriptWrapper.CallAPI(String[] args)
       at GhostscriptSharp.GhostscriptWrapper.GeneratePageThumb(String inputPath, String outputPath, Int32 page, Int32 width, Int32 height)
       at MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator.Generate(String file)
     2017-04-24 00:53:56,131 [P9416/D2/T42] INFO  MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator - Completed Creating Thumbnail (took 26ms)
     2017-04-24 00:59:56,990 [P9416/D2/T16] INFO  umbraco.BusinessLogic.Log - Log scrubbed.  Removed all items older than 2017-04-23 00:59:56
     2017-04-24 02:55:08,124 [P9416/D2/T39] INFO  MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator - Started Creatning Thumbnail
     2017-04-24 02:55:08,152 [P9416/D2/T39] ERROR MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator - Faled generat pdf thumbnail
    System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
       at GhostscriptSharp.GhostscriptWrapper.CreateAPIInstance(IntPtr& pinstance, IntPtr caller_handle)
       at GhostscriptSharp.GhostscriptWrapper.CallAPI(String[] args)
       at GhostscriptSharp.GhostscriptWrapper.GeneratePageThumb(String inputPath, String outputPath, Int32 page, Int32 width, Int32 height)
       at MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator.Generate(String file)
     2017-04-24 02:55:08,152 [P9416/D2/T39] INFO  MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator - Completed Creating Thumbnail (took 27ms)
     2017-04-24 04:59:57,024 [P9416/D2/T16] INFO  umbraco.BusinessLogic.Log - Log scrubbed.  Removed all items older than 2017-04-23 04:59:56
     2017-04-24 08:08:15,220 [P9416/D2/T64] INFO  MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator - Started Creatning Thumbnail
     2017-04-24 08:08:16,110 [P9416/D2/T64] ERROR MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator - Faled generat pdf thumbnail
    System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
       at GhostscriptSharp.GhostscriptWrapper.CreateAPIInstance(IntPtr& pinstance, IntPtr caller_handle)
       at GhostscriptSharp.GhostscriptWrapper.CallAPI(String[] args)
       at GhostscriptSharp.GhostscriptWrapper.GeneratePageThumb(String inputPath, String outputPath, Int32 page, Int32 width, Int32 height)
       at MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator.Generate(String file)
     2017-04-24 08:08:16,110 [P9416/D2/T64] INFO  MissingCode.Umbraco.PdfThumbnail.ThumbnailGenerator - Completed Creating Thumbnail (took 890ms)
    

    Then when you look at the media folder it is trying to convert from PDF to JPG I see a few temp PDF files that are filling up the drive.

    enter image description here

    Which is the exact same issue that I had with Yakov , but this plugin does not fills up the drive as fast as before. With the previous plugin the grow rate was continuous and filled up the drive after like 2 days.

    https://our.umbraco.org/projects/backoffice-extensions/pdf-thumbnail/

    But we are making progress, the PDFs are all converted to JPG and it shows it nicely. But I wonder where the DLL stores the converted JPG's?

    EDIT: Temp PDFs where still being created by the pdf-thumbnail package. Had nothing to do with the DLL from Damiaan.

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 24, 2017 @ 08:18
    Damiaan
    1

    This should not be happening. The converted images are stored by imageprocessor. Maybe Ghostscript stores temporary folders. I'll look at a website where we deployed the package and see if we have the same behaviour.

    The JPG's are stored in Imageprocessor's /App_Data/Cache folder.

    Concertning the exception, you are still using the old plugin "MissingCode.Umbraco.PdfThumbnail". You don't need to call the thumbnailGenerator. Everything is handled by ImageProcessor when using our plugin.

    In fact, it's a plugin for imageprocessor, allowing imageprocessor to have PDF's as an input format.

  • DonZalmrol 220 posts 833 karma points
    Apr 24, 2017 @ 08:36
    DonZalmrol
    0

    Hi Damiaan,

    Indeed, my mistake. The old plugin was used in a different script as well. Changed it to yours and the error is gone at the moment.

    I also believe that the random PDFs that are created are from that plugin as well. As that one does the same thing as yours, but stores the converted JPG file in the original media folder.

    And when it fails creating said JPG, it tries again & again until your harddrive is full or it succeeds, it does not however clean up or remove the old random PDF's...

    With this gone, your DLL is working. Now I only see this error. Something I can ignore I believe?

     2017-04-24 10:30:21,256 [P9416/D3/T66] ERROR Umbraco.Core.UmbracoApplicationBase - An unhandled exception occurred
    Ghostscript.NET.GhostscriptAPICallException: An error occured when call to 'gsapi_new_instance' is made: -100
       at Ghostscript.NET.Interpreter.GhostscriptInterpreter.Initialize()
       at Ghostscript.NET.Viewer.GhostscriptViewer.Open(String path, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory)
       at Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open(Stream stream, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory)
       at ImageProcessor.Plugins.Pdf.PdfRasterizer.Rasterize(Stream pdfStream, Int32 pageNumber)
       at ImageProcessor.Plugins.Pdf.PdfFormat.Load(Stream stream)
       at ImageProcessor.ImageFactory.Load(Stream stream)
       at ImageProcessor.Web.HttpModules.ImageProcessingModule.<ProcessImageAsync>d__34.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar)
       at System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar)
    

    Many thanks so far!

    Laurens

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 24, 2017 @ 10:25
    Damiaan
    1

    Never had an issue like mentioning gsapi_new_instance. I just merged in a pull request and testing it right now. Give me a few hours to give feedback.

  • DonZalmrol 220 posts 833 karma points
    Apr 24, 2017 @ 10:42
    DonZalmrol
    0

    Of course, thank you!

    If it can help, this is the most recent entry of the error code.

    Ghostscript.NET.GhostscriptAPICallException: An error occured when call to 'gsapi_new_instance' is made: -100
       at Ghostscript.NET.Interpreter.GhostscriptInterpreter.Initialize()
       at Ghostscript.NET.Viewer.GhostscriptViewer.Open(String path, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory)
       at Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open(Stream stream, GhostscriptVersionInfo versionInfo, Boolean dllFromMemory)
       at ImageProcessor.Plugins.Pdf.PdfRasterizer.Rasterize(Stream pdfStream, Int32 pageNumber)
       at ImageProcessor.Plugins.Pdf.PdfFormat.Load(Stream stream)
       at ImageProcessor.ImageFactory.Load(Stream stream)
       at ImageProcessor.Web.HttpModules.ImageProcessingModule.<ProcessImageAsync>d__34.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar)
       at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    
  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 24, 2017 @ 10:42
    Damiaan
    100

    You don't need to install ghostscript anymore with the latest version (1.2.0) of the plugin - thanks to a wonderful pullrequest.

  • DonZalmrol 220 posts 833 karma points
    Apr 24, 2017 @ 10:52
    DonZalmrol
    0

    So only the DLL's are required then? I'll update the plugin :)

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 24, 2017 @ 13:12
    Damiaan
    1

    Yes indeed. You don't need to install ghostscript anymore.

  • DonZalmrol 220 posts 833 karma points
    Apr 26, 2017 @ 08:27
    DonZalmrol
    0

    Perfect, can confirm that it is working on my old dev environment that doesn't allow you to install ghostscript on the virtual server.

    Also at the moment I do not see the error reocurring about the ghostscript.net API call exception: Ghostscript.NET.GhostscriptAPICallException: An error occured when call to 'gsapinewinstance' is made: -100

    But probably because it isn't used anymore?

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 26, 2017 @ 08:30
    Damiaan
    1

    It feels more like he is now able to call it, and previously it was not.

  • DonZalmrol 220 posts 833 karma points
    Apr 26, 2017 @ 08:39
    DonZalmrol
    0

    Then I retract my previous statement :)

    Final question, will you create an Umbraco package as well, besides the nuget & github packages?

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 26, 2017 @ 08:46
    Damiaan
    1

    Good remark! I really should. :-D

    I'll see what I can do today.

  • DonZalmrol 220 posts 833 karma points
    Apr 26, 2017 @ 08:53
    DonZalmrol
    0

    I'll happely test it :)

    Then you can contain in it all pre-reqs for the plugin :)

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jul 16, 2018 @ 16:20
    bob baty-barr
    0

    have the instructions changed on this? where do i get the gsdll32.dll or gsdll64.dll???

    please advise and THANKS!

  • DonZalmrol 220 posts 833 karma points
    Jul 16, 2018 @ 20:00
    DonZalmrol
    0

    Old thread arises from the ashes ;)

    You should be able to download them from here. https://www.nuget.org/packages/GhostScriptSharp/

    And should be stored in your \bin folder.

    Goodluck!

  • David Amri 214 posts 740 karma points
    Jan 14, 2019 @ 11:47
    David Amri
    0

    Hi, I'm not able to get a preview of the specified pdf file. I have read this post regarding the issues but I'm not able to load it. What could be wrong?

    I have these in my bin folder:

    • ImageProcessor.Plugins.Pdf.dll (1.3.9)
    • ImageProcessor.dll (2.5.6)
    • gsdll32.dll (9.05)
    • gsdll64.dll (9.05)

    The code looks like this:

    <img src="@(Umbraco.TypedMedia(@media.Id).Url)?format=jpg&width=500" />
    

    The url output string looks like this:

    /media/1494/dokumenation-1.pdf?format=jpg&width=500
    
  • DonZalmrol 220 posts 833 karma points
    Jan 24, 2019 @ 11:32
    DonZalmrol
    0

    Do you get an error message? Do you see an output on your page itself?

    Also this is what I use on my personal site now.

    <ul class="thumbnails" id="image_gallery_files">
    
    @* Go over each mediaID in the list *@
    @foreach (var mediaId in mediaIds.Split(','))
    {
        var media = Umbraco.TypedMedia(mediaId);
    
        @* Media var has value *@
        if (media.Children != null && media.Children.Any())
        {
            foreach(var file in media.Children)
            {
                <li>
                    <center>
    
                        <a href="@file.Url" class="ilightbox" target="_blank">
                            <img class="span2" class="img-responsive img-blog" src="@file.Url?Format=jpg&Width=200&Height=200" alt="@String.Format("{0}",Path.GetFileNameWithoutExtension(@file.Name))"/>
                        </a>
    
                        <br />
    
                        <a href="@file.Url" download><button type="button" class="btn btn-secondary"><i class="fas fa-download"></i> Download</button></a>
                    </center>
    
                    &nbsp;
    
                </li>
    
                @* Increment the file counter*@
                fileCount++;
    
                @* Check if multiple files are present *@
                if(@fileCount > 0)
                {
                    multiple += "True";
                }
    
                else
                {
                    multiple += "False";
                }
            }
        }
    
        @* No media folder was selected *@
        else
        {
            <p>No document folder selected!</p>
        }
    }
    

    Where img class="span2" class="img-responsive img-blog" src="@file.Url?Format=jpg&Width=200&Height=200" alt="@String.Format("{0}",Path.GetFileNameWithoutExtension(@file.Name))"/> is the part that uses the PDF previewer.

Please Sign in or register to post replies

Write your reply to:

Draft