Best practise for print or form or convert it to PDF

Hi,

are there some best practise solutions or examples available to print out a form (include field values) or (would be better) to convert it to a PDF.

tks

Hi

unfortunately we do not have ready solution

Hello,

I know it’s a little late in the game but if you’re still wanting to just do a simple print-job of a form, you could get the ‘div’ element where the form object is appended and adjust the height before calling the ‘.print()’ method. For example, you could do this:

var printArea = document.getElementById('<id of div where the form resides>'); var originalHeight = printArea.style.height; printArea.style.height = printArea.height+'px' // I'm using 1300px for me var printContent = printArea.contentWindow; printContent.print(); printArea.style.height = originalHeight; // Set it back to the original height

For me, I’m not on the actual form to print it off. I actually have the form in another document when I call the ‘.print()’ method. So I have an empty ‘div’ element on the page and when I call my method to print, I append an ‘iframe’ element with the source to my form document and adjust the height of that div using the above code.

I hope this helps a little. I don’t know of a way to convert it to PDF without using an external api/library (such as a PHP library like fpdf) but hopefully you’ll find a solution soon.

Hello,

i found this solution: printjs.crabbly.com/

It works fine !! But you need a div id to print your form. And thats my problem now. Is it possible to set an div id to the dhtmlxform or to any parent object??

Regards
Stephan

In regards to Stephan’s reply, I took a look at printjs and it’s awesome! I have it working and I figured out how to give a dhtmlx form object an “id”.

So here’s what I did:

// I added these to the header porition

. . . // Then I added a print button to a toolbar and used an "onClick" event to execute this code // The 'cont' property returns the HTML of the form freezeForm.cont.id = "printJob"; // I set the div id to "printJob" printJS("printJob", "html"); // Then I call the printjs library

I hope this helps!