Forum Discussion
DemoUser_1
Jun 24, 2024Copper Contributor
How to open Document print screen on same page in SPFx framework
Currently opens in new Tab..Not working proper in same Tab..
Need to open print option in desktop teams app as well
printDocument = async (printDocUrl) => {
try {
if (this.state.signedDocumentURL === "") {
throw new Error("Document not found");
}
const width = 1080;
const height = 720;
// Calculate the left and top positions for centering the window
const left = (window.screen.width - width) / 2;
const top = (window.screen.height - height) / 2;
// Open the window with calculated positions
const newWindow = window.open(
printDocUrl,
"_blank",
`height=${height},width=${width},left=${left},top=${top}`
);
// const newWindow = window.open(this.state.signedDocumentURL, '_blank', `height=${height},width=${width},left=${left},top=${top}`);
if (!newWindow) {
throw new Error("Failed to open print window");
}
// setTimeout(() => {
// newWindow.print();
// }, 3000);
// setTimeout(() => {
// newWindow.close();
// }, 6000); // Close after 6 seconds
} catch (error) {
console.error(error);
Swal.fire({
title: error.message,
icon: "error",
timer: 2000,
timerProgressBar: true,
showConfirmButton: false,
});
}
};
No RepliesBe the first to reply