Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - Programmatically batch print HTML documents

Tags:

javascript

tl;dr I'm looking for a good way of batch printing database-stored HTML documents from javascript

Our users generate rich text content via an open source WYSIWYG javascript-based text editor (CKEditor). The HTML content is saved to our database and can be printed directly from the editor via its inbuilt print functionality (basically just window.print()) . This is great and works perfectly.

Now, we have a need to batch print saved documents and I am looking for workable solutions. There are various options that I can see, but all have large tradeoffs:

  1. User selects documents to print. JS code loops through documents and calls print one-by-one. The issue here is that the user will see a bunch of print dialogs. Which is painful. (Aside: we are using Chrome but I do not have the option of setting it to kiosk mode)

  2. User selects documents to print. JS code combines all of these in a single (hidden) container and they are all printed as one 'document'. These can be fairly big documents with tables, images, etc. I worry about the performance involved here as we could be adding a significant amount to the DOM.

  3. Similar to #2 above, but at some point the documents are converted and saved to a single PDF. This would be OK, but there don't seem to be many good/cost-effective options for converting HTML to PDF.

  4. Generate some kind of a report that can handle HTML content. I took a look at SQL Server reporting services but it supports a very limited set of HTML tags and CSS properties.

Is there a better way to batch print HTML content from javascript? Any help is very much appreciated!

Edit As per @Paul, I need to clarify a few points:

The content is that which is created in your standard online text editor. In my case:

  • No iframes
  • No animations
  • No dynamic content

Now, were I to print straight from the editor a print stylesheet would be applied, so this may complicate things a bit.

like image 407
JP. Avatar asked Feb 16 '17 18:02

JP.


1 Answers

Since content could be potentially large and consume a lot of memory I would do this on server side. Select docs on client and request server to render those to PDFs e.g. utilising PhantomJS. This would then allow you to even use mobile clients to fetch PDFs.

like image 50
Janne Avatar answered Oct 22 '22 16:10

Janne