update
This commit is contained in:
@@ -594,18 +594,17 @@ export class DeDocumentViewer extends DeesElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handlePrint(): Promise<void> {
|
private async handlePrint(): Promise<void> {
|
||||||
// Create a print-specific container
|
// Create a print-specific container - hidden on screen, visible only in print
|
||||||
const printContainer = document.createElement("div");
|
const printContainer = document.createElement("div");
|
||||||
printContainer.className = "dedocument-print-container";
|
printContainer.className = "dedocument-print-container";
|
||||||
printContainer.style.cssText = `
|
printContainer.style.cssText = `
|
||||||
position: fixed;
|
position: absolute;
|
||||||
|
left: -9999px;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
width: 210mm;
|
||||||
width: 100%;
|
height: auto;
|
||||||
height: 100%;
|
visibility: hidden;
|
||||||
z-index: 999999;
|
pointer-events: none;
|
||||||
background: white;
|
|
||||||
overflow: visible;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Create a document element in print mode
|
// Create a document element in print mode
|
||||||
@@ -618,7 +617,7 @@ export class DeDocumentViewer extends DeesElement {
|
|||||||
printContainer.appendChild(printDoc);
|
printContainer.appendChild(printDoc);
|
||||||
document.body.appendChild(printContainer);
|
document.body.appendChild(printContainer);
|
||||||
|
|
||||||
// Add print styles
|
// Add print styles - hide everything except print container during print
|
||||||
const printStyles = document.createElement("style");
|
const printStyles = document.createElement("style");
|
||||||
printStyles.id = "dedocument-print-styles";
|
printStyles.id = "dedocument-print-styles";
|
||||||
printStyles.textContent = `
|
printStyles.textContent = `
|
||||||
@@ -628,8 +627,11 @@ export class DeDocumentViewer extends DeesElement {
|
|||||||
}
|
}
|
||||||
.dedocument-print-container {
|
.dedocument-print-container {
|
||||||
position: static !important;
|
position: static !important;
|
||||||
|
left: auto !important;
|
||||||
width: auto !important;
|
width: auto !important;
|
||||||
height: auto !important;
|
height: auto !important;
|
||||||
|
visibility: visible !important;
|
||||||
|
pointer-events: auto !important;
|
||||||
}
|
}
|
||||||
dedocument-dedocument {
|
dedocument-dedocument {
|
||||||
display: block !important;
|
display: block !important;
|
||||||
@@ -655,24 +657,26 @@ export class DeDocumentViewer extends DeesElement {
|
|||||||
// Wait for the document to render
|
// Wait for the document to render
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
|
|
||||||
// Trigger print
|
// Cleanup function
|
||||||
window.print();
|
|
||||||
|
|
||||||
// Clean up after print dialog closes
|
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
printContainer.remove();
|
if (document.body.contains(printContainer)) {
|
||||||
printStyles.remove();
|
printContainer.remove();
|
||||||
|
}
|
||||||
|
if (document.head.contains(printStyles)) {
|
||||||
|
printStyles.remove();
|
||||||
|
}
|
||||||
window.removeEventListener("afterprint", cleanup);
|
window.removeEventListener("afterprint", cleanup);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Listen for print dialog close
|
||||||
window.addEventListener("afterprint", cleanup);
|
window.addEventListener("afterprint", cleanup);
|
||||||
|
|
||||||
// Fallback cleanup after a delay (in case afterprint doesn't fire)
|
// Trigger print
|
||||||
setTimeout(() => {
|
window.print();
|
||||||
if (document.body.contains(printContainer)) {
|
|
||||||
cleanup();
|
// Fallback: also clean up immediately after print() returns
|
||||||
}
|
// (some browsers return from print() after dialog closes)
|
||||||
}, 60000);
|
setTimeout(cleanup, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private calculateFitWidth(): void {
|
private calculateFitWidth(): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user