{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/py-pdf/fpdf2/blob/master/tutorial/notebook.ipynb)
[![Open In nbviewer](https://img.shields.io/badge/Open_In-nbviewer-blue?logo=jupyter)](https://nbviewer.org/github/py-pdf/fpdf2/blob/master/tutorial/notebook.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Hello World with fpdf2\n", "This [Jupyter notebook](https://jupyter.org/) demontrates some basic usage of the Python [fpdf2](https://github.com/py-pdf/fpdf2) library" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [] } ], "source": [ "# Installation of fpdf2 with PIP:\n", "!pip install fpdf2" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Enable deprecation warnings:\n", "import warnings\n", "warnings.simplefilter('default', DeprecationWarning)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Generate a PDF:\n", "from fpdf import FPDF\n", "pdf = FPDF()\n", "pdf.add_page()\n", "pdf.set_font('helvetica', size=48)\n", "pdf.cell(text=\"hello world\")\n", "pdf_bytes = pdf.output()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Display the PDF in the notebook by embedding it as HTML content:\n", "WIDTH, HEIGHT = 800, 400 \n", "from base64 import b64encode\n", "from IPython.display import display, HTML\n", "base64_pdf = b64encode(pdf_bytes).decode(\"utf-8\")\n", "display(HTML(f''))" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Click to download PDF" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Diplay a download button:\n", "display(HTML(f'Click to download PDF'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To continue learning about `fpdf2`, check our tutorial:\n", "- [English](https://py-pdf.github.io/fpdf2/Tutorial.html)\n", "- [Deutsch](https://py-pdf.github.io/fpdf2/Tutorial-de.html)\n", "- [español](https://py-pdf.github.io/fpdf2/Tutorial-es.html)\n", "- [हिंदी](https://py-pdf.github.io/fpdf2/Tutorial-हिंदी.html)\n", "- [português](https://py-pdf.github.io/fpdf2/Tutorial-pt.html)\n", "- [Русский](https://py-pdf.github.io/fpdf2/Tutorial-ru.html)\n", "- [Italian](https://py-pdf.github.io/fpdf2/Tutorial-it.html)\n", "- [français](https://py-pdf.github.io/fpdf2/Tutorial-fr.html)\n", "- [Ελληνικά](https://py-pdf.github.io/fpdf2/Tutorial-gr.html)\n", "- [עברית](https://py-pdf.github.io/fpdf2/Tutorial-he.html)\n", "- [Dutch](https://py-pdf.github.io/fpdf2/Tutorial-nl.html)" ] } ], "metadata": { "colab": { "collapsed_sections": [], "include_colab_link": true, "name": "Hello World with fpdf2", "provenance": [] }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 1 }