Most powerfull Xbrowser and PDF

Most powerfull Xbrowser and PDF

Postby Marc Venken » Mon Nov 18, 2024 8:21 am

We know that Xbrowse is the most powerfull browser and PDF's are the most used document files. I'm not able to show the pdf's like we do the jpg, bmp in browse.
From a post yesterday mr. Rao had these options. Can it be converted to include the viewing of pdf's ? At this point I need a 3the party to convert the pdf to jpg for browsing large data files.

Sample with XImage (from Mr. Rao) https://forums.fivetechsupport.com/viewtopic.php?f=3&t=45155&sid=4d9e57d7689b479b76d45fd4c4cf140f

The sample uses Memo files, but that is NOT needed. Just a lot of pdf's in a location on disk.

Mr. Rao, if you are reading this, you once placed a preview of Xbrowse showing the Pdf's. and lots of other extensions. I would be happy if only the Pdf's can be added for this time.

Code: Select all  Expand view
#include "fivewin.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oFont, oBrw, oImage

   if !File( "IMAGES.DBF" )
      CreateImagesDBF()
   endif

   USE IMAGES NEW SHARED VIA "DBFCDX"

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "XBROWSE + XIMAGE"
   @ 20,20 XBROWSE oBrw SIZE 380,-20 PIXEL OF oDlg ;
      DATASOURCE "IMAGES" ;
      COLUMNS "FOLDER", "NAME" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :AutoFit()
      :nStretchCol := 1
      :bChange    := { || oImage:Refresh() }
      :CreateFromCode()
   END

   @ 20,400 XIMAGE oImage SIZE -20,-20 OF oDlg ;
      SOURCE ( oBrw:cAlias )->IMAGE

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//

function CreateImagesDBF()

   DBCREATE( "IMAGES.DBF", { { "NAME", "C", 10, 0 }, ;
      { "FOLDER", "C", 40, 0 }, { "IMAGE", "M", 8, 0 } }, ;
      "DBFCDX", .T., "IMG" )

   AEval( ;
      { "..\bitmaps\olga1.jpg", "..\bitmaps\sea.bmp", ;
      "..\bitmaps\pngs\2.png", "..\bitmaps\007.bmp" }, <|c|
         DBAPPEND()
         FIELD->NAME    := UPPER( cFileName( c ) )
         FIELD->FOLDER  := cFilePath( c )
         FIELD->IMAGE   := MEMOREAD( c )
         return nil
         > )

   CLOSE IMG

return nil


Code from inside Xbrowse

Code: Select all  Expand view
#include "fivewin.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oFont, oBrw, oImage

   if !File( "IMAGES.DBF" )
      CreateImagesDBF()
   endif

   USE IMAGES NEW SHARED VIA "DBFCDX"

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16

   DEFINE DIALOG oDlg SIZE 800,500 PIXEL TRUEPIXEL FONT oFont ;
      TITLE "XBROWSE WITHOUT XIMAGE"

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "IMAGES" ;
      COLUMNS "FOLDER", "NAME", "IMAGE" ;
      COLSIZES 200,150,400 ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :oRightCol   := "IMAGE"
      :oRightCol:lFullHeight := .t.
      :oRightCol:nDataBmpAlign := AL_CENTER
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//

function CreateImagesDBF()

   DBCREATE( "IMAGES.DBF", { { "NAME", "C", 10, 0 }, ;
      { "FOLDER", "C", 40, 0 }, { "IMAGE", "M", 8, 0 } }, ;
      "DBFCDX", .T., "IMG" )

   AEval( ;
      { "..\bitmaps\olga1.jpg", "..\bitmaps\sea.bmp", ;
      "..\bitmaps\pngs\2.png", "..\bitmaps\007.bmp" }, <|c|
         DBAPPEND()
         FIELD->NAME    := UPPER( cFileName( c ) )
         FIELD->FOLDER  := cFilePath( c )
         FIELD->IMAGE   := MEMOREAD( c )
         return nil
         > )

   CLOSE IMG

return nil
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Most powerfull Xbrowser and PDF

Postby Jimmy » Mon Nov 18, 2024 9:57 am

hi Marc,

i use MOTOOL to create Thumbnails (every Size) from PDF
viewtopic.php?t=42301&start=2

