Jdi na obsah Jdi na menu

PDF thumbnails from VBA

I was asked to develop a form where user can see a pdf thumbnail of a pdf file. It was pretty far from what I have been developing so I decided to use "uncle" google to find a solution. There are some solutions but nothing what was expecting. You can use paid version of Adobe or free Adobe Acrobat ActiveX (Acropdf1) or some others free tools that can work along a pdf file. I tested only the free version of Acrobat ActiveX component and it was really nightmare. Then I found a C# project using the GhostScript tool for creating a pdf thumbnail. Unfortunatelly VBA cannot work with this project directly. Read more to find solution.

As I mentioned you can use the Acropdf1 activeX which is automatically installed with the Adobe Reader application.

Acropdf1.PNG, 35kB

How to add the Acropdf1 activeX on a VBA form

At the first time the activeX seemed to be a good solution but then I found two "bugs". The first one is more important than the second one. The activeX takes focus and never give it back and if you press the "TAB" key, then the whole application will crash. It's very known bug but Adobe cannot fix it for some reason. And the second bug rather behavior - of the activeX control is uncomfortable - it always takes focus and never give it back and also you don't have option to find out if a pdf document is fully loaded or not. My client was complaining about that for many times so I decided to find another solution.

I found code from Matthew Ephraim. where he uses a free tool Ghostscrip and .NETFramework 3.5 and C#. Form Visual Studio you can use his tool without any problems just include it into your project. Unfortunately we cannot use his dll directly from VBA. That was the reason why I took his code and made a little adjustment to expose methods from his project to the COM object.
Now - after registration the dll to your system - you can reference the dll as usually and use it !!! And it works great.

GhostScriptSharp_reference.PNG, 17kB

Who is interested how to create a C# dll that can work with VBA I attached the zip file with entire C# solution. Look at the Attachment section.
And who just want to use it as soon as possible, download the installer and install it. I also prepare a sample and you can find everything in the Attachment section.
The installer just check if your system contains the .NETFramework 4 and if not, it will suggest to download it and then register the dlls into your system.

Your code can look like this one
and then you can take the output file as an ordinary image file and load it - for example - to an image control.

Option Explicit
' Purpose:  It uses reference to GhostscriptWrapper library.
'           From a pdf file creates a jpg file that represents a thumbnail of the pdf.
'           You can set page number and DPI quality.
' Inputs:   -none-
' Outputs:  -none-
' Created:  02/10/2011  Premysl Lazecky
' Modified: .
Sub TestPDFThumbnailGeneration()

    Dim PDF             As GhostscriptWrapper
    Dim strPath         As String
    Dim strInputFile    As String
    strInputFile = "Test.pdf"
    strPath = ActiveWorkbook.Path
    If Right$(strPath, 1) <> Application.PathSeparator Then
       strPath = strPath & Application.PathSeparator
    End If
    Set PDF = New GhostscriptWrapper
    PDF.GeneratePDFThumb inputPath:=strPath & strInputFile, _
                         outputPath:=strPath & "Output.jpg", _
                         Page:=1, _
                         Width:=72, Height:=72
    Set PDF = Nothing
End Sub

 As the result of this code you will get a jpg file called Output.jpg  with thumbnail of defined page in the pdf file - in this case page 1 - with defined resolution.


Installer and sample files
C# project




Přidat komentář

Přehled komentářů

XRumer 16.0 + XEvil 4.0 breaking of captchas Google, Facebook, Captcha.Com, SolveMedia, Bing

(Sharondop, 12. 3. 2019 6:04)

Absolutně nová aktualizace balíčku SEO / SMM "XRumer 16.0 + XEvil 4.0":
captcha řešení Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
a více než 8400 dalších kategorií captcha,
s nejvyšší přesností (80 až 100%) a nejvyšší rychlostí (100 img za sekundu).
Můžete připojit XEvil 4.0 k nejoblíbenějšímu softwaru SEO / SMM: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke a více než 100 dalších softwarů.

Zájem? Existuje spousta nepřehledných videí o XEvile na YouTube.
Hodně štěstí!


(Rodrigo, 6. 3. 2019 19:05)

ghostscriptsharp_reference.png ??????

isadora gel nail lacquer hur gor man

(isadora gel nail lacquer hur gor man, 5. 3. 2019 13:44)

