Cancel Print Event

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
Samuel
Posts: 9
Joined: Fri Mar 21, 2025 8:51 am

Cancel Print Event

Post 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
OpenOffice 4.1.15 on Windows11
JeJe
Volunteer
Posts: 3064
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to cancel Print Event?

Post by JeJe »

Have you installed the listener to investigate what's happening using that?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Samuel
Posts: 9
Joined: Fri Mar 21, 2025 8:51 am

Re: How to cancel Print Event?

Post 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();
                }
OpenOffice 4.1.15 on Windows11
Post Reply