0

I would like to only export to PDF the output - not the actual code - of specific cells that I have in my open Jupyter Notebook kernel.

I already ran the code, so when I open the notebook, the output is already there. I simply want to extract the output of 5 different cells (out of around 20) into a PDF to make it easier to share.

I tried to download latex, nbconvert using jupyter notebook tags on the cells whose output I want to extract (tag = "pdf-extract") or pip import hide_code but honestly nothing works.

I also tried using this HTML code but then I cannot 'go-backwards' and need to restart the whole kernel to see the code again... losing all output too :-(

%%html
<style>
div.input {
    display:none;
}
</style>

I've also tried Mercury, but getting the 'Waiting for worker...' message after trying to load my ipynb.

Seems like such a simple request, but seriously hard to do for me.

I would like the output to be in PDF format and for the code not to be run again. The output is already in the kernel, all I need is to extract it into a PDF.

Any help would be really appreciated!

Cla Rosie
  • 345
  • 1
  • 2
  • 10
  • As written, your post is confusing in a number of ways. It also is not clear what you really want. Specifics to back up what I just said: tour title says,"Printing only output of specific cells of jupyter notebook" and then your post says, " print the output - not the code - of specific cells in my Jupyter Notebook kernel." That kernel mention makes this two different things. You say "printing" in several places and then mention 'liking' PDF format. Those are also different things. Finally, os the output in the kernel or in the saved notebook file? If what you tried was close to what you .... – Wayne Jun 28 '23 at 15:06
  • thought you really needed, then specifics on that would be important. Such as what methods and actual tags. However, I think you are mentioning that only as some stuff you tried and not what you want so probably not a necessary direction to go in at this time for focusing your post. – Wayne Jun 28 '23 at 15:08
  • Hey Wayne, appreciate your honest feedback. Will try to improve the question. Let me know if it now makes (a lot) more sense. I hope it does :) – Cla Rosie Jun 28 '23 at 23:48
  • Your focus on the kernel having the output still confuses me. Have you saved the `.ipynb` after running it and checked in a text editor if there is output for the cells you want. The way to do it is to make a copy of notebook and clear all the output and save that and then compare the two. You may not be able to tell what the output really is but if it is there it may be possible to do what you want without an active kernel. I will say the way this is usually done to make a PDF is to run the notebook `.ipynb` file on the command line with `jupyter nbconvert` or `jupytext` or `papermill`. ... – Wayne Jun 29 '23 at 12:21
  • So honestly there's definitely some improvement in your question but still I'm concerned about this focus on the kernel. Plus you never say what types of output these are. Are they all the same? Are they varied? Are they Matplotlib plots? Or Plotly Plots? Results of calculations? A lot of these outputs have ways to save them separately, some that you can more easily make into a report and even into a report in PDF format. But you aren't saying this? Plus how much consistency do you need? Does everything have a tag that you can automate? How often will you need to do this? Scale? – Wayne Jun 29 '23 at 12:24
  • Does [here](https://stackoverflow.com/a/47773252/8508004) work at least for making the PDF on the command line? Even if it has all the cells for now. Then you don't need an active kernel. And there are other customizable ways to make the notebook with just the output of the cells you want. You can use the `--no-input` tag, see [here](https://stackoverflow.com/a/69474214/8508004) and [here](https://stackoverflow.com/a/62266448/8508004)? If the basics work you can customize making a notebook that you can then convert to get things as you need. You may need to use nbformat in customization step. – Wayne Jun 29 '23 at 12:35

0 Answers0