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

娛樂城

(Virgilmak, 17. 8. 2022 20:57)


娛樂城

수입 + 투자 포함 + 출금 포함

(DanielSor, 16. 8. 2022 11:00)

https://www.cieleau.co.kr/bbs/board.php?bo_table=free&wr_id=15858

I can suggest to visit to you a site on which there are many articles on a theme interesting you.

(Tommykar, 14. 8. 2022 16:42)

Bravo, this rather good idea is necessary just by the way
https://zeenite.com/videos/6119/big-ass-girl-fucked-in-the-kitchen-by-big-cock/
https://gay0day.com/videos/183694/the-icemen-cumming/

cabana

(RichardBix, 14. 8. 2022 13:55)


cabana-de-inchiriat.ro este o platforma de listare a cabanelor, gratuita si fara comisioane. Rezervarea este facuta direct cu propietarul, fara intermediari! Cazare la munte, la mare, toata romania.

casino siteleri

(casino siteleri, 12. 8. 2022 13:20)

casino siteleri

타오바오구매대행

(DavidNob, 12. 8. 2022 10:57)


타오바오구매대행

How Binary Options Travail

(BruceMic, 12. 8. 2022 2:53)

Binary options subcontract out traders profit from price fluctuations in multiple global markets, but it's foremost to covenant the risks and rewards of these contentious and often-misunderstood financial instruments. Binary options substantiate little resemblance to traditional options, featuring out of the ordinary payouts, fees, and risks, as showily as a unrivalled liquidity edifice and investment process https://corretoras-opcoes-binarias.com/

타오바오구매대행

(DavidNob, 11. 8. 2022 17:27)


타오바오구매대행

They Live film retelling

(Thomasguany, 11. 8. 2022 15:23)

https://t.me/s/bestmoviesyt

타오바오구매대행

(DavidNob, 11. 8. 2022 8:05)


타오바오구매대행

Gestão de Ferramentaria

(AnthonyNig, 11. 8. 2022 4:14)


Sistema que padroniza processos, controla o ferramental, monitora a sua qualidade e otimiza seu tempo de utilização, atribuindo responsabilidades aos usuários e informando aos gestores sobre toda a operação em tempo real.

I like this phrase :)

(Tommykar, 10. 8. 2022 23:09)

In my opinion, it is an interesting question, I will take part in discussion.
https://amateur-interracial.com
https://scattube.info

The best futures

(Patrikhok, 10. 8. 2022 16:38)

https://samaraonline24.ru/narodnyje-primjety-o-pogodje
You didn't even know about these things.

little girls cp

(DenisCef, 9. 8. 2022 11:27)

ARTBBS PTCH PTSC

little girls cp

ddx.cz/Fa

수입 + 투자 포함 + 출금 포함

(DanielSor, 6. 8. 2022 17:22)

https://www.htns.com/lvlm/bbs/board.php?bo_table=free&wr_id=28859

Купить Мефедрон в Москве? Телеграмм - @FV_24 Купить Мефедрон. Телеграмм - @FV_24

(Timothyehed, 6. 8. 2022 15:59)

Купить Мефедрон в Москве? Телеграмм - @FV_24 Купить Мефедрон. Телеграмм - @FV_24


ССЫЛКА В ТЕЛЕГРАММ - https://t.me/FV_24

ССЫЛКА В ДЛЯ ВХОДА - https://t.me/FV_24

ССЫЛКА ДЛЯ ЗАКАЗА - https://t.me/FV_24

ССЫЛКА В ДЛЯ СВЯЗИ - https://t.me/FV_24

ССЫЛКА В НАШ КАНАЛ - https://t.me/FV_24

!!!МЕФЕДРОН МОСКВА!!!
Купить Мефедрон в Москве,
Сколько стоит Мефедрон в Москве,
Как купить Мефедрон в Москве,
Где купить Мефедрон в Москве,
Купить Мефедрон в Москве,
Сколько стоит КУРЕВО Мефедрон в Москве,
Купить КУРЕВО Мефедрон в Москве,
Цена на КУРЕВО Мефедрон в Москве,
Купить героин в Москве,
Купить экстази в Москве,
Купить шишки в Москве,
Купить гашиш в Москве,
Купить мефедрон в Москве,
Купить экстази в Москве,
Купить МДМА в Москве,
Купить лсд в Москве,
Купить фен в Москве,
Купить скорость альфа в Москве,
Купить гидропонику в Москве,
Купить метамфетамин в Москве,
Купить эйфоретики в Москве,
Купить закладки в Москве,
Купить Мефедрон закладкой в Москве
!!!МЕФЕДРОН МОСКВА!!!

https://go88.tips/

(DonaldWep, 5. 8. 2022 10:13)

https://go88.tips/

Check, at best a test

(Jamesfueno, 4. 8. 2022 11:44)

Hello. And Bye.
https://cdgamebuy.ru/

My book is free!!

(Rodneysag, 3. 8. 2022 11:38)

My book is free from Thursday, August 4, 2022, 12:00 AM , please download and review if possible. I will be very grateful to you.
Easy Recipes for Kids: 50+ Super Simple and Quick Recipe Book
https://www.amazon.com/dp/B08PSCMND4

수입 + 투자 포함 + 출금 포함

(DanielSor, 2. 8. 2022 21:38)

https://walltent.co.kr/bbs/board.php?bo_table=free&wr_id=135


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

následující »