Adolfo
Posts: 900 Joined: Tue Oct 11, 2005 11:57 am
Location: Chile
Contact:
Post
by Adolfo » Thu Dec 18, 2025 1:52 pm
Saludos fivewinners.
Necesito en una aplicación para poder convertir desde adentro de mi sistema algunos archivos HTML a PDF
El usuario los selecciona y los debe convertir en PDF dentro de una directorio que el sistema les entrega.
Conocen algún convertidor en modo consola que yo pueda llamarlo desde adentro del sistema y que me haga el trabajo. Obviamente por control interno no puedo utilizar un convertidor en linea.
Cualquier ayuda sirve.
Saludos desde Chile
Ji,ji,ji... buena la cosa... "all you need is code"
http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Horizon
Posts: 1388 Joined: Fri May 23, 2008 1:33 pm
Post
by Horizon » Thu Dec 18, 2025 3:40 pm
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.06
karinha
Posts: 8720 Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:
Post
by karinha » Thu Dec 18, 2025 5:48 pm
USE: wkhtmltopdf.exe
Code: Select all | Expand
// C:\FWH\SAMPLES\HTML2PDF.PRG - [email protected] - https://wkhtmltopdf.org/
// USE: wkhtmltopdf.exe
#include 'fivewin.ch'
FUNCTION Main()
LOCAL cHtmlFile, cPdfFile, cWkHtmlToPdfPath, cCommand
cHtmlFile := "C:\TEMP\CHAT.html" // origem -> ex: C\TEMP
cPdfFile := ".\OUTPUT.pdf" // destino -> ex: C:\FWH\SAMPLES
IF FILE( cPdfFile )
FErase( cPdfFile )
ENDIF
IF FILE( cPdfFile )
? [AQUI, PROBLEMAS EN EL *.PDF]
QUIT
RETURN NIL
ENDIF
// https://wkhtmltopdf.org/ -> o de otro sitio mejor. a Tu gosto personal.
// C:\wkhtml\bin -> mi ejemplo en testes perfectos.
// cWkHtmlToPdfPath := "C:\Path\To\wkhtmltopdf.exe" // Adjust path as necessary
cWkHtmlToPdfPath := "C:\wkhtml\bin\wkhtmltopdf.exe"
// Command to convert the HTML file to a PDF file
cCommand := cWkHtmlToPdfPath + " " + cHtmlFile + " " + cPdfFile
// Execute the command (uses 'RUN' for simplicity; other functions like HB_RUN might be better for capturing output/errors)
// RUN ( cCommand )
MYRUN ( cCommand )
// Check if the file was created and handle errors
IF FILE( cPdfFile ) // Si ejiste...
// Success: proceed with opening or managing the PDF file
MsgInfo( "PDF generated successfully!" )
cCommand := "START " +cPdfFile
// RUN ( cCommand )
MYRUN ( cCommand ) // ADOBE ACROBAT
ELSE
// Error handling: might need to check command line exit code for detailed errors
MsgStop( "Failed to generate PDF. Check if wkhtmltopdf is installed and accessible." )
ENDIF
RETURN NIL
FUNCTION MYRUN( cComando )
Local oShell, RET, lOk:=.T.
TRY
#IFDEF __XHARBOUR__
oShell := CreateObject( "WScript.Shell" )
#ELSE
oShell := Win_OleCreateObject( "WScript.Shell" )
#ENDIF
CATCH
TRY
#IFDEF __XHARBOUR__
oShell := CreateObject( "WScript.Shell" )
#ELSE
oShell := Win_OleCreateObject( "WScript.Shell" )
#ENDIF
CATCH
lOk:=.F.
END
END
IF lOk
TRY
//.F. = Nao espera a aplicacao fechar, .T. espera.
oShell:Run( "%comspec% /c " + cComando, 0, .T. )
CATCH
lOk:=.F.
END
oShell := NIL
ENDIF
//-- RET := oShell:Run( "%comspec% /c " + cComando, 0) //, .T. )
RETURN( lOk )
// FIN / END [email protected]
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Adolfo
Posts: 900 Joined: Tue Oct 11, 2005 11:57 am
Location: Chile
Contact:
Post
by Adolfo » Thu Dec 18, 2025 7:32 pm
Muchas Gracias....
Lo Reviso y les comento.
Ji,ji,ji... buena la cosa... "all you need is code"
http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650