Display thumbnails of pdfs
Display thumbnails of pdfs
Is it possible to display thumbnails showing a preview of pdfs like what we can see at Windows Explorer?
That's the starting point my hope is to be able to mimic exactly Windows Explorer capability of showing preview thumbnails of all type of files.
TIA
That's the starting point my hope is to be able to mimic exactly Windows Explorer capability of showing preview thumbnails of all type of files.
TIA
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
BCC5.82/BCC7.3
xHarbour/Harbour
- Antonio Linares
- Site Admin
- Posts: 42393
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 9 times
- Been thanked: 41 times
- Contact:
Re: Display thumbnails of pdfs
Dear Hua,
This is a first prototype based on a Karina example:
This is a first prototype based on a Karina example:
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
local oWndPdf, oPdf
DEFINE WINDOW oWndPdf TITLE "Generating thumbnail"
oPdf := TActiveX():New( oWndPdf, "AcroPDF.PDF.1" )
oWndPdf:oClient := oPdf
oPdf:Do( "LoadFile", "fwintro.pdf" )
ACTIVATE WINDOW oWndPdf MAXIMIZED ;
ON INIT( oWndPdf:SetSize( 200, 300 ), oWndPdf:Center(), PDFActivex(),;
SysWait( 1 ), oWndPdf:oClient:SaveToBmp( "thumbnail.bmp" ), oWndPdf:End() ) ;
VALID ( oPdf:End(), .T. )
return nil
function PDFActivex()
local MyProgID
if IsActivex( "PDF.PdfCtrl.1" ); MyProgID := "PDF.PdfCtrl.1"; endif
if IsActivex( "PDF.PdfCtrl.2" ); MyProgID := "PDF.PdfCtrl.2"; endif
if IsActivex( "PDF.PdfCtrl.3" ); MyProgID := "PDF.PdfCtrl.3"; endif
if IsActivex( "PDF.PdfCtrl.4" ); MyProgID := "PDF.PdfCtrl.4"; endif
if IsActivex( "PDF.PdfCtrl.5" ); MyProgID := "PDF.PdfCtrl.5"; endif
if IsActivex( "PDF.PdfCtrl.6" ); MyProgID := "PDF.PdfCtrl.6"; endif
if IsActivex( "PDF.PdfCtrl.7" ); MyProgID := "PDF.PdfCtrl.7"; endif
if IsActivex( "acroPDF.PDF.1" ); MyProgID := "acroPDF.PDF.1"; endif
if IsActivex( "acroPDF.PDF.2" ); MyProgID := "acroPDF.PDF.2"; endif
return MyProgID
Re: Display thumbnails of pdfs
hi,
as i know PDF Thumbnail are "process" by external App like Adobe Acrobat, Foxit Reader or SumatraPDF to show in Explorer
all have a Option at Install to "enable" Thumbmails show in Explorer
! Note : SumatraPDF Portable Version does NOT hat a Option
---
i use MuPDF which is the Library for SumatraPDF
https://github.com/ArtifexSoftware/mupdf
you can download MuPDF here
https://mupdf.com/releases/index.html (mupdf-1.20.0-windows.zip)
it include mupdf.exe, mupdf-gl.exe and mutool.exe
make a *.BAT File and include this Line
it will generate Thumbnail "Filename.PNG" with 96 DPI and 150 Pixel Height
1-1 mean only Page 1
1-N are Tbumbs from 1 until End
as i know PDF Thumbnail are "process" by external App like Adobe Acrobat, Foxit Reader or SumatraPDF to show in Explorer
all have a Option at Install to "enable" Thumbmails show in Explorer
! Note : SumatraPDF Portable Version does NOT hat a Option
---
i use MuPDF which is the Library for SumatraPDF
https://github.com/ArtifexSoftware/mupdf
you can download MuPDF here
https://mupdf.com/releases/index.html (mupdf-1.20.0-windows.zip)
it include mupdf.exe, mupdf-gl.exe and mutool.exe
make a *.BAT File and include this Line
Code: Select all | Expand
mutool draw -o "%1.png" -r 96 -h 150 "%1" 1-1
it will generate Thumbnail "Filename.PNG" with 96 DPI and 150 Pixel Height
1-1 mean only Page 1
1-N are Tbumbs from 1 until End
greeting,
Jimmy
Jimmy
- nageswaragunupudi
- Posts: 10701
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 3 times
- Contact:
Re: Display thumbnails of pdfs
That's the starting point my hope is to be able to mimic exactly Windows Explorer capability of showing preview thumbnails of all type of files.
I understand what he is looking for is this.
While on the left side, files are browsed (filename, size, date, etc, like Windows Explorer) on the right side pane, he likes to see the "preview of the file", same way as we see in Windows Explorer. The files can be of all types, not only pdf. They can be pdf, docx, xlsx, ppts, txt, prg, any image file or any file type.
In other words, we need to make an application with the same functionality and look of Windows Explorer.
We will try and hope to provide it.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Otto
- Posts: 6396
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 8 times
- Been thanked: 1 time
- Contact:
Re: Display thumbnails of pdfs
Hello Hua,
I use this workaround:
Best regards,
Otto
I use this workaround:
Best regards,
Otto
Code: Select all | Expand
function PdfToJpeg( cPDF )
local cExe := "c:\Tracker Software\PDF Viewer\PDFXCview.exe"
local cTitle := cFileNoExt( LFN2SFN( cPDF ) ) //+ " - PDF-XChange Viewer"
local cCmd
local hWnd, hBmp, hBmp2, hDib, cBuf, nWait := 2
local lRet := .f.
if File( cExe ) .and. File( cPDF )
cCmd := cExe + ' /A "fullscreen=yes"' + ' ' + LFN2SFN( cPDF )
//cCmd := cExe + ' /A "Zoom=150"' + ' ' + cPDF
WinExec( cCmd )
SysWait( 3 )
do while nWait < 12 .and. Empty( hWnd := FindWnd( cTitle ) )
SysWait( nWait )
nWait += 1
enddo
if ! Empty( hWnd )
SetFocus( hWnd )
SetForeGroundWindow( hWnd )
SysRefresh()
SysWait( 0.1 )
hBmp := WndBitmap( hWnd )
SendMessage( hWnd, WM_CLOSE )
hBmp2 := BmpTrim( hBmp )
DeleteObject( hBmp )
hDib := DibFromBitmap( hBmp2 )
cBuf := DibToStr( hDib )
GlobalFree( hDib )
DeleteObject( hBmp2 )
lRet := BmpBufToJpg( cFileSetExt( cPDF, "jpg" ), cBuf )
cBuf := nil
endif
endif
return lRet
//----------------------------------------------------------------------------//
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- nageswaragunupudi
- Posts: 10701
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 3 times
- Contact:
Re: Display thumbnails of pdfs
Work in Progress
First sample.
Provides previews for
DOCX,XLSX,PPTX,HTML as well as image files, text files and video files.
In the next sample, we will add most other file types.
This is just the beginning:
First sample.
Provides previews for
DOCX,XLSX,PPTX,HTML as well as image files, text files and video files.
In the next sample, we will add most other file types.
This is just the beginning:
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: Display thumbnails of pdfs
hi,
as i understand Hua want Thumbnails, not "open" any File for Preview.
so how to make Thumbnail from pdf, docx, xlsx, ppts
---
next Question would be : how to display Thumbnail "like Explorer"
Explorer use Listview and Imagelist and have "Extra large Icon" (SHIL_JUMBO)
Fivewin have 2 Sample
but CLASS Imagelist() from Fivewin is IHMO limited to
so we need to enhance CLASS Imageview()
p.s. i wonder that FiveWin have only 2 Listview Sample and no LVS_REPORT Style
hua wrote:showing preview thumbnails of all type of files.
as i understand Hua want Thumbnails, not "open" any File for Preview.
so how to make Thumbnail from pdf, docx, xlsx, ppts
---
next Question would be : how to display Thumbnail "like Explorer"
Explorer use Listview and Imagelist and have "Extra large Icon" (SHIL_JUMBO)
Fivewin have 2 Sample
c:\fwh\samples\xblstgrd.prg
c:\fwh\samples\listvie.prg
but CLASS Imagelist() from Fivewin is IHMO limited to
Code: Select all | Expand
#define SHIL_LARGE 0 // normally 32x32
#define SHIL_SMALL 1 // normally 16x16
so we need to enhance CLASS Imageview()
Code: Select all | Expand
#define SHIL_EXTRALARGE 2
#define SHIL_SYSSMALL 3 // like SHIL_SMALL, but tracks system small icon metric correctly
#if (NTDDI_VERSION >= NTDDI_VISTA)
#define SHIL_JUMBO 4 // normally 256x256
p.s. i wonder that FiveWin have only 2 Listview Sample and no LVS_REPORT Style
greeting,
Jimmy
Jimmy
- Antonio Linares
- Site Admin
- Posts: 42393
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 9 times
- Been thanked: 41 times
- Contact:
Re: Display thumbnails of pdfs
Dear Jimmy,
Please search for LISTVIEW in FWH\samples folder and you will find six results
I guess you could use:
SetWindowLong( oList:hWnd, -16, nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP, LVS_REPORT ) )
used in samples\listvie.prg
Please search for LISTVIEW in FWH\samples folder and you will find six results
I guess you could use:
SetWindowLong( oList:hWnd, -16, nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP, LVS_REPORT ) )
used in samples\listvie.prg
Re: Display thumbnails of pdfs
hi Antonio,
HB_FUNC() in c:\fwh\source\winapi\listview.c is special for Listview_Group
it have LVITEM and LVGROUP Structure but not LVCOLUMN which is need for LVS_REPORT Style
i have this in my "native" Xbase++ Listview
---
i´m not a "C" Programmer so i have Problem to rebuild OT4XB Wrapper to FiveWin
please also look at my Problem with BCC 7 and INCLUDE Files
Antonio Linares wrote:SetWindowLong( oList:hWnd, -16, nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP, LVS_REPORT ) )
HB_FUNC() in c:\fwh\source\winapi\listview.c is special for Listview_Group
it have LVITEM and LVGROUP Structure but not LVCOLUMN which is need for LVS_REPORT Style
i have this in my "native" Xbase++ Listview
Code: Select all | Expand
::oLVCol := LVCOLUMN():New()
::oLVCol:mask := nOr( LVCF_FMT, LVCF_WIDTH , LVCF_TEXT , LVCF_SUBITEM )
::oLVCol:fmt := nOr( LVCFMT_LEFT )
::nColMax := Len(::aTitle)
for nCol := 1 to ::nColMax
::oLVCol:cx := ::aColWide[nCol]
::oLVCol:cText := ::aTitle[nCol]
::lv_InsertColumn(nCol-1,::oLVCol) // LVM_INSERTCOLUMN
next
---
i´m not a "C" Programmer so i have Problem to rebuild OT4XB Wrapper to FiveWin
please also look at my Problem with BCC 7 and INCLUDE Files
greeting,
Jimmy
Jimmy
- Antonio Linares
- Site Admin
- Posts: 42393
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 9 times
- Been thanked: 41 times
- Contact:
Re: Display thumbnails of pdfs
Dear Jimmy,
This is the definition of the struct LVCOLUMN from commctrl.h
Please try this example where Class LVColumn is implemented. We should implement more methods to manage all the struct members. Hope it helps you. Once ready we will implement a new method InsertColumn() in Class TListView.
This is the definition of the struct LVCOLUMN from commctrl.h
typedef struct tagLVCOLUMNA
{
UINT mask;
int fmt;
int cx;
LPSTR pszText;
int cchTextMax;
int iSubItem;
#if (_WIN32_IE >= 0x0300)
int iImage;
int iOrder;
#endif
#if _WIN32_WINNT >= 0x0600
int cxMin; // min snap point
int cxDefault; // default snap point
int cxIdeal; // read only. ideal may not eqaul current width if auto sized (LVS_EX_AUTOSIZECOLUMNS) to a lesser width.
#endif
} LVCOLUMNA, *LPLVCOLUMNA;
Please try this example where Class LVColumn is implemented. We should implement more methods to manage all the struct members. Hope it helps you. Once ready we will implement a new method InsertColumn() in Class TListView.
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
local oLVCol := LVColumn():New()
MsgInfo( oLVCol:ClassName() )
oLVCol:Mask = 5
oLVCol:fmt = 6
MsgInfo( oLVCol:Mask )
MsgInfo( oLVCol:fmt )
oLVCol:End()
return nil
CLASS LVColumn
DATA hData HIDDEN
METHOD New()
METHOD mask( nValue ) SETGET
METHOD fmt( nValue ) SETGET
METHOD End() INLINE LVColumnEnd( ::hData )
ENDCLASS
METHOD New() CLASS LVColumn
::hData = LVColumnNew()
return Self
METHOD mask( nValue ) CLASS LVColumn
local nOldValue
if PCount() == 0
nOldValue = LVColumnMask( ::hData )
else
nOldValue = LVColumnMask( ::hData, nValue )
endif
return nOldValue
METHOD fmt( nValue ) CLASS LVColumn
local nOldValue
if PCount() == 0
nOldValue = LVColumnFmt( ::hData )
else
nOldValue = LVColumnFmt( ::hData, nValue )
endif
return nOldValue
#pragma BEGINDUMP
#include <windows.h>
#include <commctrl.h>
#include <hbapi.h>
HB_FUNC( LVCOLUMNNEW )
{
LVCOLUMN * lvcol = ( LVCOLUMN * ) hb_xgrab( sizeof( LVCOLUMN ) );
memset( lvcol, 0, sizeof( LVCOLUMN ) );
hb_retptr( ( void * ) lvcol );
}
HB_FUNC( LVCOLUMNMASK )
{
UINT mask = ( ( LVCOLUMN * ) hb_parptr( 1 ) )->mask;
if( ! hb_pcount() )
hb_retnl( ( HB_LONG ) mask );
else
( ( LVCOLUMN * ) hb_parptr( 1 ) )->mask = ( UINT ) hb_parnl( 2 );
hb_retnl( mask );
}
HB_FUNC( LVCOLUMNFMT )
{
int fmt = ( ( LVCOLUMN * ) hb_parptr( 1 ) )->fmt;
if( ! hb_pcount() )
hb_retnl( ( HB_LONG ) fmt );
else
( ( LVCOLUMN * ) hb_parptr( 1 ) )->fmt = ( int ) hb_parnl( 2 );
hb_retnl( fmt );
}
HB_FUNC( LVCOLUMNEND )
{
hb_xfree( ( void * ) hb_parptr( 1 ) );
}
#pragma ENDDUMP
- nageswaragunupudi
- Posts: 10701
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 3 times
- Contact:
Re: Display thumbnails of pdfs
how to make Thumbnail from pdf, docx, xlsx, ppts?
This information may not be useful in the context of this post, but may be interesting to some.
Some kind of files store the thumbnail also embedded in the same file.
I know only about MS Office files (docx,xlsx,pptx).
While saving these files, there is an option to save "with thumbnails". If the user saves the file with this option a thumbnail image is also saved along with the file. These images are in the formats of "emf,wmf,jpeg" for "docx,xlsx,pptx" respectively.
In case of MS Office files saved with this option, we can extract the thumbnails and save them, using the FWH built-in function:
Code: Select all | Expand
OfficeExtractImage( cOfficeFileName, [lReExtract] ) //--> cThumbNailFile saved.
Sample usage:
Code: Select all | Expand
cThumb := OfficeExtractImage( "mydoc.docx", .t. )
if Empty( cThumb )
? "Thumbnail not saved"
else
? cThumb
XImage( cThumb )
endif
In all other cases, we have to go through the tedious process of displaying the file on the screen, take the screenshot and save it, after resizing if required.
c:\fwh\samples\xblstgrd.prg
c:\fwh\samples\listvie.prg
listvie.prg uses ListView but not xblstgrd.prg. This program uses XBrowse only.
If the purpose of using ListView is to display the application icon along with the filename, I think there are other ways too.
hope is to be able to mimic exactly Windows Explorer capability of showing preview thumbnails of all type of files.
Basic requirement is to "mimic exactly Windows Explorer's functionality".
What Windows Explorer displays in the Preview Pane are NOT thumbnails, but Preview of the file. For this purpose, Windows uses "IPreview Handler" and that is exactly what our program in development is using wherever possible.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: Display thumbnails of pdfs
Thanks for the reply Antonio, Jimmy, Rao and Otto.
Rao is correct, what I aim for is eventually a preview in thumbnail size of any files.
It's just that currently, I want to at least be able to do it with pdfs.
The preview will appear in the boxes below. What control is most suitable?
I'd like it to display filename in a tooltip and if user double-click on it windows will launch the app that is registered for the document type
TIA
Rao is correct, what I aim for is eventually a preview in thumbnail size of any files.
It's just that currently, I want to at least be able to do it with pdfs.
The preview will appear in the boxes below. What control is most suitable?
I'd like it to display filename in a tooltip and if user double-click on it windows will launch the app that is registered for the document type
TIA
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
BCC5.82/BCC7.3
xHarbour/Harbour
Re: Display thumbnails of pdfs
hi,
this is what my CLASS TGrid() will do up to 256 x 256 Thumbnail
i already can load "System-Icon" which are associate with App into ImageList()
i need some "extra" CODE to load any IMAGE e.g. PNG made by mutool.exe
---
the FiveWin Sample c:\fwh\samples\xblstgrd.prg is also a Solution
but you still have to generate Thumbnail of PDF before you can load them
this is what my CLASS TGrid() will do up to 256 x 256 Thumbnail
i already can load "System-Icon" which are associate with App into ImageList()
i need some "extra" CODE to load any IMAGE e.g. PNG made by mutool.exe
---
the FiveWin Sample c:\fwh\samples\xblstgrd.prg is also a Solution
but you still have to generate Thumbnail of PDF before you can load them
greeting,
Jimmy
Jimmy
- Otto
- Posts: 6396
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 8 times
- Been thanked: 1 time
- Contact:
Re: Display thumbnails of pdfs
Hello Jimmy,
would a webview2 project be suitable for this?
LG
Otto
would a webview2 project be suitable for this?
LG
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
Re: Display thumbnails of pdfs
hi Otto,
i do not understand what you want with TGrid() and Webview2
Question : can you use a Explorer Windows with Webview2 ?
you can use [url]file:///C:/Temp/[/url] as URL and display Files but that is not Explorer Window
---
or do you mean ImageList()
i do not know if HTML use Imagelist which is the Windows Way to load Image up to 256 x 256 (SHIL_JUMBO)
as i know Browser like FireFox will download all Image into "Cache" Folder and that load to display
Otto wrote:would a webview2 project be suitable for this?
i do not understand what you want with TGrid() and Webview2
Question : can you use a Explorer Windows with Webview2 ?
you can use [url]file:///C:/Temp/[/url] as URL and display Files but that is not Explorer Window
---
or do you mean ImageList()
i do not know if HTML use Imagelist which is the Windows Way to load Image up to 256 x 256 (SHIL_JUMBO)
as i know Browser like FireFox will download all Image into "Cache" Folder and that load to display
greeting,
Jimmy
Jimmy