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ářů

arambpa.acosva.se

(arambpa.acosva.se, 30. 4. 2019 18:22)


Yes! Finally something about
Undeniably consider that which you stated. Your favourite reason appeared to be at the internet the easiest thing to take into accout of. I say to you, I certainly get annoyed at the same time as folks think about concerns that they plainly don't recognise about. You managed to hit the nail upon the top as smartly as outlined out the entire thing without having side effect , folks could take a signal. Will likely be back to get more. Thanks
arambpa.acosva.se

atrana.aclenig.se

(atrana.aclenig.se, 29. 4. 2019 11:34)


Article writing is also a excitement, if you be acquainted with afterward you can write if not it is complicated to write.
atrana.aclenig.se

keirh.sapne.se

(keirh.sapne.se, 28. 4. 2019 10:08)


Excellent post. I'm facing a few of these issues as well..
keirh.sapne.se

abun.telre.se

(abun.telre.se, 26. 4. 2019 22:41)


Do you have a spam problem on this site; I also am a blogger, and I was wondering your situation; many of us have created some nice practices and we are looking to swap techniques with others, please shoot me an email if interested.
abun.telre.se

театральный репертуар

(Orlandoblope, 26. 4. 2019 4:19)

Подмосковью заказанные билеты доставляются нашей курьерской службой. Иногородние клиенты могут получить билеты в кассах, в день
https://www.youtube.com/channel/UCziL091w0D7XLuQqNUiv8Sw

credhe.sapne.se

(credhe.sapne.se, 25. 4. 2019 16:40)


Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how can we communicate?
credhe.sapne.se

dust.tatef.se

(dust.tatef.se, 24. 4. 2019 14:45)


I enjoy reading through an article that can make people think. Also, many thanks for permitting me to comment!
dust.tatef.se

tranp.bestwomepri.se

(tranp.bestwomepri.se, 23. 4. 2019 6:58)


Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I get in fact enjoyed account your blog posts. Any way I'll be subscribing to your augment and even I achievement you access consistently rapidly.
tranp.bestwomepri.se

Kia Pham - Youtuber

(KiaPhamProxy, 21. 4. 2019 17:58)

Kia Pham - Youtuber
https://kiapham.com/kia-pham-youtuber.html

webgate.tn - Faucet, 10 - 50 satoshi, No timer

(Merrillzew, 19. 4. 2019 11:38)

sieu thi hoang anh

(CornellFem, 19. 4. 2019 1:23)

sieu thi hoang anh

&@$ avengersendgamefull.org

(Jamespes, 18. 4. 2019 20:07)

https://avengersendgamefullmovie.com
https://avengers2019full.com
https://123fullmovie.de/avengersendgame/

exfolierande fotkram

(exfolierande fotkram, 10. 4. 2019 8:08)


Magnificent beat ! I wish to apprentice while you amend your website, how can i subscribe for a blog site? The account helped me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear idea
exfolierande fotkram titema.se/ways-to-lose-weight/exfolierande-fotkraem.php

peau grasse brillante solution

(peau grasse brillante solution, 8. 4. 2019 2:42)


Good day! Do you know if they make any plugins to help with SEO? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good gains. If you know of any please share. Many thanks!
peau grasse brillante solution livava.se/beauty-and-health/peau-grasse-brillante-solution.php

cocktailklanning lang arm

(cocktailklanning lang arm, 5. 4. 2019 7:29)


Wow, that's what I was looking for, what a stuff! existing here at this weblog, thanks admin of this site.
cocktailklanning lang arm netcomap.se/treatment/cocktailklaenning-lng-aerm.php

planscher pa natet

(planscher pa natet, 1. 4. 2019 6:37)


Terrific work! This is the kind of info that are supposed to be shared around the internet. Disgrace on the search engines for not positioning this post upper! Come on over and discuss with my web site . Thank you =)
planscher pa natet livava.se/healthy-legs/komplett-multivitamin.php

usb шнур с тестеоом

(alexTwext, 31. 3. 2019 15:32)

usb шнур с тестеоом: https://texnoera.com/rizne/ohliad-testera-kcx-017.html

проценты онлайн займа

(Olegrella, 30. 3. 2019 14:27)

https://citycredits.com.ua/alexcredit/ - проценты онлайн займа

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í!

qrodrigob@gmail.com

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

ghostscriptsharp_reference.png ??????