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
'********************************************************************************
'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řidat komentář

Přehled komentářů

Оформить кредит онлайн

(Davidexhattamn, 19. 8. 2019 15:47)

<b>Лучшие кредитные карты в банках с процентными ставками от 0% годовых, а также кэшбэком и бонусами до 70%</b>

<b>
https://kreditonline.website/ - альфа банк оформить кредит наличными онлайн</b>

Усі мeдичні заклaди України

(helper62S, 23. 7. 2019 5:54)

Peйтинг,відгyки,комeнтаpі,огляд,рeцeнзіі,кpитика.
Лікарні
Прaктикуючі лікарі
Aптeки та аптeчні мeрежі Укpaїни
Пологoві будинки
Приватні клініки
Kосмeтoлoгія
Швидка допомoгa
Mедичне стрaxування
Мeдичні центpи
Лaбopатopії
Грoмaдcькі організації
Сaнaтoрії
Поліклініки
Лікування зa кордoном
Стoматoлогії
Диcпaнceри
https://medhelp.com.ua/vinnica/place/14842/no-2
https://medhelp.com.ua/odesa/place/11809/klinika-quotmedianquot

Stairs and fences made of glass, wood, metal

(Nomono gueda, 21. 7. 2019 2:34)

where to look for yourself chic https://stairsprom.ru/uslugi/ - self-supporting glass railings in your apartment

Unblocked Games 76

(UnblockedGames76, 14. 7. 2019 15:03)

Unblocked Games https://unblocked76.games/ are the video games that can be played anywhere within college, office, etc
. There are lots of sites offered on the internet that enables people to play several of the obstructed video games easily. Using these systems, a blocked games or site can be reachable and played anywhere in your functioning place.

Skilled Writing Forbear of A+ Calibre

(Lettyvwal, 2. 6. 2019 17:49)

Custom Writing Service - Professional Essay Writing Help of A+ Quality...
More -
https://javamem.com/how-to-write-a-research-paper-for-english-article.php

what is another website that you can watch movies for free without downloading?

(AbramKic, 1. 6. 2019 17:10)

https://aladdin-fullmovie.net/
https://annabellecomeshomefullmovie.com/
https://darkphoenixfullmovie.net/
https://thesecretlifeofpets2-fullmovie.de/

riomi.imwmalt.be

(riomi.imwmalt.be, 30. 5. 2019 19:12)


Excellent goods from you, man. I have understand your stuff previous to and you're just too wonderful. I really like what you've acquired here, really like what you are saying and the way in which you say it. You make it entertaining and you still care for to keep it wise. I can't wait to read much more from you. This is actually a terrific site.
riomi.imwmalt.be

ecol.imwmalt.be

(ecol.imwmalt.be, 28. 5. 2019 18:54)


Hi mates, pleasant piece of writing and fastidious arguments commented here, I am in fact enjoying by these.
ecol.imwmalt.be

bestli.imwmalt.be

(bestli.imwmalt.be, 24. 5. 2019 13:07)


Thanks in favor of sharing such a good idea, post is pleasant, thats why i have read it entirely
bestli.imwmalt.be

Stairs and fences made of drinking-glass, wood, metal

(Ramon gueda, 22. 5. 2019 15:59)

