kc-print
The best way to print kc cli presentations to PDF.
Why this repo exists
The kc-cli uses Reveal.js and we wanted to export our slick presentations to PDF as handouts. There are a couple of options to do this:
-
Append
?print-pdf
to the address bar, then print. In the print screen, Chrome offers a "Save as PDF" destination.This option is easy to accomplish, but slides do not come out well. At all. Slides overlap, styling disappears, fonts gets mangled, no corporate design.
-
Use an external PDF printer, like Decktape. This export shows the slides as they are, which is great.
Decktape unfortunately has a dependency called HummusJS, a PDF library that requires Visual Studio C++ compilers to be installed on the machine.
-
Get creative. For example, one could grab Puppeteer, create screenshots of every slide and use a PDF library like PDFKit to generate a PDF.
With this, the PDF looks exactly how we want it and we don't have any pesky dependencies that rely on C++ compilers, so it works everywhere. But, because we're placing lots of screenshots in a PDF, the PDF size increases dramatically (> 100MB). Also, the PDF cannot be searched for text.
Initially, we executed the last option. But searchability was too important to simply discard.
So we went back to the drawing board and decided to combine Decktape with a bit of customization. Decktape exports the presentation to one big PDF where every slide is a page and we transform that into a PDF that complies with our corporate design. This way, we get a PDF that looks exactly how we want it, it's small in size and it's searchable. Yay!
Unfortunately, because of the reliance on C++ compilers, this solution does not work on all machines. Specially Windows machines that do not have Visual Studio installed. During the installation of the npm package, it will crash. This is why this is in a separate repo. The kc cli installation should not fail because of some PDF printer. People have presentations or courses to give.
Installation
As mentioned above, the installation phase is where it will crash if your machine is not equipped with the right stuff. See Possible solutions for help.
You can install this package globally and locally. If you've installed the kc cli globally, install kc print globally as well. If you've installed the kc cli locally, install kc print locally.
If, during the installation, the console prints out lots of .cpp
and .c
files, along with the occasional yellow warning, then you're on the right path.
Global
npm install --global @infosupport/kc-print # Windows
npm install --global @infosupport/kc-print --unsafe-perm=true # Linux
Local
npm install @infosupport/kc-print # Windows
npm install @infosupport/kc-print --unsafe-perm=true # Linux
Usage
This will export your slides to PDF using Decktape and Hummus. First, Decktape reads all the presentation slides and uses Hummus to generate a PDF where every page is a slide. With a bit of custom code, this PDF is transformed into a PDF that fits our corporate design.
First, use the kc cli to serve your presentation (kc serve
). Then run kc print
.
option | description |
---|---|
kc print |
print presentation to pdf using default url (http://localhost:15000) and the folder name as filename |
kc print --url [url] |
use specified url and the folder name as filename |
kc print --url [url] --output [filename] |
use specified url and filename |
Possible solutions
Solutions that are 99.9% guaranteed to work
- Use Linux, like Ubuntu. These problems seem to only occur on Windows. Booting up a Linux VM with Hyper-V is quite easy, check out "Hyper-V Quick Create".
- Install Visual Studio. I know. That's a lot.
The less-than-successful solutions
-
Install windows-build-tools. This can take several hours. Not kidding.
npm install --global windows-build-tools --production
If, after installing
windows-build-tools
, you get this error:MSBUILD : error MSB4132: The tools version "2.0" is unrecognized. Available tools versions are "4.0"
Check this issue for possible fixes, like:
open up a new cmd as administrator and run this command:
npm install --global --production windows-build-tools
then
npm config set msvs_version 2015 --global
close all instances of shell/cmd, reopen a cmd (regular this time, non-administrator) return to your directory where you are trying to run npm install and run it again
-
Ask a colleague to export the PDF for you. Hopefully
kc print
will work on his machine.
Known issues
- Some fonts, especially the font for the code blocks, don't render as they're shown on-screen. See this issue.