djplaner / Content-Interface-Tweak

Improves both the task of creating content for Blackboard Learn, and reading that content.
https://djplaner.github.io/Content-Interface-Tweak/
GNU General Public License v3.0
0 stars 0 forks source link

Explore JavaScript methods for producing PDF of Content Interface (again) #41

Closed djplaner closed 3 years ago

djplaner commented 3 years ago

Maybe even a web component that can be easily added?

jsPDF

As per StackOverflow in theory it's possible with jsPDF and including

BUT It you lose all the style information.

jsPDF and html2canvas

html2canvas apparently uses the browser to generate a canvas image. Possibly keeping the styles, but probably generating a PDF with images, not text?

PDFReactor

An API based service. Have to pay to get a real licence. But seems very full features.

PDFMake which is based on PDFKit

PDFKit is very low level for PDF generation - Browser or server (node)

PDFMake takes a doc definition as JSON array - not as html.

Some early work on HTML to PDF, and someone wrote a html-to-pdf module.

BUT

djplaner commented 3 years ago

Print HTML

StackOverflow post suggestion works

  1. Open new window
  2. Insert HTML from div into there
  3. Add some additional CSS
  4. Print that window "to PDF"

Doing it safely across browser might be the main difficulty.

Do Javascript conversion of HTML

Not only can you add CSS, but you should be able to run Javascript on the HTML from the div to do all the changes currently done in Python.

To do

djplaner commented 3 years ago

General set up tasks

convertLib::processHtml

Takes title and HTML and does the following changes

djplaner commented 3 years ago

Status

Working on style images. They can't be printed because they are background images. Implying that the STYLE_PREPEND stuff doens't need to happen normally, could be moved just to the print stage

djplaner commented 3 years ago

PDF generation

PDFs being generated have links that can't be clicked on.

Apparently printing to PDF (printer) is the same as printing on a printer. The PDF is flattened, i.e. links are visually displayed, but don't actually work as links. This is from Acrobat.

Appears that Firefox does the same. Chrome generates clickable links, however, styles appear to break.

Formatting for print - a tale of two browsers

Currently code adds a "print" css to the main document, that works in chrome. But not in Firefox.

Remove it and it works in Firefox but not in Chrome

Both screen and print work in Firefox Chrome

But only in the pop-up window. Load that same HTML page into a proper window (the original that works in Firefox) and it all works.

Suggestion Is it having a print css in the original that makes the difference? Yes. Chrome needs the print css in the original. Firefox doesn't. But have it and a screen one in the popup and both are happy.

Advanced features

This page has some details on

And a similar page

djplaner commented 3 years ago

Alternate to image background in CSS

  1. Activity, Reading, FilmWatchOptions etc all use background image CSS to locate and control the size of the relevant icons
  2. But CSS background images don't print (though apparently can force on webkit browsers)

STYLE_PREPEND has to happen for all of these because Mammoth can't do it alone. Thus move away from using background images

djplaner commented 3 years ago

Missing film watch options icon

For some reason, Chrome doesn't like displaying the Film Watch Options icon, but it can be iconsisstent.

Fixed. Problem with my code

Kitchen sink test - note icon is huge

Appears fine elsewhere. Fixed my code.

djplaner commented 3 years ago

Adding course code and title to the header

djplaner commented 3 years ago

=== COM14 issues

Week 13 of COM14 isn't printing?? Forms embed?

Week 1 embed stream isn't being converted

Also some issues with activity icons