Gecko:Printing API: Difference between revisions
Jump to navigation
Jump to search
Tschneider (talk | contribs) (first draft of IDL addition and example) |
Tschneider (talk | contribs) (known bugs) |
||
| Line 57: | Line 57: | ||
Window implements Printing; | Window implements Printing; | ||
== Bugs == | |||
* https://bugzilla.mozilla.org/show_bug.cgi?id=1209273 | |||
* https://bugzilla.mozilla.org/show_bug.cgi?id=132035 | |||
Revision as of 15:17, 5 January 2016
Scope
Purpose of this document is to define a set of standards and API's to give web developers more control over printing output.
Example
window.startPrintJob(function (state) {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
if (!state.isPreview) {
canvas.width *= 5;
canvas.height *= 5;
ctx.scale(5, 5);
}
switch (state.currentPage) {
case 1:
ctx.drawText(0, 0, state.title);
break;
case 2:
case 3:
ctx.drawText(0, 0, "Page " + state.currentPage + " of " + state.totalPages);
break;
default:
return Promise.reject(Error("Invalid page number"));
}
return Promise.resolve(canvas);
}, 3, "Printing Example")
.then(function () {
console.log('Printing done');
}, function () {
console.error('Printing failed');
});
IDL addition
interface PrintPageHandler {
Promise getPageElement(PrintState state);
}
interface PrintState {
readonly attribute double totalPages;
readonly attribute DOMString title;
readonly attribute double currentPage;
readonly boolean isPreview: Boolean;
}
dictionary PrintOptions {
double totalPages = 1;
DOMString title = "";
...
};
interface Printing {
Promise startPrintJob(PrintPageHandler handler,
optional (unrestricted double or PrintOptions) options);
};
Window implements Printing;