Jump to content

How to convert a HTML in your application to PDF?


jrp

Recommended Posts

8 hours ago, jrp said:

Hello,

In my application, when the user click "Show Report" then the application prepare a HTML file and display it in a new tab. How to convert it to a PDF file so the user can download it?

Thanks

try with this:

https://qawithexperts.com/article/javascript/easy-way-to-convert-html-to-pdf-using-javascript/335

or https://stackoverflow.com/questions/18191893/generate-pdf-from-html-in-div-using-javascript

  • Like 1
Link to comment
Share on other sites

All our work is done server side - so it's just pretty standard Delphi stuff, no Javscript etc required. 

In one application we have tablets out in the field returning HTML data to the server. When the UNIGUI user browses the list of returned files we check to see if the same file name exists but with a PDF extension rather than HTM - if not we simply call wkhtmltopdf.exe from a procedure in mainmodule in a hidden window  with param1 as source html and param2 as the required PDF. Once the PDF does exist we display/print as required.

you could use any Delphi function that runs an external exe (ShellExecute, ShellExecureEx, WinExec, CreateProcess....) 

This approach works fine for us, it's easy to implement and allows additional processing if the called process is actually a batch file with a list of other things to do in it, rather than just converting to a PDF.

 

Cheers

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
Em 07/09/2022 às 11:18, Harry Rogers disse:

Todo o nosso trabalho é feito do lado do servidor - por isso é apenas coisas Delphi bastante padrão, sem Javscript etc necessário.

Em um aplicativo, temos tablets em campo retornando dados HTML para o servidor. Quando o usuário UNIGUI navega na lista de arquivos retornados, verificamos se o mesmo nome de arquivo existe, mas com uma extensão PDF em vez de HTM - se não, simplesmente chamamos wkhtmltopdf.exe de um procedimento no mainmodule em uma janela oculta com param1 como html de origem e param2 como o PDF necessário. Uma vez que o PDF existe, exibimos/imprimimos conforme necessário.

você pode usar qualquer função Delphi que execute um exe externo (ShellExecute, ShellExecureEx, WinExec, CreateProcess....)

Essa abordagem funciona bem para nós, é fácil de implementar e permite processamento adicional se o processo chamado for realmente um arquivo em lote com uma lista de outras coisas para fazer nele, em vez de apenas converter para um PDF.

 

Obrigada

Hello, can you post an example of how to use it?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...