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: )?

Thanks!
Berta

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: http://stackoverflow.com/questions/27934885/how-to-hide-code-from-cells-in-ipython-notebook-visualized-with-nbviewer#28073228)
from IPython.display import HTML

HTML('''<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 } else {
 $('div.input').show();
 }
 code_show = !code_show
} 
$( document ).ready(code_toggle);
</script>
<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).

HTH,
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,

Berta

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 …
HTH,
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!

Cheers,

Berta