Page 1 of 1
Crear pdf y abrirlo con HTMLVIEW [RESUELTO
Posted: Fri Oct 15, 2021 7:59 am
by Ramón J.
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: Select all | Expand
#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
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 8:41 am
by hmpaquito
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
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 9:48 am
by Ramón J.
Gracias, Paquito, por tu pronta respuesta. ¿Sugieres algo asi?
Code: Select all | Expand
#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
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 10:18 am
by Ramón J.
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
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 2:35 pm
by karinha
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 ... x2odaMRp7kCode: Select all | Expand
//-> 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
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 2:50 pm
by Ramón J.
João, perdona que esté espeso, pero no acabo de pillar el fondo del mensaje.
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Fri Oct 15, 2021 3:04 pm
by karinha
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.
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Sat Oct 16, 2021 2:01 pm
by karinha
Ahora usando SumatraPDF.exe, Download completo aqui:
https://mega.nz/file/VJVzjaKS#ZHZjxtJDV7lwDUvACIo3WT4Bngm85Oh2O_j2g5xjGVgCode: Select all | Expand
//-> C:\OFFICEPD\EXAMPLE.PRG -> README.TXT - 16/10/2021 - kapiabafwh@gmail.com.#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.
Re: Crear pdf y abrirlo con HTMLVIEW
Posted: Sat Oct 16, 2021 7:01 pm
by Ramón J.
Muchas gracias, João. Perdona el malentendido.
Saludos