I'm trying to export a notebook to pdf via latex, but doesn't work.
If I upload an image in markdown cell,
![image.png](attachment:image.png)
I can see the image in notebook, but when I export to pdf
the final file doesn't open, it says that the file can be danified and can't be open.
But if I put the image via cell code
PATH = "C:/Users/my_folder/"
Image(filename = PATH + "image.png", width=800)
the pdf works well, but I don't like the style, with the grey box on the cell code...
Could someone help me? How to export notebooks with markdown images or how to change the style of exported files in jupyter notebook to something more similar to an article.
When I convert a notebook containing an ipywidget, the widget doesn't render, only the label is printed. Is it possible to get nbconvert to render the ipywidget when converting to html or pdf? I don't need interactivity, just a static image.
Here is the notebook defining a slider widget
And here is the output after running nbconvert --to pdf widget-test.ipynb
I went through the process of saving the notebook widget state according to the official instructions before converting the notebook.
I am using the latest jupyter/scipy-notebook docker image.
I wrote a jupyter notebook and set up slideshow options to obtain slides and do a presentation. Thus I can see my presentation with
jupyter nbconvert notebook.ipynb --to slides --post serve
Doing this I also obtain a notebook.slides.html file. But if I open that file with my browser, the slides are not rendered, I obtain a basic html page. I would like to know how can I render the slides in a browser directly from the html file ?
For example, if you open the demo.html file of reveal.js the slides are directly rendered.
I am running Python 3.7 on Windows using pycharm. I have a jupyter notebook and I would like to embed an image into the notebook. I know all the ways of doing standard embedding with markdown language, BUT ideally what I want is:
a. Embed the image via markdown language, i.e. the notebook cell is in 'markdown' state, not 'Code' state, AND ALSO
b. Have it able to export to HTML and retain that image in the HTML file. i.e. on the notebook. I want to click File -> Download as -> HTML (.html), save the notebook file in .html format, and then when I send it to my buddy, the image that I attached is in the notebook, and he sees it.
I know i could do this in a cell ('code'):
from IPython.display import Image
Image(filename="myfile.jpg")
but I do not want to use 'Code', since when I send to my buddy, he will see the In [] code statement and the Out [] of the image in the notebook html file.
Note: This would be an image that was on my laptop that I would want in the html formatted exported notebook. It is NOT on the web where he could refer to it with a www type statement. Unless I'm crazy, there is no way to do this with markdown command in a cell, the only way to do it (with the image embedded 'permanently' into the .html format of the notebook), would be via a cell that was in 'Code' celltype.
When you use a code cell to show an image and then export the notebook to an HTML file, the image is converted to Base64 and the code directly used in the src attribute of the <img> tag. You can apply the same procedure with images included in markdown cells.
First, encode your image as Base64, e.g. by using one of the online enocders.
Create a markdown cell and include an <img> tag which uses your Base64 code, e.g.:
<img src="data:image/png;base64,CODE_FOLLOWS_HERE" />
Evaluate the cell and you should already see your image.
If you now export your notebook to HTML, the image should be included in the file the same way as images from code cells.
The only disadvantage with this approach is that your markdown cell gets cluttered with the (probably long) Base64 code. However, this is manageable by e.g. using a markdown cell dedicated solely to the image without other content.
You can install the Unofficial Jupyter Notebook Extensions.
It has some interesting extensions (e.g. spell checker, collapsible headings, ...). One of the extensions is Export HTML With Embedded Images which exactly does what you want.
To install Nbextensions using pip do the following:
$ pip install jupyter_contrib_nbextensions
$ pip install jupyter_nbextensions_configurator
$ jupyter contrib nbextension install --user
$ jupyter nbextensions_configurator enable --user
Then you will see in your Jupyter homepage a new tab (Nbextensions), where you can enable and configure different extension.
After enabling the "Export HTML With Embedded Images", you will see the corresponding option in the "File-Download as" menu.
My complete solution is based on Milania and
encoding-an-image-file-with-base64
how-to-base64-encode-an-image-using-python
BytesIO.getvalue
the code
import base64, io, IPython
from PIL import Image as PILImage
image = PILImage.open(image_path)
output = io.BytesIO()
image.save(output, format='PNG')
encoded_string = base64.b64encode(output.getvalue()).decode()
html = '<img src="data:image/png;base64,{}"/>'.format(encoded_string)
IPython.display.HTML(html)
For me, on Visual Studio Code, something like this did the trick (in a markdown cell, as you requested, and a image that you want to embed in your notebook and further be exported to the html output):
<figure>
<img src="./notebook_img/diptera_taxat_yes_no.jpg" width="200"/>
<figcaption>Limit the search on Diptera</figcaption>
</figure>
Where the image is located in "./notebook_img" relative to the location of the notebook (in this sense, the notebook is located in .)
Your buddy will not see the code from above when reading the HTML exported file, so that should satisfy the requested need as far as I understand. He will also not need the folder "notebook_img".
I use ipython nbconvert mynotebook.ipynb --to pdf to get a pdf file of my notebook. The picture below shows the (latex-)generated output. How can I change the behavior of nbconvert so that it shows the rendered HTML and not the object string representation?