Hey! I know this is kinda off topic however I'd figured I'd ask. Would you be interested in exchanging links or maybe guest writing a blog article or vice-versa? My blog discusses a lot of the same topics as yours and I think we could greatly benefit from each other. If you're interested feel free to shoot me an email. I look forward to hearing from you! Terrific blog by the way!
isadora gel nail lacquer hur gor man baokep.se/dermatology/isadora-gel-nail-lacquer-hur-goer-man.php

hem till hem alingsas

(hem till hem alingsas, 26. 2. 2019 7:12)

Great website you have here but I was wanting to know if you knew of any discussion boards that cover the same topics discussed in this article? I'd really like to be a part of online community where I can get suggestions from other experienced individuals that share the same interest. If you have any recommendations, please let me know. Appreciate it!
hem till hem alingsas livava.se/ways-to-lose-weight/green-coffee-800.php

tikei finishing veil matte

(tikei finishing veil matte, 21. 2. 2019 17:37)

Thanks for sharing your thoughts on. Regards
tikei finishing veil matte neutin.se/beauty-and-health/enkla-matmuffins-recept.php

association pour les droits de la femme

(association pour les droits de la femme, 14. 2. 2019 9:17)

Thank you a bunch for sharing this with all folks you really know what you're speaking approximately! Bookmarked. Kindly also visit my web site =). We may have a link change agreement among us
association pour les droits de la femme lessred.se/veins-on-the-legs/association-pour-les-droits-de-la-femme.php


(RogerNix, 6. 2. 2019 17:57)

Godlike date
I unseat to your r‚clame excellent sites
Video delightful


(KattyGluk, 3. 2. 2019 13:39)

snygg inredning vardagsrum

(snygg inredning vardagsrum, 25. 1. 2019 9:23)

you're in point of fact a excellent webmaster. The site loading pace is incredible. It seems that you are doing any distinctive trick. Moreover, The contents are masterpiece. you have performed a fantastic job on this topic!
snygg inredning vardagsrum titema.se/dermatology/slitet-hr-inpackning.php


(NickP_Lob, 20. 12. 2018 10:34)

Our conversations with other storytellers have led to an invocation of ultra-dynamic consciousness. We are at a crossroads of self-actualization and materialism. Who are we? Where on the great quest will we be awakened?

Best Way To Get FREE Cryptocurrency Coins

(Cholladal, 26. 10. 2018 19:59)


I want to be a part of Cryptocurrency but me and my friends dont have any money to buy some Cryptocurrency.
So I went looking how we could get some Free Crypto.
We have found 4 ways to do it !

How to get FREE Cryptocurrency !

1. Claim Faucets every day
2. Play Games and EARN FREE Bitcoins
3. Watch advertisements and earn FREE Bitcoins
4. EARN FREE Tokens From Airdrops

Click here and take a look:https://www.faucetcryptocurrency.net

Want to earn Cryptocurrency with your Mobile Phone? (Electroneum)

Good luck and have fun collecting FREE Cryptocurrency


frysta roda vinbar

(nseo-sw.men, 24. 10. 2018 2:46)

What a material of un-ambiguity and preserveness of valuable experience on the topic of unexpected emotions.
frysta roda vinbar nseo-sw.men/diets/32800-frysta-roeda-vinbaer.html


(XEvilBestTag, 1. 10. 2018 17:11)

Yep, f*kin sp*am. Yes, yes, yes, AGAIN. And - yes, IT F*KIN WORKS BECAUSE YOU READ IT! :)
Because XEvil 4.0 WAS RELEASED! It's bypass ANY captcha included ReCaptcha-2 and ReCaptcha-3.
Neeed more info (just to...maybe kill this Evil? ;))

Just Google or YouTube for it.
You'll be impressed.

Peace to you, bro! :)

Test, just a test

(masshal, 18. 9. 2018 10:38)

Hello. And Bye.

Test, just a test

(feran, 8. 9. 2018 12:03)

Hello. And Bye.

Test, just a test

(vennnile, 8. 9. 2018 11:14)

Hello. And Bye.

Test, just a test

(etiol, 8. 9. 2018 11:11)

Hello. And Bye.

Test, just a test

(xaipheira, 5. 9. 2018 16:22)

Hello. And Bye.

Test, just a test

(cynengefl, 1. 9. 2018 8:23)

Hello. And Bye.

Test, just a test

(MariDup, 17. 8. 2018 17:08)

Hello. And Bye.