FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Crear pdf y abrirlo con HTMLVIEW [RESUELTO
Posts: 152
Joined: Mon Feb 13, 2006 08:23 PM
Crear pdf y abrirlo con HTMLVIEW [RESUELTO
Posted: Fri Oct 15, 2021 07:59 AM
Buenos días a todos

Veréis, tengo un pequeño problema al convertir un fichero rtf en pdf. El fichero pdf lo crea sin problemas, pero al tratarlo de ver con HTMLVIEW() resulta que no se ve nada porque HTMLVIEW se abre antes de haberse creado el pdf.

El pdf lo creo con OfficetoPdf.exe.

El código es el siguiente:
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()
local cExec, cPara, p1, p2
 
 P1:= "c:\sample\test.rtf"
 P2:= "C:\sample\test.pdf"
  
cPara :=" " + P1 + " " + P2 

cExec :="c:\sample\"+"OfficetoPdf.exe" //hidden(con OfficetoPdf.exe /hidden no crea pdf, no sé por qué)
ShellExecute( 0,"Open", cExec, cPara,0,1)

//Shellexecute(GetActiveWindow(),"open", P2 ,,,1)

HTMLVIEW(P2)
return NIL


Por cierto, me gusta mucho la presentación con HTMLVIEW.

¿Alguna sugerencia?

Saludos y gracias
Ramón
FWH 20.12 BCC7
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 08:41 AM

Facil. Pon un Sleep() despues de Shellexecute() o bien invoca al officetopdf.exe con WaitRun() o similar.

Otra opcion es que borres el .pdf por si ya existiera, despues del shellexecute haces algo asi poniendole limitacion de tiempo para que no entre en un bucle eterno

// Aqui falta introducir un limitante de tiempo
DO WHILE !File(P2)
Sleep(.01)
ENDDO

Posts: 152
Joined: Mon Feb 13, 2006 08:23 PM
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 09:48 AM
Gracias, Paquito, por tu pronta respuesta. ¿Sugieres algo asi?

Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()
local cExec, cPara, p1, p2
 
 P1:= "c:\sample\test.rtf"
 P2:= "C:\sample\test.pdf"
 
cPara :=" " + P1 + " " + P2

if File(P2)
ferase ("C:\sample\test.pdf")
endif

cExec :="c:\sample\"+"OfficetoPdf.exe"//hidden(con OfficetoPdf.exe /hidden no crea pdf, no sé por qué)
ShellExecute( 0,"Open", cExec, cPara,0,1)


DO WHILE !File(P2)
Sleep(.01)
ENDDO

//Shellexecute(GetActiveWindow(),"open", P2 ,,,1)

HTMLVIEW(P2)
return NIL
FWH 20.12 BCC7
Posts: 152
Joined: Mon Feb 13, 2006 08:23 PM
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 10:18 AM
Ahora ya funciona.
Para que no se vea la ventana de CMD de OfficetoPdf mientras se ejecuta, he añadido el parámetro 2 en:

ShellExecute( 0,"Open", cExec, cPara,0,2)

Por lo menos así no se ve la ventanita negra.

Me faltaría probar con WaitRun()

Gracias
Saludos
FWH 20.12 BCC7
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 02:35 PM
Empezando a compilar con HARBOUR para aprender más. No es tan malo como imaginaba. jajajajajajaja. -> HARB.BAT Y HARB.LNK

Download completo aqui:

https://mega.nz/file/lN8SGYia#jBQCsbwC6 ... x2odaMRp7k

Code (fw): Select all Collapse
//-> C:\OFFICEPD\EXAMPLE.PRG -> README.TXT

#Include "FiveWin.ch"

MEMVAR cDirExe

FUNCTION Main()

   LOCAL cTxtPdf1, cTxtPdf2, cFile

   cDirExe := GETCURDIR()

   IF SUBS( cDirExe, LEN( ALLTRIM(cDirExe ) ) , 1 ) = "\"
      cDirExe := SUBS( cDirExe, 1 , LEN( ALLTRIM(cDirExe ) ) - 1 )
   ENDIF

   LCHDIR( cDirExe )

   cTxtPdf1 := cDirExe + "\README.txt"
   cTxtPdf2 := cDirExe + "\TESTE.pdf"

   cFile := ConvertePdf( cTxtPdf1, cTxtPdf2 )

   IF cFile > 0

      HTMLVIEW( cDirExe + "\TESTE.pdf" )

   ELSE

      MsgStop( "Algo errado con el Archivo .PDF", "Error" )

   ENDIF

RETURN NIL

FUNCTION ConvertePdf( cTxtPdf1, cTxtPdf2 )

   LOCAL cExec, cParaPDF, cRet

   cParaPDF := " " + cTxtPdf1 + " " + cTxtPdf2

   IF FILE( cDirExe + "\TESTE.pdf" )

      FERASE( cDirExe + "\TESTE.pdf" )

   ENDIF

   cExec :=  cDirExe + "\OfficetoPdf.exe"

   cRet := ShellExecute( 0, "Open", cExec, cParaPDF, 0, 0 )
   // cRet := ShellExecute( 0, "Open", cExec, cParaPDF, 0, 2 )

   SysWait( 10 )

RETURN( cRet )

// FIN / END


Regards, saludos
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 152
Joined: Mon Feb 13, 2006 08:23 PM
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 02:50 PM

João, perdona que esté espeso, pero no acabo de pillar el fondo del mensaje.

FWH 20.12 BCC7
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 03:04 PM
Ramón J. wrote:João, perdona que esté espeso, pero no acabo de pillar el fondo del mensaje.



Lo siento Ramón, no entiendo a qué te refieres.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Sat Oct 16, 2021 02:01 PM
Ahora usando SumatraPDF.exe, Download completo aqui:

https://mega.nz/file/VJVzjaKS#ZHZjxtJDV7lwDUvACIo3WT4Bngm85Oh2O_j2g5xjGVg

Code (fw): Select all Collapse
//-> C:\OFFICEPD\EXAMPLE.PRG -> README.TXT - 16/10/2021 - <!-- e --><a href="mailto:kapiabafwh@gmail.com">kapiabafwh@gmail.com</a><!-- e -->.

#Include "FiveWin.ch"

STATIC lViewSumatraPDF := .T.

MEMVAR cDirExe

FUNCTION Main()

   LOCAL cTxtPdf1, cTxtPdf2, cFile

   cDirExe := GETCURDIR()

   IF SUBS( cDirExe, LEN( ALLTRIM(cDirExe ) ) , 1 ) = "\"
      cDirExe := SUBS( cDirExe, 1 , LEN( ALLTRIM(cDirExe ) ) - 1 )
   ENDIF

   LCHDIR( cDirExe )

   cTxtPdf1 := cDirExe + "\README.txt"
   cTxtPdf2 := cDirExe + "\TESTE.pdf"

   cFile := ConvertePdf( cTxtPdf1, cTxtPdf2 )

   IF cFile > 0

      IF lViewSumatraPDF // .T.

         WaitRun( cDirExe+"\SumatraPDF.exe -reuse-instance -lang br "+cTxtPdf2 )

      ELSE

         HTMLVIEW( cDirExe + "\TESTE.pdf" )

      ENDIF

   ELSE

      MsgStop( "Algo errado con el Archivo .PDF", "Error" )

   ENDIF

RETURN NIL

FUNCTION ConvertePdf( cTxtPdf1, cTxtPdf2 )

   LOCAL cExec, cParaPDF, cRet

   cParaPDF := " " + cTxtPdf1 + " " + cTxtPdf2

   IF FILE( cDirExe + "\TESTE.pdf" )

      FERASE( cDirExe + "\TESTE.pdf" )

   ENDIF

   cExec :=  cDirExe + "\OfficetoPdf.exe"

   cRet := ShellExecute( 0, "Open", cExec, cParaPDF, 0, 0 )
   // cRet := ShellExecute( 0, "Open", cExec, cParaPDF, 0, 2 )

   SysWait( 10 )

RETURN( cRet )

// FIN / END


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 152
Joined: Mon Feb 13, 2006 08:23 PM
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Sat Oct 16, 2021 07:01 PM

Muchas gracias, João. Perdona el malentendido.

Saludos

FWH 20.12 BCC7

Continue the discussion