{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "77e0481d-3f52-469d-a7bf-d0e705e5a2a4", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[33mDEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0mCollecting weasyprint\n", " Downloading weasyprint-55.0-py3-none-any.whl (249 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m249.5/249.5 kB\u001b[0m \u001b[31m2.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: Pillow>=4.0.0 in /opt/homebrew/lib/python3.9/site-packages (from weasyprint) (9.0.1)\n", "Collecting cssselect2>=0.1\n", " Downloading cssselect2-0.6.0-py3-none-any.whl (15 kB)\n", "Collecting pydyf>=0.0.3\n", " Downloading pydyf-0.2.0-py3-none-any.whl (6.6 kB)\n", "Collecting Pyphen>=0.9.1\n", " Downloading pyphen-0.12.0-py3-none-any.whl (2.0 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m13.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: tinycss2>=1.0.0 in /opt/homebrew/lib/python3.9/site-packages (from weasyprint) (1.1.1)\n", "Requirement already satisfied: cffi>=0.6 in /opt/homebrew/lib/python3.9/site-packages (from weasyprint) (1.15.0)\n", "Collecting html5lib>=1.1\n", " Downloading html5lib-1.1-py2.py3-none-any.whl (112 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m112.2/112.2 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hCollecting fonttools[woff]>=4.0.0\n", " Downloading fonttools-4.33.3-py3-none-any.whl (930 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m930.9/930.9 kB\u001b[0m \u001b[31m16.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: pycparser in /opt/homebrew/lib/python3.9/site-packages (from cffi>=0.6->weasyprint) (2.21)\n", "Requirement already satisfied: webencodings in /opt/homebrew/lib/python3.9/site-packages (from cssselect2>=0.1->weasyprint) (0.5.1)\n", "Collecting brotli>=1.0.1\n", " Downloading Brotli-1.0.9-cp39-cp39-macosx_10_9_universal2.whl (786 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m786.7/786.7 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hCollecting zopfli>=0.1.4\n", " Downloading zopfli-0.2.1-cp39-cp39-macosx_10_9_universal2.whl (289 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m289.8/289.8 kB\u001b[0m \u001b[31m9.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: six>=1.9 in /opt/homebrew/lib/python3.9/site-packages (from html5lib>=1.1->weasyprint) (1.12.0)\n", "Installing collected packages: brotli, zopfli, Pyphen, pydyf, html5lib, fonttools, cssselect2, weasyprint\n", "\u001b[33m DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0m\u001b[33m DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0m\u001b[33m DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0m\u001b[33m DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0m\u001b[33m DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0m\u001b[33m DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0m\u001b[33m DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0m\u001b[33m DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0m\u001b[33mDEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621\u001b[0m\u001b[33m\n", "\u001b[0mSuccessfully installed Pyphen-0.12.0 brotli-1.0.9 cssselect2-0.6.0 fonttools-4.33.3 html5lib-1.1 pydyf-0.2.0 weasyprint-55.0 zopfli-0.2.1\n", "\u001b[33mWARNING: There was an error checking the latest version of pip.\u001b[0m\u001b[33m\n", "\u001b[0m" ] } ], "source": [ "!pip install weasyprint" ] }, { "cell_type": "code", "execution_count": 4, "id": "db0a9ff4-403f-472e-8e1e-2fa36062e35d", "metadata": { "tags": [] }, "outputs": [ { "ename": "FileNotFoundError", "evalue": "[Errno 2] No such file or directory: '/User/donaldrich/Desktop/weasyprint-website.pdf'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m/Users/donaldrich/Projects/secrets/code/Weazyprint/weasyprint.ipynb Cell 2'\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mweasyprint\u001b[39;00m \u001b[39mimport\u001b[39;00m HTML\n\u001b[0;32m----> 3\u001b[0m HTML(\u001b[39m\"\u001b[39;49m\u001b[39mhttp://weasyprint.org/\u001b[39;49m\u001b[39m\"\u001b[39;49m)\u001b[39m.\u001b[39;49mwrite_pdf(\u001b[39m\"\u001b[39;49m\u001b[39m/User/donaldrich/Desktop/weasyprint-website.pdf\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n", "File \u001b[0;32m/opt/homebrew/lib/python3.9/site-packages/weasyprint/__init__.py:177\u001b[0m, in \u001b[0;36mHTML.write_pdf\u001b[0;34m(self, target, stylesheets, zoom, attachments, finisher, presentational_hints, optimize_size, font_config, counter_style, image_cache)\u001b[0m\n\u001b[1;32m 132\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mwrite_pdf\u001b[39m(\u001b[39mself\u001b[39m, target\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, stylesheets\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, zoom\u001b[39m=\u001b[39m\u001b[39m1\u001b[39m,\n\u001b[1;32m 133\u001b[0m attachments\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, finisher\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, presentational_hints\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m,\n\u001b[1;32m 134\u001b[0m optimize_size\u001b[39m=\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mfonts\u001b[39m\u001b[39m'\u001b[39m,), font_config\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m,\n\u001b[1;32m 135\u001b[0m counter_style\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, image_cache\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m):\n\u001b[1;32m 136\u001b[0m \u001b[39m\"\"\"Render the document to a PDF file.\u001b[39;00m\n\u001b[1;32m 137\u001b[0m \n\u001b[1;32m 138\u001b[0m \u001b[39m This is a shortcut for calling :meth:`render`, then\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 174\u001b[0m \n\u001b[1;32m 175\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[1;32m 176\u001b[0m \u001b[39mreturn\u001b[39;00m (\n\u001b[0;32m--> 177\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mrender(\n\u001b[1;32m 178\u001b[0m stylesheets, presentational_hints\u001b[39m=\u001b[39;49mpresentational_hints,\n\u001b[1;32m 179\u001b[0m optimize_size\u001b[39m=\u001b[39;49moptimize_size, font_config\u001b[39m=\u001b[39;49mfont_config,\n\u001b[1;32m 180\u001b[0m counter_style\u001b[39m=\u001b[39;49mcounter_style, image_cache\u001b[39m=\u001b[39;49mimage_cache)\n\u001b[1;32m 181\u001b[0m \u001b[39m.\u001b[39;49mwrite_pdf(target, zoom, attachments, finisher))\n", "File \u001b[0;32m/opt/homebrew/lib/python3.9/site-packages/weasyprint/document.py:853\u001b[0m, in \u001b[0;36mDocument.write_pdf\u001b[0;34m(self, target, zoom, attachments, finisher)\u001b[0m\n\u001b[1;32m 851\u001b[0m shutil\u001b[39m.\u001b[39mcopyfileobj(file_obj, target)\n\u001b[1;32m 852\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 853\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mopen\u001b[39;49m(target, \u001b[39m'\u001b[39;49m\u001b[39mwb\u001b[39;49m\u001b[39m'\u001b[39;49m) \u001b[39mas\u001b[39;00m fd:\n\u001b[1;32m 854\u001b[0m shutil\u001b[39m.\u001b[39mcopyfileobj(file_obj, fd)\n", "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '/User/donaldrich/Desktop/weasyprint-website.pdf'" ] } ], "source": [ "from weasyprint import HTML\n", "\n", "HTML(\"http://weasyprint.org/\").write_pdf(\"/User/donaldrich/Desktop/weasyprint.pdf\")" ] }, { "cell_type": "code", "execution_count": null, "id": "b66cdca8-02c4-4761-84b1-a0a91991fb0a", "metadata": {}, "outputs": [], "source": [ "https://selenium-python.readthedocs.io/_/downloads/en/latest/pdf/" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.13 64-bit", "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.9.13" }, "vscode": { "interpreter": { "hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e" } }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }