{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Voilà Notebook to PDF Converter" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# css box model: https://www.w3schools.com/css/css_boxmodel.asp\n", "# box shadow: https://www.w3schools.com/cssref/css3_pr_box-shadow.asp\n", "# adding css style to ipywidgets.Box: https://stackoverflow.com/questions/49863789/setting-background-color-of-a-box-in-ipywidgets" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2e8dd55e02ec4139809ecaaefe3641d5", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(VBox(children=(HTML(value='

Notebook to PDF Converter

'), HBox(children=(HTML(value='Have you uploaded a notebook file yet?

'))\n", " return \n", " pdfName = nbName.replace('ipynb', 'pdf')\n", " with open(nbName, 'w+b') as f:\n", " f.write(fileInput.data[0])\n", " proc = subprocess.run(['jupyter', 'nbconvert', nbName, '--to', 'pdf'])\n", " clear_output()\n", " if proc.returncode == 1:\n", " print()\n", " display(HTML('

LaTeX compiling error!

'))\n", " else:\n", " with open(pdfName, \"rb\") as f:\n", " data = f.read()\n", " b64 = base64.b64encode(data)\n", " payload = b64.decode()\n", " display(HTML(f''' \n", " \n", " '''))\n", "\n", "convertButton.on_click(convert)\n", "\n", "# display(fileInput, convertButton, output) \n", "\n", "\n", "text = '''\n", "## 3 Easy Steps: \n", "1. Upload your notebook (.ipynb) file. You may only convert one notebook at a time \\n\n", "* Hit Convert \\n\n", "* A Download button will show up when your PDF file is ready. Enjoy!\n", "'''\n", "\n", "footer = '''

Powered by 

\n", "\"Binder,\n", "'''\n", "\n", "box_layout = widgets.Layout(display='flex',\n", " flex_flow='column',\n", " align_items='center',\n", " width='100%')\n", "\n", "form = widgets.VBox([\n", " widgets.HTML(markdown.markdown('# Notebook to PDF Converter')), \n", " widgets.HBox([widgets.HTML(markdown.markdown(text)), widgets.HTML('

        

'), \n", " widgets.VBox([widgets.HTML('

'), fileInput, convertButton, output])]), \n", " widgets.HTML(markdown.markdown(footer))\n", " ])\n", "form.add_class('box_style')\n", "\n", "widgets.HBox([form], layout=box_layout)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.8" } }, "nbformat": 4, "nbformat_minor": 4 }