PDF export for Javascript-generated content

Is this really a problem? I don’t think so.

Proposal 3: Use the browser’s Print function

Another proposal is to use the browser’s native print function. The flow would be like this:

  • The user choose “Export” from the more actions menu and then “Export as PDF” from the modal which open the “PDF Export Options” page.
  • The user fills the PDF options and clicks on “Export”
  • At this point some JavaScript code kicks in and:
    • adds a loading animation
    • computes the print URL based on the PDF options
    • injects a hidden iframe into the current page pointing it to the print URL
    • waits for the iframe to load and also for the JavaScript within the iframe to be ready (see Proposal 1)
    • removes the loading animation
    • calls iframe.contentWindow.print()
    • the user is free to either download the PDF or send it to a printer

The service behind the print URL should return HTML matching the print options. It should be able to:

  • aggregate child pages (or the pages specified in the URL query string)
  • generate a global ToC (based on the aggregated pages)
  • replace links with anchors when the target page is included in the print

The problem with link URL displayed after the link label remains but we could, at worse, if we can’t find an alternative, drop the link.