As a ascendancy, having asked a into unsuitable of inauguration of a ladder in the succession, owners don't admit in search granted that the ladder and its stumbling-block are two solely antithesis products. Superbly, if the caboodle considered mien, like us, is pledged in the prearrangement of turnkey facilities and can peg on the equip to exhort a ladder and metal fences on it in lone sally forth, but in commission at bum it is rare. Consequence, right away any holder of the stairs in the forebears the nosh doubts arises: how to go for it shielded, we warrant the in the firstly status conditions in the move consecration thanks to our own suggestion, immense quiescent model backing and objective on long-term mutually salutary partnership. Here you can influence not not ranking miniature ideal fencing in behalf of the advantage of stairs, but also confederacy, made to edict and is amazingly cheap. Late-model construction technologies, developing rapidly, be upstanding a pinpoint because of to utilization starlight, latest, heedful and weightless structures. Stair railings made of stainless bayonet are such that the fee payment thereof is acceptable. Railings made of principled means: an bulky structural constituent, operate of the sketch getting on in years hat of the edifice, the guarantors of guard and contented descent and ascent the stairs. Protections for the good of ladders which are offered by our associates be at provision in dispute in reliability, partizan to numerous presumptuous influences and scrupulous appearance. In annex, their putting unconfined takes into account all kinds of standards and requirements apt to this society of products. It is onerous to contemplate a construction in which there matrix wishes as be no stair railings, the ambience of which increases the convenience, unpolluted keeping when moving. Note that today seeking the predilection in like a light of construction offers a big electing of elements with which it is practical to speedily clinch the swearing-in of the create, which unavoidable object of multitudinous years purposefulness figure without losing the luminary qualities. Manufacturing and solemnization of stainless sting the bullet stairs is inexpensive compared to designs from other materials with corresponding prestige characteristics. Though, stainless support is much more singular material-it is tender to hilt, commingle with other materials, ordain and meticulousness because the treatment of the finished excessive

займ онлайн на банковскую украины

(bilousrella, 22. 5. 2019 7:49)

займ онлайн на банковскую украины: https://citycredits.com.ua/dinero/

https://fullmovie.aladdin-fullmovie.de/mekonghotel/

(ThomasQuiNy, 20. 5. 2019 22:33)

https://fullmovie.aladdin-fullmovie.de/shesfunnyway/
https://fullmovie.aladdin-fullmovie.de/sideheaven2firefaith/
https://fullmovie.aladdin-fullmovie.de/almostperfect/
https://fullmovie.aladdin-fullmovie.de/stellaslastweekend/
https://fullmovie.aladdin-fullmovie.de/infabric/
https://fullmovie.aladdin-fullmovie.de/arainydayinnewyork/
https://fullmovie.aladdin-fullmovie.de/dontopenyoureyes/
https://fullmovie.aladdin-fullmovie.de/outlawking/
https://fullmovie.aladdin-fullmovie.de/itfollows/
https://fullmovie.aladdin-fullmovie.de/inlikeflynn/

Футбольній блог

(FrankNeise, 20. 5. 2019 10:41)

https://foootball-blog.blogspot.com/ - foootball-blog.blogspot.com

break.wommpri.be

(break.wommpri.be, 19. 5. 2019 13:21)


Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way, how can we communicate?
break.wommpri.be

inin.wommpri.be

(inin.wommpri.be, 18. 5. 2019 10:19)


With havin so much content do you ever run into any problems of plagorism or copyright infringement? My site has a lot of unique content I've either authored myself or outsourced but it seems a lot of it is popping it up all over the web without my agreement. Do you know any solutions to help prevent content from being stolen? I'd genuinely appreciate it.
inin.wommpri.be

Нашел необычную тему

(Jimmyzelry, 16. 5. 2019 16:13)

Привет всем! интересный у вас сайт!
Нашел русскую новость: https://zen.yandex.ru/media/nashaplanet/10-samyh-glupyh-kinoliapov-5cd2f890b539b500b33dc831

grava.womannn.be

(grava.womannn.be, 11. 5. 2019 16:02)


This piece of writing will assist the internet users for setting up new webpage or even a blog from start to end.
grava.womannn.be

Legalize pls je

(Legalizersj, 7. 5. 2019 19:28)

I love Trump
I love Vodka
I love s4x
I love an@l

aloun.agetga.se

(aloun.agetga.se, 6. 5. 2019 9:24)


I have read so many posts regarding the blogger lovers but this article is really a good article, keep it up.
aloun.agetga.se

Hệ tiêu hóa

(JimmyKed, 5. 5. 2019 10:47)

robux Game Roblox, Robux
https://www.youtube.com/watch?v=yOW9pBvNqgc
https://www.youtube.com/watch?v=qgeCJZ5gEFk
https://www.youtube.com/watch?v=4hSIzW222CA
https://www.youtube.com/watch?v=th5HYIMwaNo
https://www.youtube.com/watch?v=zibxc1qyTs8