-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add printing support #154
Comments
Goals
The big to-do item is to figure out what existing web APIs let us do. I've heard there's some kind of "onprint" event or something, but I don't know what we can do with it. After that, we can make a best-effort implementation with what we have, and then figure out what web APIs to add. |
Olly Pettay from Mozilla pointed out that the event we can listen for is "beforepaint". |
Couldn't this be solved with a stylesheet, which just removes everything but the page canvases? |
Not really. We don't keep canvases for all pages around all the time because that would consume a huge amount of memory. We also need to rerender the canvases at output resolution, not screen resolution. SVG would make that a non-issue, but we would still have a problem trying to print >1000-page PDFs. |
Using something like Internet Printing Protocol might help (?) If the "printer" supports PDF we can send it as is, otherwise PNGs can be generated and sent to the server. |
Just printing the canvas isn't enough by far. The resolution of the rendered canvas compared to the resolution (200dpi?) for printing is far to low. Either a really bit canvas is rendered to solve this issue, or we come up with some proper Web Print API, which I'm voting for. I can imagine a lot of applications like MS's Office 365 or Google Docs that like to have 100% perfect printing support without any workaround. |
YES! A web printing API would be absolutely fantastic for many applications. Right now, web apps have virtually no control over the print output that they produce with browsers adding ugly headers and footers by default, and difficulty controlling print layout, page breaks, etc. A low level web print API that just let developers output raw graphics commands with an API similar to canvas, but with additional APIs for controlling page breaks would be awesome here. |
Oh, and I think a potential WebPrint API should be a little higher level than just "send postscript commands to the printer". :P A nice API like canvas has, perhaps just extending the canvas API to support printing, would be pretty awesome. For example, a potential API that I just made up would be:
That is just one idea, but let's get the ball rolling on this one. It would be awesome for the web! :) |
I've analysed the current state of printing. See here:
The comment by Eugene expresses very well what I was concerned about and I think he is right. For most use cases, a not canvas-based print solution for the web would be better, as styling a page/table/any content using HTML&CSS is way easier then implementing all the drawing, text breaks etc. in JS, although the browser knows way better how to do it. (Also, note that the +1 comes from Paul Irish.) A WebPrintAPI as I have it in my mind fits the needs for PDF.JS, but I don't think there is much sense in implementing & standalize an API that is not useful for other use then PDF.JS. Therefore, I think I take a closer look at CSS3 Paged Media and try to figure out what subset needs to get implemented to fit the requirements for PDF.JS. Also, once that's figured out, I want to ping Roc and discuss what he thinks about it/how to implement the missing stuff. Not using the WebPrintAPI idea implies that the rendering needs to be done using SVG to get good looking printout. Right now I got the first page of the tracemonkey paper working on a very simple SVG backend for PDF.JS and the performance is not that much worth then in canvas. Does that sounds reasonable? \cc @brendandahl, @arturadib, @wfwalker |
I support the push for better printing support in the browser, even independent of its effect on the progress of printing support in pdf.js. So I'm all for trying that route. |
I'll say what I said on Google Plus here just so everyone sees it: CSS and HTML are good high level tools, but honestly I think we need both low level APIs and high level ones so we can properly fill both use cases. I would love a WebPrint API that allowed me direct, pixel perfect control over my printed output rather than leaving that up to the browser. CSS will be good enough for most people, but there are some use cases for a lower level API as well. PDF.js is one of them. Honestly, the real reason why I wrote PDFKit (my PDF document generator), is so that I could generate nice looking printed documents from an app I was working on. I originally tried doing things with CSS paged media and HTML but had all sorts of problems, namely getting things to lay out properly and issues like not being able to programmatically hide and show the headers and footers with the webpage URL in them that browsers put there, etc. So I wrote PDFKit, and generate the documents server side. The user then has to download the PDF and print it from there. This works but it is very cumbersome for the user, and for the developer. I don't think there is any problem with supporting both low level and high level APIs in the browser in general. Most people will use the high level one, but for certain use cases low level APIs are really useful when we want to do really custom things that the standard hadn't thought of yet. Anyway, just my two cents! |
Based on the feedback and some other discussions I've started to scratch what a WebPrintAPI could look like. See this post:
Future discussion about the API will happen on the mailing list. |
Opened bug 745025: https://bugzilla.mozilla.org/show_bug.cgi?id=745025 Attached is a first iteration of the |
Printing support has been added - Should this be closed? |
No description provided.
The text was updated successfully, but these errors were encountered: