I am trying to save HTML div as pdf in javascript and PHP. I have tried a lot of libraries, but all of them are returning to the pdf-only HTML structure. The page I want to convert to pdf is generated from a database table in which I have put everything for well structure HTML. Now I am at the point where I can serialize all my input data in string like action=saveWorkPermit&text_CLMC_491=1515&date_CLMC_494l495d=2021-12-06&time_CLMC_496l497t=10%3A34&. I also can get them in array as {"action": "saveWorkPermit", "text_CLMC_491": "1515" ...}. I have my HTML structure also and then. I am stuck. I do not know how to input in the HTML the values and then get this result HTML and put it in some pdf function. I will really appreciate your answers if you can help me. Here is the Ajax code:
case "GeneratePdf":
var ex = data.details.structure ; // here it is the html
var array = data.details.data; // this is the data as array
for (var key in array) {
var type = key.split("_")[0];
var value = array[key];
if(type == 'check' && value == 'on') {
$("#"+key).prop("checked", true);
} else if (type == 'gr'){
$("input[name="+key+"][value=" + value + "]").prop('checked', true);
} else {
$("[name='"+key+"']").val(value);
}
}
let mywindow = window.open('', 'SAVE', 'height=650,width=900,top=100,left=150');
mywindow.document.write(`<html><head><title>MyPdf</title>`);
mywindow.document.write('</head><body >');
var params2 = $("#AllWP").serialize();
mywindow.document.write(document.getElementById("AllWP").innerHTML); // one more time the html structure
mywindow.document.write(params2); // this is the serialized data
mywindow.document.write(ex); // because of this line it is not working
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.focus();
mywindow.print();
mywindow.close();
break;
This is one of the forms I want to export as pdf:

If there is no way to do that in javascript, I can also get the above data in PHP and loop them there.
The main question is if I have HTML like this :
<div class="row spacer">
<div class="col-sm-2 col-sm-2half ">
<label for="text_CLMC_494l495d">Дата на започване:</label>
</div>
<div class="col-sm-4 ">
<input type="date" id="text_CLMC_494l495d" name="date_CLMC_494l495d" size="0" placeholder="">
</div>
and data like this: ..&text_CLMC_494l495d=1515&..
How can I have this:
<div class="row spacer">
<div class="col-sm-2 col-sm-2half ">
<label for="text_CLMC_494l495d">Дата на започване:</label>
</div>
<div class="col-sm-4 ">
<input type="text" id="text_CLMC_494l495d" name="text_CLMC_494l495d" size="0" placeholder="">1515</input>
</div>
Here it is what I have - the first one is the html, the second one are the values with its HTML names:

Here it is the text from data picture:
<div id="allwpunic">
<input type="hidden" value="saveWorkPermit" name="action" id="action">
<div class="clmc_header">
<div class="row spacer">
<div class="col-sm-2 ">
<img src="/assets/images/logotita.png" alt="logo_img">
</div>
<div class="col-sm-7 ">
<h1>ПЛАН ЗА КРИТИЧНО ПОВДИГАНЕ ОТ МОБИЛЕН КРАН №</h1>
</div>
<div class="col-sm-1 nopadding">
<h4>ОР No:</h4>
</div><div class="col-sm-2 ">
<input type="text" style="max-width:100%;" id="text_CLMC_491" name="text_CLMC_491" size="10" placeholder="">
</div></div><div class="row spacer">
<div class="col-sm-2 col-sm-2half ">
<label for="date_CLMC_494l495d">Дата на започване:</label>
</div>
<div class="col-sm-4 ">
<input type="date" id="date_CLMC_494l495d" name="date_CLMC_494l495d" size="0" placeholder="">
</div>
<div class="col-sm-1 nopadding">
<label for="time_CLMC_496l497t">От:</label>
</div>
<div class="col-sm-2 ">
<input type="time" id="time_CLMC_496l497t" name="time_CLMC_496l497t" size="0" placeholder="">
</div><div class="col-sm-1 nopadding">
<label for="time_CLMC_498l499t">До:</label>
</div>
<div class="col-sm-2 ">
<input type="time" id="time_CLMC_498l499t" name="time_CLMC_498l499t" size="0" placeholder="">
</div>
</div>
<div class="row spacer">
<div class="col-sm-3 ">
<label for="text_CLMC_502l503t">Отдел/ място, където ще се работи:</label>
</div>
<div class="col-sm-9 ">
<input type="text" style="max-width:100%;" id="text_CLMC_502l503t" name="text_CLMC_502l503t" size="85" placeholder="">
</div>
</div>
<div class="row spacer">
<div class="col-sm-3 ">
<label for="text_CLMC_506l507t">Кранът е осигурен от:</label>
</div>
<div class="col-sm-9 ">
<input type="text" style="max-width:100%;" id="text_CLMC_506l507t" name="text_CLMC_506l507t" size="85" placeholder="">
</div>
</div>
<div class="row spacer">
<div class="col-sm-3 ">
<label for="text_CLMC_510l511t">Описание на работата:</label>
</div>
<div class="col-sm-9 ">
<input type="text" style="max-width:100%;" id="text_CLMC_510l511t" name="text_CLMC_510l511t" size="85" placeholder="">
</div>
</div>
</div>
action: "saveWorkPermit"
date_CLMC_494l495d: "2021-12-08"
language: "en"
text_CLMC_491: "49846498"
text_CLMC_502l503t: "Някъде"
text_CLMC_506l507t: "Нещо си"
text_CLMC_510l511t: "Тестов пример"
time_CLMC_496l497t: "10:01"
time_CLMC_498l499t: "02:56"