CERN Accelerating science

Convert to PDF hiding the code

Hi everybody,

I am trying to export / download the notebook in .pdf hiding the code.

Since I have not found a way of doing so using SWAN’s interface, I have tried following the recommended steps in:

using SWAN’s terminal, but it failed several times and I reached a point were I could not keep going.

Has someone tried this (…and succeeded :slight_smile: )?


Hi Berta,

yeah, I have a notebook which I run via the nbconvert in an acron job, which hides the code in the created web page. To do so, I only have this code in the first cell:

# # Hide the code by default from the web page:
# # (from:
from IPython.display import HTML

function code_toggle() {
 if (code_show){
 } else {
 code_show = !code_show
$( document ).ready(code_toggle);
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the code."></form>

then I run the conversion via:

jupyter nbconvert --execute --to html --ExecutePreprocessor.timeout=180 ./notebookName.ipynb

(You may have to adjust your PYTHONPATH beforehand to find privately installed packages, if needed).

cheers, andreas

Hi Andreas,

Thanks for your answer!

It’s an interesting alternative, but it converts to .html, right?
In principle I wanted to have in .pdf, but if there are no other options then this will be my way to go!

Thanks a lot,


Hi Berta,
well, according to:

there is the option to use --to pdf instead of --to html :slight_smile:
Though I’ve not (yet) tried that …
cheers, andreas

Hi Andreas,

Yes indeed! That should be possible but I tried it with SWAN and it does not work.
Thanks a lot anyway!