Hi,

I try to print a document to a ps file and to convert it into jpeg by
the 'convert' command. But I found 'convert' was run before the ps
file became available. I implemented
nsIWebProgressListener#onStateChange and waited until the STATE_STOP
flag was set, but it did not work. Is there a way to be notified when
the print is complete?


    var ifreq =
 
_content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
    var webBrowserPrint =
    ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);

    var printService = Components.classes['@mozilla.org/gfx/
printsettings-service;1']
    .getService(Components.interfaces.nsIPrintOptions);

    var printSettings = printService.CreatePrintSettings();
    printSettings.toFileName        = this.tmpFile;
    printSettings.printToFile       = true;
    printSettings.printSilent       = true;

    ...

    printSettings.showPrintProgress = false;

    this.printCallback.init(this);
    try {
        webBrowserPrint.print(printSettings, this.printCallback);
    } catch (e) {}

// implements nsIWebProgressListener
printCallback: {
    pobj: null,
    init: function (pobj) {
        this.pobj = pobj;
    },
    onLocationChange: function () {},
    onProgressChange: function () {},
    onSecurityChange: function () {},
    onStatusChange: function () {},
    onStateChange: function (aWebProgress, aRequest, aStateFlags,
aStatus) {
        const nsIWebProgressListener =
Components.interfaces.nsIWebProgressListener;
        if ((aStateFlags & nsIWebProgressListener.STATE_STOP)
            && (aStateFlags & nsIWebProgressListener.STATE_IS_DOCUMENT)) {

            // do postprocess when the print is complete
            this.pobj.printPostProcess();
        }
    }
},

// convert ps into jpg
printPostProcess: function () {
    var cvtF = Components.classes["@mozilla.org/file/local;1"]
        .createInstance(Components.interfaces.nsILocalFile);
    cvtF.initWithPath("/usr/bin/convert");
    var myProcess = Components.classes["@mozilla.org/process/util;1"]
        .getService(Components.interfaces.nsIProcess);
    myProcess.init (cvtF);
    var args = [this.tmpFile, "/tmp/output.jpg"];
    myProcess.run(true, args, args.length);
}


Thanks in advance.

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to