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.
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.
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
'********************************************************************************
'TestPDFThumbnailGeneration
'
' 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.
Attachments
Installer and sample files
C# project
Komentáře
Přehled komentářů
I could not resist commenting. Perfectly written! boeuf bourgogne recept dehllap.se/map9.php
plantering av blommor munhea.se
(munhea.se, 5. 11. 2020 0:52)
It is not my first time to go to see this web page, i am visiting this web page dailly and get nice information from here every day. skywe.munhea.se/map8.php plantering av blommor
lanba.se surhetsgrad i kroppen
(lanba.se surhetsgrad i kroppen, 5. 11. 2020 0:23)
Definitely believe that which you stated. Your favorite justification appeared to be on the web the simplest thing to be aware of. I say to you, I definitely get annoyed while people think about worries that they just do not know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks surhetsgrad i kroppen lanba.se/map24.php
medicin för springmask aperca.se
(aperca.se, 4. 11. 2020 9:36)
Fine way of explaining, and fastidious article to take information about my presentation topic, which i am going to convey in university. huera.aperca.se/map1.php medicin för springmask
halv ГҐtta hos mig recept 2016 munhea.se
(munhea.se, 3. 11. 2020 12:19)
Pretty! This has been an extremely wonderful article. Many thanks for providing these details. atrec.munhea.se/map7.php halv ГҐtta hos mig recept 2016
aloe vera shot aperca.se
(aperca.se, 2. 11. 2020 16:15)
This paragraph is genuinely a nice one it assists new net visitors, who are wishing in favor of blogging. prosd.aperca.se/map8.php aloe vera shot
baka bröd maskin munhea.se
(munhea.se, 1. 11. 2020 23:40)
When I initially commented I seem to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I receive 4 emails with the exact same comment. Perhaps there is a way you are able to remove me from that service? Thank you! searn.munhea.se/map6.php baka bröd maskin
otertbe.se
(otertbe.se, 1. 11. 2020 3:12)
Fantastic goods from you, man. I've keep in mind your stuff previous to and you are simply too great. I really like what you have received here, really like what you are saying and the way in which during which you say it. You're making it entertaining and you still take care of to keep it smart. I can not wait to learn much more from you. This is really a great website. otertbe.se/map16.php frisör ågatan linköping
orebro e skola aperca.se
(aperca.se, 31. 10. 2020 20:30)
I loved as much as you'll receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get got an nervousness over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly very often inside case you shield this hike. reldo.aperca.se/map7.php orebro e skola
vad Г¤r hypertoni aperca.se
(aperca.se, 30. 10. 2020 2:06)
I'd like to thank you for the efforts you have put in writing this site. I'm hoping to see the same high-grade content by you later on as well. In fact, your creative writing abilities has inspired me to get my own, personal blog now ;) doodr.aperca.se/map1.php vad Г¤r hypertoni
benmmdi.se
(benmmdi.se, 30. 10. 2020 0:05)
I am not certain where you are getting your info, however great topic. I must spend some time learning much more or working out more. Thanks for magnificent info I was looking for this info for my mission. benmmdi.se/map5.php ingefära för magen
oratrg.se
(oratrg.se, 29. 10. 2020 18:55)
I have read so many articles regarding the blogger lovers except this post is in fact a good paragraph, keep it up. oratrg.se/map35.php lГҐssmed lund bankgatan
enugn.se
(enugn.se, 28. 10. 2020 14:03)
You made some good points there. I looked on the net for more info about the issue and found most individuals will go along with your views on this site. enugn.se/map17.php saab 96 1980
bra och billigt löspuder munhea.se
(munhea.se, 28. 10. 2020 9:27)
These are truly fantastic ideas in regarding blogging. You have touched some fastidious factors here. Any way keep up wrinting. tiodo.munhea.se/map5.php bra och billigt löspuder
willys trelleborg jobb aperca.se
(aperca.se, 28. 10. 2020 6:58)
I was suggested this website by means of my cousin. I'm now not positive whether or not this put up is written through him as no one else recognize such designated about my problem. You are incredible! Thanks! spare.aperca.se/map3.php willys trelleborg jobb
squgarik.se
(squgarik.se, 28. 10. 2020 4:09)
This text is invaluable. Where can I find out more? squgarik.se/map2.php kur mot förkylning
olja pГҐ apoteket munhea.se
(munhea.se, 26. 10. 2020 22:02)
Hi! This is my first visit to your blog! We are a collection of volunteers and starting a new project in a community in the same niche. Your blog provided us useful information to work on. You have done a marvellous job! gurgle.munhea.se/map13.php olja pГҐ apoteket
nike outlet sverige munhea.se
(munhea.se, 26. 10. 2020 19:22)
I have been browsing on-line greater than 3 hours lately, but I never discovered any fascinating article like yours. It's pretty price sufficient for me. In my opinion, if all site owners and bloggers made excellent content material as you did, the internet will likely be much more helpful than ever before. atrec.munhea.se/map10.php nike outlet sverige
sasilu.se
(sasilu.se, 26. 10. 2020 4:21)
Nice post. I used to be checking continuously this weblog and I am impressed! Extremely useful information specifically the closing part :) I deal with such info a lot. I used to be looking for this certain info for a long time. Thank you and good luck. sasilu.se/map10.php sluta med levaxin symptom
egluopu.se
(egluopu.se, 25. 10. 2020 8:50)
It's hard to come by experienced people about this topic, however, you seem like you know what you're talking about! Thanks egluopu.se/map1.php sarah sjöström längd
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97
dehllap.se boeuf bourgogne recept
(dehllap.se boeuf bourgogne recept, 5. 11. 2020 17:36)