1
0
forked from poc/pds

Package for export pdf

This commit is contained in:
dhanabalan
2025-04-28 00:11:34 +05:30
parent a8f717d99a
commit e328569cc1
5 changed files with 640 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
.preview-table {
background: white;
color: black;
width: 100%;
border-collapse: collapse;
border-spacing: 0;
}
.preview-table td,
.preview-table th {
border-color: #ededed;
border-style: solid;
border-width: 1px;
font-size: 13px;
line-height: 2;
overflow: hidden;
padding-left: 6px;
word-break: normal;
}
.preview-table th {
font-weight: normal;
}
.preview-table-wrapper {
max-height: min(500px, 80vh);
overflow-y: auto;
}

View File

@@ -0,0 +1,36 @@
function onElementRemoved(element, callback) {
new MutationObserver(function (mutations) {
if (!document.body.contains(element)) {
callback();
this.disconnect();
}
}).observe(element.parentElement, { childList: true });
}
function triggerInputEvent(statePath, value) {
let input = document.getElementById(statePath);
input.value = value;
input.dispatchEvent(new Event('input', { bubbles: true }));
}
function printHTML(html, statePath, uniqueActionId) {
let iframe = document.createElement("iframe");
let random = Math.floor(Math.random() * 99999);
iframe.id = `print-${random}`;
iframe.srcdoc = html;
document.body.append(iframe);
onElementRemoved(iframe, () => triggerInputEvent(statePath, `afterprint-${uniqueActionId}`));
iframe.contentWindow.onafterprint = () => document.getElementById(iframe.id).remove();
iframe.contentWindow.onload = () => iframe.contentWindow.print();
}
window.triggerInputEvent = triggerInputEvent;
window.printHTML = printHTML;