{ "info": { "author": "Navin Mohan", "author_email": "navinmohan81@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Pychromepdf\n\nPychromepdf is a Python package that lets you easily create PDFs by rendering HTML content using Chrome or Chromium as backend. It works without any external dependecies except a working installation of Chrome or Chromium that supports headless mode.\n\n# Installation\n\n```bash\npip install pychromepdf\n```\n\n## Usage\n\n### Rendering HTML bytestring to PDF\n\n```python\nfrom pychromepdf import ChromePDF\n\n# change to your chrome executable path\nPATH_TO_CHROME_EXE = '/usr/bin/google-chrome-stable'\n\nif __name__ == '__main__':\n # initialize chromepdf object\n cpdf = ChromePDF(PATH_TO_CHROME_EXE)\n\n # the html that need to be rendered into pdf\n html_bytestring = '''\n \n \n \n \n \n \n

Hello, World

\n
Generated using headless chrome
\n \n \n '''\n\n # create a file and write the pdf to it\n with open('test.pdf','w') as output_file:\n if cpdf.html_to_pdf(html_bytestring,output_file):\n print(\"Successfully generated the pdf: {}\".format(output_file.name))\n else:\n print(\"Error generating pdf\")\n\n```\n\n### Rendering a flask template into PDF\n\n```python\nfrom flask import Flask, render_template, send_file\nimport tempfile\nfrom pychromepdf import ChromePDF\n\napp = Flask(__name__)\n\n# change to your chrome executable path\nPATH_TO_CHROME_EXE = '/usr/bin/google-chrome-stable'\n\n# initialize a chromepdf object\ncpdf = ChromePDF(PATH_TO_CHROME_EXE)\n\n# home route\n@app.route('/')\ndef index():\n return render_template('index.html',username=\"John\")\n\n# custom pdf route\n@app.route('/getpdf',defaults={'username': 'John'})\n@app.route('/getpdf/')\ndef getpdf(username):\n\n # get the rendered html as string using the template\n rendered_html = render_template('index.html',username=username)\n\n # create a temporary output file which will be deleted when closed\n with tempfile.NamedTemporaryFile(suffix='.pdf') as output_file:\n\n # create a pdf from the rendered html and write it to output_file\n if cpdf.html_to_pdf(rendered_html,output_file):\n print(\"PDF generated successfully: {0}\".format(output_file.name))\n\n try:\n # send the file to user\n return send_file(output_file.name,attachment_filename='awesome.pdf')\n except Exception as e:\n return str(e)\n else:\n print(\"Error creating PDF\")\n\n return \"Error\"\n \n\nif __name__ == '__main__':\n app.run(debug=True)\n\n```\n\nTemplate\n\n```html\n{# templates/index.html #}\n\n\n\n\n \n \n Example\n \n \n\n\n

Hello {{ username }}!

\n

Generated using ChromePDF

\n\n\n\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/nvnmo/pychromepdf", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "pychromepdf", "package_url": "https://pypi.org/project/pychromepdf/", "platform": "", "project_url": "https://pypi.org/project/pychromepdf/", "project_urls": { "Homepage": "https://github.com/nvnmo/pychromepdf" }, "release_url": "https://pypi.org/project/pychromepdf/0.0.4/", "requires_dist": null, "requires_python": "", "summary": "Creates PDFs from HTML rendered using chrome or chromium", "version": "0.0.4" }, "last_serial": 4828162, "releases": { "0.0.3": [ { "comment_text": "", "digests": { "md5": "1518c4fb1045b52fd45fc121ea7369ee", "sha256": "d110df516b44bcedf356f26d9000441d6e2da33bac45cf39a7194f49bd9cb6c8" }, "downloads": -1, "filename": "pychromepdf-0.0.3.tar.gz", "has_sig": false, "md5_digest": "1518c4fb1045b52fd45fc121ea7369ee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3306, "upload_time": "2019-02-15T04:59:38", "url": "https://files.pythonhosted.org/packages/1a/fc/f24438b817c2e627d74ba9cc38c0972dd7dc4e444e3af8b2d830ba3aba51/pychromepdf-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "557cb48523d3e2ccc2c9c7a044721c38", "sha256": "efe2856267a07cb72799484235556a4734730b6b7e135a115f9223f832444b38" }, "downloads": -1, "filename": "pychromepdf-0.0.4.tar.gz", "has_sig": false, "md5_digest": "557cb48523d3e2ccc2c9c7a044721c38", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3348, "upload_time": "2019-02-16T08:01:41", "url": "https://files.pythonhosted.org/packages/64/ea/9fbb64f1c4953ca8a1b41b3b4376dec4034ea4b7f4064648b7f587e71ce3/pychromepdf-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "557cb48523d3e2ccc2c9c7a044721c38", "sha256": "efe2856267a07cb72799484235556a4734730b6b7e135a115f9223f832444b38" }, "downloads": -1, "filename": "pychromepdf-0.0.4.tar.gz", "has_sig": false, "md5_digest": "557cb48523d3e2ccc2c9c7a044721c38", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3348, "upload_time": "2019-02-16T08:01:41", "url": "https://files.pythonhosted.org/packages/64/ea/9fbb64f1c4953ca8a1b41b3b4376dec4034ea4b7f4064648b7f587e71ce3/pychromepdf-0.0.4.tar.gz" } ] }