Html2pdf

Author: roger.wallin@abilita.fi (rogerw)

Hi,  Does anyone have a way to convert an Uniface-string containing html to a Uniface-string containing a pdf-file (raw or base64) without writing to a temporary html-file and pdf-file? Writing to temporary files I can use eg. spawn "#wkhtmltopdf.exe %%htmlFile%%% %%pdfFile%%%" Then I can use fileload/raw to get the pdf into an variable.  But in this case, due to security restrictions, it would be better not writing any temporary files, although they can be deleted afterwards.   There is a wkhtmltopdf C-library that probably contains the needed functions, but I'll see if I find some easier way before starting to compile something containing the wkhtmltopdf library. There is quite a long time since I made som C-routines/C++routines for Uniface..... The goal is to send the pdf-file (string), base64 coded, into a web-service.  Regards RogerW.

7 Comments

  1. Thanks for the answers, if this would be of really high priority for us, I would continue on Ulis advice or use some C-library. But now the pipe-solution is probably the one that could solve it fairly fast and acceptable. Searching for "pipe wkhtmltopdf" gave some interesting examples. I have to test this a bit with Uniface and encryption/decryption before saying any more.... Any advice still appreciated. Regards RogerW.

    echo ^<h3^>magical ponies^</h3^> | "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" - test.pdf
     
    echo ^<h3^>magical ponies^</h3^> > temp.txt "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" - test.pdf < temp.txt
    
     

    Without escaping.

    echo | set /p="<h3>Magical ponies</h3>" | wkhtmltopdf - test.pdf

     

    Using PowerShell
    $html = "<h1>Magical Ponies</h1><p>Once upon a time in Horseland, there was a band of miniat ure creatures..." $html | .\wkhtmltopdf.exe - C:\temp\test.pdf

    Author: rogerw (roger.wallin@abilita.fi)
  2. Hi, This issue has been postponed. However it looks that we have already done this in .net and used some commercial libraries for the html to pdf conversion. As those programs are installed as services and they aren't always available where I need them, I'll probably use "Unmanaged exports" to make them available from a .net dll. This is something that we have used successfully before. How to use a .net dll exporting functions to native applications eg. to Uniface, is something that could be mentioned in the Uniface manual, isnt it? Regards RogerW.


    Author: rogerw (roger.wallin@abilita.fi)
  3. Thanks Ingo, that would make it a bit more secure. Probably there is a small risk that the pipe is aborted at the wrong time and leaving eg. the pdf-file unencrypted on the disk. Or should the pipe handle that? However I'm still leaving this question active, waiting for other solutions. My program is doing this GetXml  (eg. componenttostruct, structtoxml or however your xml is built)   activate "USYSXSLT".XMLTRANSFORM(..........) (Transform the XML to HTML by using a xslt-file)  HTML2PDF  (Transform the html to pdf. This is the stage I should improve). I've understood that there are people building report-engines in similar ways, but we are still using this in a very restricted way, so I'll probably not buy some expensive report-engine. Regards RogerW. 


    Author: rogerw (roger.wallin@abilita.fi)
  4. Hi Have a look to Apache FOP You can get PDF files via command line or calling your own server http://server:8080/fop/fop?xml=data.xml&xsl=template.xsl The result is the PDF. It joins data with a WYSIWYG report definition and gets an XSL-FO which is, in fact, your printed report that can be rendered as PDF. At basic level it still is using files :-( but I think is possible to modify servlet to be fed by streams instead of files. And as it is an standard way of reporting, maybe someone has already done it.   Regards


    Author: luis.vila (luis.vila@uniface.es)
  5. rogerw said Thanks Ingo, that would make it a bit more secure. Probably there is a small risk that the pipe is aborted at the wrong time and leaving eg. the pdf-file unencrypted on the disk. Or should the pipe handle that?

    Hi Roger Yes, the pipe should encrypt the result of html2pdf and only this encrypted PDF will be on disk. But I dont know, if all this executables are pipe/streaming enabled Smile Ingo


    Author: istiller (i2stiller@gmx.de)
  6. Hi Roger, just a simple combination: under JAVA, there are a lot of libraries to convert HTML to PDF. The following is just to combine Ingos idea of the "pipe", but run all this (decode HTML, generate pdf, encode pdf) inside a simpe (runnable) java JAR. Still it uses external (but encrypted) files, but the complete process is inside only one application. HIH, Uli P.S. In September 2016, Chris Breemer published on uniface.info "javacall" which may allow a complete "in memory" processing.

    The next best thing we can do is provide a generic C signature with a 3GL 
    module that can call more or less arbitrary Java methods. Enter the JAVASIG signature.

    Author: ulrich-merkel (ulrichmerkel@web.de)
  7. Hi Roger Just a thougt, not proofed :) Encrypt the HTML and save this to harddrive Then call a (temporary) batchfile like this (or spawn it) " type {filename of encrypted html} > decrypt.exe - key xyz> wkhtmltopdf.exe > encrypt.exe -key xyz > {filename of encrypted pdf} " Now you can load this file and decrypted it to PDF Okay, the must be an encrypt/decrypt executable which works with pipes And wkhtmltopdf mus be pipe enabled Ingo


    Author: istiller (i2stiller@gmx.de)