Page 1 of 1
Cancel Print Event
Posted: Fri Mar 21, 2025 8:59 am
by Samuel
Hi, I am creating a java extension for openoffice and I am able to successfully trigger print event through code but i am not able to cancel the print event from my dialog.I referred this link
https://www.openoffice.org/api/docs/com ... ntJob.html. and here there is a method called cancelJob .I call that when my response was no but its not cancelling the print. Please help me find a solution
Re: How to cancel Print Event?
Posted: Fri Mar 21, 2025 10:15 am
by JeJe
Have you installed the listener to investigate what's happening using that?
Re: How to cancel Print Event?
Posted: Fri Mar 21, 2025 10:31 am
by Samuel
yes on installing the listener i call this msg box on Ctrl+P.
Code: Select all
XMessageBox xMessageBox = xMsgBoxFactory.createMessageBox(
(XWindowPeer) parentWindow,
com.sun.star.awt.MessageBoxType.QUERYBOX,
com.sun.star.awt.MessageBoxButtons.BUTTONS_YES_NO,
"Print Confirmation",
"Do you want to proceed with printing?");
short result = xMessageBox.execute();
// Check user response
if (result == MessageBoxResults.YES) {
logEvent("User chose to print the document.");
return true;
} else {
logEvent("User chose to cancel printing.");
return false;
}
which if they click NO,i did this;
Code: Select all
boolean proceedWithPrint = askForPrintConfirmation();
if (!proceedWithPrint) {
try {
// Cancel the print job
XPrintJob printJob = UnoRuntime.queryInterface(XPrintJob.class, event.Source);
if (printJob != null) {
printJob.cancelJob();
logEvent("Printing cancelled by the user.");
} else {
logEvent("Could not obtain XPrintJob interface.");
}
} catch (Exception e) {
logEvent("Error canceling print job: " + e.getMessage());
e.printStackTrace();
}