you can get MOTOOLS here
https://github.com/ArtifexSoftware/mupdf
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Most powerfull Xbrowser and PDF

Postby Otto » Mon Nov 18, 2024 10:02 am

Hi Mark,
The provided code in ScrnShot.Prg is a FiveWin/Harbour program containing several functions for capturing screenshots and converting files into JPEG images.
Best regards,
Otto

viewtopic.php?f=3&t=42301&p=254919&hilit=xdocviewer&sid=1db1e2f0d7449de3a058698618c5b1e8#p254919

The provided code in ScrnShot.Prg is a FiveWin/Harbour program containing several functions for capturing screenshots and converting files into JPEG images. Here's an explanation of the key functions and their purposes:

1. PdfToJpeg(cPDF)
Converts a PDF file to a JPEG image.
Steps:
Opens the PDF in PDF-XChange Viewer.
Captures the window displaying the PDF using WndBitmap.
Trims unnecessary borders (BmpTrim) and saves the bitmap as a JPEG file using BmpBufToJpg.
2. FindWnd(cTitle)
Finds a window handle (hWnd) by matching its title (cTitle).
Uses a loop to traverse through all child windows on the desktop.
3. BmpTrim(hBmp)
Trims black areas from the sides of a bitmap.
Calculates non-black pixel regions and crops the bitmap to reduce empty spaces.
4. WordToJpeg(cFile)
Converts a Microsoft Word document to a JPEG image.
Steps:
Opens the Word document using OLE automation.
Captures the displayed window content as a bitmap.
Processes and trims the bitmap (DocBmpTrim).
Saves the resulting bitmap as a JPEG.
5. DocBmpTrim(hBmp)
Similar to BmpTrim, but specifically optimized for trimming a bitmap generated from a Word document.
Identifies the document content area and removes surrounding borders.
6. BmpBufToJpg(cJpeg, cBuf)
Converts a bitmap buffer (cBuf) into a JPEG file (cJpeg).
Uses the FreeImage library for the conversion.
7. RTFToJpeg(cPDF)
Converts an RTF (Rich Text Format) file to a JPEG image.
Steps:
Opens the file in WordPad.
Captures and trims the displayed content as a bitmap.
Converts the processed bitmap to a JPEG file.
8. FindAllWnd()
Retrieves all window titles and their handles on the desktop.
Useful for debugging or identifying target windows for further processing.
9. MSGToJpeg(cMSG)
Converts an Outlook MSG file to a JPEG image.
Steps:
Opens the MSG file using the default program.
Captures the displayed content as a bitmap.

Processes and saves it as a JPEG file.
10. StandardDruckerUmstellen(cDruckerName)
Temporarily changes the system's default printer to cDruckerName.
Returns the previous default printer name for restoration.
11. change2default_printer(coldprinter)
Restores the previously saved default printer (coldprinter).
12. ENUMCHILDWINDOWS
A C function embedded with #pragma BEGINDUMP.
Enumerates all child windows of a given parent window (hWnd) and executes a Harbour code block for each window.
This enables dynamic interaction with GUI elements in other applications.
Main Use Cases:
File Conversion: Converts PDF, Word, RTF, and MSG files to JPEG images.
GUI Automation: Finds and interacts with application windows using their titles.
Screenshot Processing: Captures and processes screenshots of applications or files.
Printer Management: Temporarily changes and restores the default printer.



