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 like reading an article that can make people think. Also, many thanks for allowing for me to comment! sollb.aperca.se/map9.php Г¤ppelformad kropp diet
slem i halsen allergi munhea.se
(munhea.se, 20. 10. 2020 16:34)
Hi, Neat post. There's a problem together with your web site in internet explorer, would check this? IE still is the marketplace chief and a large part of people will omit your magnificent writing because of this problem. nistm.munhea.se/map3.php slem i halsen allergi
otertbe.se
(otertbe.se, 20. 10. 2020 7:44)
Neat blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple tweeks would really make my blog jump out. Please let me know where you got your design. Thanks otertbe.se/map29.php aspartic acid svenska
smala hГ¶ga badrumsskГҐp aperca.se
(aperca.se, 19. 10. 2020 0:23)
First off I would like to say wonderful blog! I had a quick question in which I'd like to ask if you don't mind. I was interested to find out how you center yourself and clear your mind before writing. I've had a difficult time clearing my mind in getting my ideas out. I do enjoy writing but it just seems like the first 10 to 15 minutes are lost simply just trying to figure out how to begin. Any recommendations or tips? Kudos! derse.aperca.se/map3.php smala hГ¶ga badrumsskГҐp
dry skin everywhere munhea.se
(munhea.se, 18. 10. 2020 23:37)
Appreciate the recommendation. Let me try it out. tuta.munhea.se/map4.php dry skin everywhere
persdap.se
(persdap.se, 18. 10. 2020 6:05)
I'm truly enjoying the design and layout of your blog. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Fantastic work! persdap.se/map14.php eget smГ¶r recept
godis grossist sverige munhea.se
(munhea.se, 17. 10. 2020 6:36)
Hi there! Would you mind if I share your blog with my zynga group? There's a lot of folks that I think would really enjoy your content. Please let me know. Cheers riedu.munhea.se/map7.php godis grossist sverige
parfym gift set billigt aperca.se
(aperca.se, 17. 10. 2020 5:45)
My spouse and I stumbled over here by a different page and thought I might as well check things out. I like what I see so now i'm following you. Look forward to going over your web page again. inun.aperca.se/map4.php parfym gift set billigt
oratrg.se
(oratrg.se, 16. 10. 2020 3:54)
What's up, this weekend is nice designed for me, as this occasion i am reading this impressive informative article here at my house. oratrg.se/map29.php tova helgesson flashback
cross fit Гёvelser munhea.se
(munhea.se, 15. 10. 2020 13:38)
I couldn't resist commenting. Exceptionally well written! loqua.munhea.se/map4.php cross fit Гёvelser
vad Г¤r giftigt fГ¶r katter aperca.se
(aperca.se, 15. 10. 2020 11:56)
Very good post! We are linking to this great post on our website. Keep up the great writing. suspi.aperca.se/map3.php vad Г¤r giftigt fГ¶r katter
sasilu.se
(sasilu.se, 14. 10. 2020 0:58)
Amazing! Its actually remarkable article, I have got much clear idea regarding from this piece of writing. sasilu.se/map21.php painful hard skin on feet
te veel gember schadelijk aperca.se
(aperca.se, 13. 10. 2020 12:36)
I don't even know the way I ended up right here, however I believed this post was once good. I do not recognize who you're but certainly you're going to a famous blogger in the event you are not already. Cheers! desvi.aperca.se/map3.php te veel gember schadelijk
egluopu.se
(egluopu.se, 13. 10. 2020 10:23)
Hello, yeah this article is actually nice and I have learned lot of things from it concerning blogging. thanks. egluopu.se/map38.php willys gГ¶teborg erbjudanden
yasuragi kids rabatt munhea.se
(munhea.se, 13. 10. 2020 5:36)
I enjoy what you guys tend to be up too. This sort of clever work and exposure! Keep up the excellent works guys I've incorporated you guys to our blogroll. reipo.munhea.se/map10.php yasuragi kids rabatt
tumphati.se
(tumphati.se, 12. 10. 2020 1:44)
excellent issues altogether, you just received a brand new reader. What would you suggest about your publish that you just made some days ago? Any positive? tumphati.se/map18.php the body shop borlänge
enugn.se
(enugn.se, 11. 10. 2020 9:52)
Great post. I was checking constantly this blog and I'm impressed! Extremely useful info particularly the last part :) I care for such info a lot. I was looking for this particular info for a very long time. Thank you and good luck. enugn.se/map6.php the body shop kalmar
gb krossad choklad munhea.se
(munhea.se, 11. 10. 2020 7:07)
The other day, while I was at work, my sister stole my iphone and tested to see if it can survive a 40 foot drop, just so she can be a youtube sensation. My iPad is now broken and she has 83 views. I know this is entirely off topic but I had to share it with someone! gurgle.munhea.se/map4.php gb krossad choklad
oreiep.se
(oreiep.se, 10. 10. 2020 23:30)
This is very interesting, You're a very skilled blogger. I have joined your rss feed and look forward to seeking more of your magnificent post. Also, I have shared your web site in my social networks! oreiep.se/map31.php blåmärken på benen utan orsak
weleda night cream review naoblal.se
(naoblal.se, 10. 10. 2020 9:33)
Oh my goodness! Amazing article dude! Thanks, However I am having issues with your RSS. I don't understand why I cannot subscribe to it. Is there anybody having identical RSS issues? Anyone who knows the solution will you kindly respond? Thanx!! galsio.naoblal.se/travels/weleda-night-cream-review.php weleda night cream review
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
Г¤ppelformad kropp diet aperca.se
(aperca.se, 20. 10. 2020 22:06)