Is there a way to save a pdf or html version of the current notebook view

In Jupyter lab 4+ (last tested in 4.3.4) all the methods that allow saving a copy of a notebook that extends beyond the view window do not abide by the current DOM formatting. In particular, I would like my exports to keep collapsed cells and things like that.

In classic Jupyter notebooks one could use the browser Print to pdf function to get a very good approximation of the current view. Now with Jupyter lab and the new notebook this does not work, because it only sees the current displayed page and not the parts of the notebook that are out of view (even when the notebook windowing mode is set to “none”).

One thought would be to make the JIab file menu print option open a static copy of just the notebook DOM with all current formatting in a new tab and print from that. I do not presently have time to go grepping through the code to see if this is possible. Does anyone know how to do this or have a better idea?

Another, I believe harder to implement, solution would be to change the behavior of nbconvert.

Thanks.

Did you try to expert to webpdf format? You need to run an install command documented in nbconvert dice

1 Like

@krassowski thank you for the suggestion. Unfortunately, webpdf export generates a pdf with hidden cells showing and collapsed code showing, just as with the other methods. The closest I can get are either screen shots or the browser print option, but those only show what is visible on the screen.

What I am looking for is something more or less equivalent to printing an old fashioned iframe.

what do you mean with collapsed cell?
using markdown collapse or what are you referring to?
if that is what you mean it should be possible to get nbconvert to exclude cells under the "jp-MarkdownHeadingCollapsed": true metatag, but i wouldn’t bother.

there are templates like pretty jupyter which parse metadata for each individual cell to hide input or output, with my own pretty jupyter metadata form extension you can even set those options in the property inspector.

1 Like

@spookster Thanks for the pointer to other possible solutions. I will look at them.

I want to export static views of the current notebook state as either html or pdf. I want the export to respect the current view state of all the notebook DOM elements. I do not care how the view state is set (in metadata or by using an extension that controls element views). Thus, I am wary of any tool that depends on the cell metadata exactly reflecting the current view. The metadata flags used that impact view depend on which extensions are being used, if they even set metadata.