Code: Select all  Expand view

 
 
  #include "fivewin.ch"
 
  #define GW_CHILD        5
  #define GW_HWNDNEXT     2
 
  //----------------------------------------------------------------------------//
 
  function PdfToJpeg( cPDF )
   local cExe     := "c:\Tracker Software\PDF Viewer\PDFXCview.exe"
   local cTitle   := cFileNoExt( cPDF  ) //+ " - PDF-XChange Viewer"
   local cCmd, oIni
   local hWnd, hBmp, hBmp2, hDib, cBuf, nWait := 2
   local lRet  := .f.
   
   
   oIni     := TIni():New( "PDFXCVIEW.INI" )
   cExe     := oIni:Get(  "PDFXCVIEW", "FULLPATH",  cExe )
   if ! File( cExe )
      cExe     := cGetFile( "PDFXCView.Exe |PDFXCView.Exe|", "Select Installed Location", ;
         nil, "c:\" )
   endif
   if Empty( cExe ) .or. ! File( cExe )
   return .f.
endif

oIni:Set( "
PDFXCVIEW", "FULLPATH",  cExe )


if File( cExe ) .and. File( cPDF )
   // cCmd  := cExe + ' /A "
fullscreen=yes"' +  ' ' +  LFN2SFN(  cPDF )
   cCmd  := cExe + ' /A "
fullscreen=yes"' +  ' "' +  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

//----------------------------------------------------------------------------//
function FindWnd( cTitle )
   
   local hWnd := GetWindow( GetDesktopWindow(), GW_CHILD )
   local aGetWindowText := {}
   *----------------------------------------------------------
   
   while hWnd != 0
      if len (alltrim( GetWindowText( hWnd ) ) ) > 0
         AADD( aGetWindowText, left( Upper( GetWindowText( hWnd ) ), len( ALLTRIM( cTitle) ) ) )
      endif
      if Upper( cTitle ) $   left( Upper( GetWindowText( hWnd ) ), len( ALLTRIM( cTitle) ) )
         
      return hWnd
   endif
   
   hWnd = GetWindow( hWnd, GW_HWNDNEXT )
end

// xbrowse( aGetWindowText )
return nil

//----------------------------------------------------------------------------//

static function BmpTrim( hBmp )  // Trim black sides on left and right
   
   local hOldBmp, hDC, hDCMem, hBmpTrim
   local nLeft := 0, nRight := 0
   local nHeight, nWidth, ny
   *----------------------------------------------------------
   
   nWidth   := nBmpWidth(  hBmp )
   nHeight  := nBmpHeight( hBmp )
   
   hDC      := GetDC( GetDeskTopWindow() )
   hDCMem   := CreateCompatibleDC( hDC )
   hOldBmp  := SelectObject( hDCMem, hBmp )
   
   ny       := Int( nHeight / 2 )
   do while nLeft < .4 * nWidth .and. GetPixel( hDCMem, nLeft, ny ) == 0
      nLeft++
   enddo
   nRight   := nWidth - 1
   do while nRight > .6 * nWidth .and. GetPixel( hDCMem, nRight, ny ) == 0
      nRight--
   enddo
   SelectObject( hDCMem, hOldBmp )
   DeleteDC( hDCMem )
   ReleaseDC( GetDesktopWindow(), hdc )
   
   hBmpTrim    := CropImage( hBmp, 0, nLeft, nHeight, nRight )
   
return hBmpTrim

//----------------------------------------------------------------------------//


function WordToJpeg( cFile )
   local oWord, oDoc, hWnd, hBmp,hBmp2, hDib, cBuf
   local lRet  := .f.
   local nWidth   := GetSysMetrics( 0 )
   local nHeight := GetSysMetrics( 1 )  
   
   
   if nWidth > 1920
      nWidth :=  1124 //1920
   endif
   
   
   oWord := CreateObject("
Word.Application")    
   
   if ( oWord := WinWordObj() ) == nil
      //    MsgInfo( "
Can not load MS Word OLE" )
     
   else
      oWord:Caption  := "
TEMPWINHOTEL"
     
      if Empty( hWnd := FindWnd(  "
TEMPWINHOTEL" ) )
         //  MsgInfo( "
MS Word not active" )
      else
         oDoc              := oWord:Documents:Open( cFile )
         oWord:ActiveDocument:ActiveWindow:View:ReadingLayout := .t.
         oWord:Visible     := .t.
         oWord:WindowState := 1 // Maximize
         
         SetFocus( hWnd )
         SetForeGroundWindow( hWnd )
         SysRefresh()
         
         SysRefresh()
         SysWait( 0.9 )
         
         hBmp              := WndBitmap( hWnd )
         oDoc:Close()
         oWord:Quit()
         /*
         hBmp              := DocBmpTrim( hBmp )
         hDib              := DibFromBitmap( hBmp )
         cBuf              := DibToStr( hDib )
         
         */      
         
         hBmp2              := DocBmpTrim( hBmp )
         
         DeleteObject( hBmp )
         
         //CropImage( hOringalBmp, nTop, nLeft, nBottom, nRight ) --> hCroppedBmp.
         hBmp2 := CropImage( hBmp2, 150, 40, nHeight,nWidth )    
         hDib              := DibFromBitmap( hBmp2 )
         cBuf              := DibToStr( hDib )
         
         GlobalFree( hDib )
         DeleteObject( hBmp )
         lRet              := BmpBufToJpg( cFileSetExt( cFile, "
jpg" ), cBuf )
         cBuf              := nil
         
         // Without some message, GPF is occuring
         SysWait(0.2)
         
         SysRefresh()
         
      endif
     
   endif
   
   //FindAllWnd( )
   
return lRet

//----------------------------------------------------------------------------//

static function DocBmpTrim( hBmp )
   
   local hOldBmp, hDC, hDCMem, hBmpTrim
   local nLeft := 1, nRight := 0, nTop := 1, nBottom := 0
   local nBmpHeight, nBmpWidth, ny, nx
   local nColor      := 0
   local lTrimmed    := .f.
   *----------------------------------------------------------
   
   nBmpWidth   := nBmpWidth(  hBmp )
   nBmpHeight  := nBmpHeight( hBmp )
   nRight      := nBmpWidth - 2
   nBottom     := nBmpHeight - 2
   
   hDC         := GetDC( GetDeskTopWindow() )
   hDCMem      := CreateCompatibleDC( hDC )
   hOldBmp     := SelectObject( hDCMem, hBmp )
   
   ny          := Int( nBmpHeight / 2 )
   nx          := Int( nBmpWidth / 2 )
   
   if ( nColor := GetPixel( hDCMem, 1, nY ) ) == GetPixel( hDCMem, nBmpWidth - 2, nY )
   else
      nColor   := -1
   endif
   
   if nColor >= 0
      do while nLeft < .4 * nBmpWidth .and. GetPixel( hDCMem, nLeft, ny ) == nColor
         nLeft++
      enddo
      do while nRight > .4 * nBmpWidth .and. GetPixel( hDCMem, nRight, ny ) == nColor
         nRight--
      enddo
     
      nTop     := 2
      nBottom  := nBmpHeight - 3
     
      nX       := Int( ( nLeft + nRight ) / 2 )
     
      nColor   := GetPixel( hDCMem, nX, 2 )
     
      do while nTop < .4 * nBmpHeight .and. GetPixel( hDCMem, nX, nTop ) == GetPixel( hDCMem, 2, nTop )
         nTop++
      enddo
      do while nBottom > .6 * nBmpHeight .and. GetPixel( hDCMem, nX, nBottom ) == GetPixel( hDCMem, 2, nBottom )
         nBottom--
      enddo
      lTrimmed := .t.
   endif
   
   SelectObject( hDCMem, hOldBmp )
   DeleteDC( hDCMem )
   ReleaseDC( GetDesktopWindow(), hdc )
   
   if lTrimmed
      hBmpTrim    := CropImage( hBmp, nTop, nLeft, nBottom, nRight - 800 )
      DeleteObject( hBmp )
   endif
   
return If( lTrimmed, hBmpTrim, hBmp )

//----------------------------------------------------------------------------//

static function BmpBufToJpg( cJpeg, cBuf )
   
   local hMem, nFormat, hDib, hDib2, lRet := .f.
   local nQuality    := 0  // Default
   
   if LoadFreeImage() <= 32
      MsgAlert( "
freeimage.dll not found" )
   return .f.
endif

hMem        := FI_OpenMemory( cBuf, Len( cBuf ) )
nFormat     := FI_GetFileTypeFromMemory( hMem, 0 )
hDib        := FI_LoadFromMemory( nFormat, hMem, 0 )
cBuf        := nil  // to release memory
FI_CloseMemory( hMem )
hDib2       := FICnv24( hDib )
FIUnload( hDib )
lRet        := FISave( 2, hDib2, cJpeg, nQuality )
FIUnload( hDib2 )

return lRet

//----------------------------------------------------------------------------//

function RTFToJpeg( cPDF )
   local oPrn
   local cExe     := "
c:\Program Files\Windows NT\Accessories\wordpad.exe"
   local cTitle   := cFileNoExt(    cPDF  ) //+ "
- PDF-XChange Viewer"
   local cCmd, oIni, hCroppedBmp
   local hWnd, hBmp, hBmp2, hDib, cBuf, nWait := 2
   local lRet  := .f.
   local cFile
   local nWidth   := GetSysMetrics( 0 )
   local nHeight := GetSysMetrics( 1 )  
   
   
   if nWidth > 1920
      nWidth :=  1920
   endif
   
   if File( cPDF )
      cCmd  := cExe +   ' ' +  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 )
         
         //CropImage( hOringalBmp, nTop, nLeft, nBottom, nRight ) --> hCroppedBmp.
         hBmp2 := CropImage( hBmp2, 150, 420, nHeight,nWidth-420 )    
         hDib              := DibFromBitmap( hBmp2 )
         cBuf              := DibToStr( hDib )
         GlobalFree( hDib )
         
         DeleteObject( hBmp2 )
         
         lRet   := BmpBufToJpg( cFileSetExt( cPDF, "
jpg" ), cBuf )
         cBuf   := nil
         
      endif
   endif
   
return lRet

//----------------------------------------------------------------------------//

function FindAllWnd( )
   
   local hWnd               := GetWindow( GetDesktopWindow(), GW_CHILD )
   local aGetWindowText := {}
   *----------------------------------------------------------
   
   while hWnd != 0
     
      if len (alltrim( GetWindowText( hWnd ) ) ) > 0
         AADD( aGetWindowText, { GetWindowText( hWnd ), hWnd } )
      endif  
      hWnd = GetWindow( hWnd, GW_HWNDNEXT )
     
   end
   
   xbrowse( aGetWindowText )
return nil

//----------------------------------------------------------------------------//

function MSGToJpeg( cMSG )
   local cTitle   := "
"
   local hWnd, hBmp, hBmp2, hDib, cBuf, nWait := 2
   local lRet := .f.
   local nWidth := GetSysMetrics( 0 )
   local nHeight := GetSysMetrics( 1 )
   local aClass := {}
   
   cTitle := msgGetTitle( cMSG )
return nil

if nWidth > 1920
   nWidth :=  1920
endif

if File( cMSG )
   ShellExecute( 0, 'Open', cMSG )
   SysWait( 3 )
   
   do while nWait < 5 .and. Empty( hWnd :=  FindWnd( cTitle ) )
      SysWait( nWait )
      nWait    += 1
   enddo
   
   
   if ! Empty( hWnd )
      SetFocus( hWnd )
      SetForeGroundWindow( hWnd )
      SysRefresh()
      SysWait( 0.8 )
      // for a test
      EnumChildWindows( hWnd,;
         { | hWnd, nLParam | AADD( aClass,{ GetClassName( hWnd ), hWnd } ), .T. },; // .T. means continue
      0 )                                 // optional supplied value
     
      xbrowse( aClass )
      // for a test end
     
      hBmp  := WndBitmap( hWnd )
     
      SendMessage( hWnd, WM_CLOSE )
      hBmp2 := BmpTrim( hBmp )
     
      DeleteObject( hBmp )
     
      //    hBmp2 := CropImage( hBmp2, 150, 420, nHeight,nWidth-420 )
      hDib              := DibFromBitmap( hBmp2 )
      cBuf              := DibToStr( hDib )
      GlobalFree( hDib )
     
      DeleteObject( hBmp2 )
     
      lRet  := BmpBufToJpg( cFileSetExt( cMSG, "
jpg" ), cBuf )
      cBuf  := nil
     
     
   endif
endif

return lRet

//----------------------------------------------------------------------------//

//coldprinter := StandardDruckerUmstellen( cDruckerName )
function StandardDruckerUmstellen( cDruckerName )
   local coldprinter := prnGetName()            // default printer
   *----------------------------------------------------------
   
   if len( ALLTRIM( cDruckerName ) )  > 0
      WriteProfString( "
windows", "device", cDruckerName ) // change to new printer
      SetPrintDefault( cDruckerName )
      PrinterInit()
      SysRefresh()  
     
   endif          
   
return( coldprinter )
//------------------------------------------------------------------------------------------//

function  change2default_printer( coldprinter )
   
   WriteProfString( "
windows", "device",coldprinter) // default printer
   SetPrintDefault(coldprinter)
   PrinterInit()
   SysRefresh()
return nil
//------------------------------------------------------------------------------------------//  

#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapiitm.h>
#include <windows.h>

void hb_evalBlock( PHB_ITEM pCodeBlock, ... );
   
static PHB_ITEM pCodeBlock = NULL;
   
BOOL CALLBACK static EnumChildProc( HWND hWnd, LPARAM lParam )
{
PHB_ITEM pHWnd  = hb_itemPutNL( NULL, ( LONG ) hWnd );
   PHB_ITEM pParam = hb_itemPutNL( NULL, ( LONG ) lParam );
     
if( pCodeBlock )
   hb_evalBlock( pCodeBlock, pHWnd, pParam, 0 );
     
   hb_itemRelease( pHWnd );
      hb_itemRelease( pParam );  
   
return hb_parl( -1 );      
}  

HB_FUNC( ENUMCHILDWINDOWS )
{
HWND hWnd = ( HWND ) hb_parnl( 1 );
   LPARAM lParam = ( LPARAM ) hb_parnl( 3 );
     
pCodeBlock = hb_param( 2, HB_IT_BLOCK );
   hb_retl( EnumChildWindows( hWnd, EnumChildProc, lParam ) );
      pCodeBlock = NULL;
         }  

#pragma ENDDUMP


********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Most powerfull Xbrowser and PDF

Postby Marc Venken » Mon Nov 18, 2024 10:29 am

Thanks Guys ....

I'm using Poppler for converting

But in the topic Jimmy provided you can see that Mr. Rao did show PDFs from xbrowse with no conversions at all.

https://forums.fivetechsupport.com/viewtopic.php?f=3&t=42301&start=15&sid=a72eba99a1f20a5db197b7484d61b332&sid=a72eba99a1f20a5db197b7484d61b332#p254887

Just the code for pdf's would be helpfull at this moment. Maybe at later stage Mr. Rao wants to implement it for Fwin Libraries. If testing purposes is needed, i'm gladly to help.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Most powerfull Xbrowser and PDF

Postby nageswaragunupudi » Mon Nov 18, 2024 11:21 am

Please try this and provide your feedback
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local aDir, oWnd, oView, oBrw
   local cPath := ".\"  // give your path

   HB_CDPSELECT( "
UTF8" )
   aDir  := DIRECTORY( "
*.pdf" )
   AEval( aDir, { |a| a[ 1 ] := cPath + a[  1 ] } )

   DEFINE WINDOW oWnd FROM 0,0 TO 800,1000 PIXEL

   oView := CreateView( aDir[ 1,1 ], oWnd )

   @ 20,20 XBROWSE oBrw SIZE 150,-20 PIXEL OF oWnd ;
      DATASOURCE aDir COLUMNS 1 HEADERS "
NAME" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :bChange := { || oView:Navigate( TrueName( oBrw:aRow[ 1 ] ) ) }
      :CreateFromCode()
   END

   ACTIVATE WINDOW oWnd CENTERED

return nil

function CreateView( cPdf, oWnd )

   local oPanel, oView

   oPanel := TPanel():New( 20, 150, oWnd:nBottom-80, oWnd:nWidth-20, oWnd, nil, nil, .t. )

   oView := TWebView2():New( oPanel )
   WITH OBJECT oView
      :Navigate( TrueName( cPdf ) )
      :SetUserAgent( "
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )
      sleep( 300 )
   END

return oView


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Most powerfull Xbrowser and PDF

Postby Marc Venken » Mon Nov 18, 2024 12:44 pm

I have to setup the latest version that I do have, in order to try it (missing WebView) . Will try it this evening.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Most powerfull Xbrowser and PDF

Postby Jimmy » Mon Nov 18, 2024 2:19 pm

hi,
nageswaragunupudi wrote:Please try this and provide your feedback
Code: Select all  Expand view
#include "fivewin.ch"
function Main()
   local cPath := ".\"  // give your path
   aDir  := DIRECTORY( "
*.pdf" )


if use a different Path e.g. "G:\CT\" i need to include it in DIRECTORY(cPath +"*.PDF") else LEN(aDir) is Empty()
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Most powerfull Xbrowser and PDF

Postby nageswaragunupudi » Mon Nov 18, 2024 6:13 pm

Jimmy wrote:hi,
nageswaragunupudi wrote:Please try this and provide your feedback
Code: Select all  Expand view
#include "fivewin.ch"
function Main()
   local cPath := ".\"  // give your path
   aDir  := DIRECTORY( "
*.pdf" )


if use a different Path e.g. "G:\CT\" i need to include it in DIRECTORY(cPath +"*.PDF") else LEN(aDir) is Empty()


Sorry for the mistake
Code: Select all  Expand view
  aDir  := DIRECTORY( cPath + "*.pdf" )
 


Thanks
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Most powerfull Xbrowser and PDF

Postby nageswaragunupudi » Mon Nov 18, 2024 6:29 pm

Maybe at later stage Mr. Rao wants to implement it for Fwin Libraries. If testing purposes is needed, i'm gladly to help.


We already have a function for the last few years that can be used here.
Code: Select all  Expand view
htmlview( "FullPath.pdf" )

This was working for the last few years but giving problems recently.
Note: This function uses the old IE Activex.
Can anybody try this simple code and let me know if it is working on their PCs?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Most powerfull Xbrowser and PDF

Postby Marc Venken » Tue Nov 19, 2024 11:29 am

I'm allready using htmlview and it works for me (opening adobe pdf) , but I have the issue that i can not position the HTML window. Otherwise I would position the html window at the same coordinates as the XImage and when scrolling the user would hardly see it.

With implementing I mean in the source of XBrowse.

Code: Select all  Expand view

         WITH OBJECT :proefdruk
             :nEditType     := EDIT_GET_BUTTON
             :bBmpAction    := { || if(at(".JPG",oBrw:aCols[oBrw:nColSel]:VALUE)>0,XIMAGE(oBrw:aCols[oBrw:nColSel]:VALUE),HTMLVIEW(oBrw:aCols[oBrw:nColSel]:VALUE)) }
             :bEditBlock    := { |r,c,oCol| cResult:= LookupFiles("LOGOS",oBrw,oCol:value),oCol:varput(cResult) }
             :bRClickData := { |r,c,f,oStru| HTMLVIEW(oBrw:aCols[oBrw:nColSel]:VALUE,oBrw:aCols[oBrw:nColSel]:VALUE,oDlg,10,100,500,500) }
         END
 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Most powerfull Xbrowser and PDF

Postby Otto » Tue Nov 19, 2024 1:52 pm

Hi Mark,
when you browse with the arrow keys, do the PDF files open quickly enough to work smoothly?
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Most powerfull Xbrowser and PDF

Postby nageswaragunupudi » Tue Nov 19, 2024 2:17 pm

but I have the issue that i can not position the HTML window.

Yes, we can help you with that.

We can use htmlview( c ) for pdf file, json files, xml files also. in addition to any Url or html files
With some modifications, we can also view any image file also.

For linking with XBrowse, we need to use a modified version of htmlview and we can provide the change.

Sadly on my PC viewing pdfs with html view is giving problems. I guess it is because of some web security settings.

Webview is working very smoothly. So I moved my previous code to WebView.

And yes, navigation speeds with arrow keys are good same like displaying different images.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Most powerfull Xbrowser and PDF

Postby Marc Venken » Tue Nov 19, 2024 3:09 pm

Otto wrote:Hi Mark,
when you browse with the arrow keys, do the PDF files open quickly enough to work smoothly?
Best regards,
Otto


Otto, It may look so, but the xbrowser is NOT showing the PDF content, while moving up/down just a icon of pdf file. I have to click on it to see the content.

So I hope that Mr. Rao will give Xbrowse the first position to move pdf code into it ))))))))))
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Most powerfull Xbrowser and PDF

Postby Otto » Tue Nov 19, 2024 4:29 pm

Hello Mark,
Where do you need this preview, and do the PDFs change often?
After realizing that opening the PDFs is too slow for a "visual-manual" search, I chose the approach of converting the PDFs into image files using the code I posted here yesterday, also for DOC files. This way, you can view the images in XBrowse, and if something is interesting, open the PDF.
I don't think it works to open PDFs in real time.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Most powerfull Xbrowser and PDF

Postby Marc Venken » Wed Nov 20, 2024 7:43 pm

Otto,

I use the same approuch.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 71 guests