From b90a84399c3f9dd1f7ceb39de7ca7ab8aae4d7b3 Mon Sep 17 00:00:00 2001 From: CoprDistGit Date: Fri, 5 May 2023 09:16:27 +0000 Subject: automatic import of python-pychromepdf --- .gitignore | 1 + python-pychromepdf.spec | 486 ++++++++++++++++++++++++++++++++++++++++++++++++ sources | 1 + 3 files changed, 488 insertions(+) create mode 100644 python-pychromepdf.spec create mode 100644 sources diff --git a/.gitignore b/.gitignore index e69de29..e8e54ad 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/pychromepdf-1.1.tar.gz diff --git a/python-pychromepdf.spec b/python-pychromepdf.spec new file mode 100644 index 0000000..b7ac95e --- /dev/null +++ b/python-pychromepdf.spec @@ -0,0 +1,486 @@ +%global _empty_manifest_terminate_build 0 +Name: python-pychromepdf +Version: 1.1 +Release: 1 +Summary: Creates PDFs from HTML rendered using chrome or chromium +License: MIT License +URL: https://github.com/nvnmo/pychromepdf +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/57/f4/75d2ef3b4a93b253924f56a3c0617768a1dbdc342ee552da596778f5bb8c/pychromepdf-1.1.tar.gz +BuildArch: noarch + + +%description +# Pychromepdf [![PyPI version](https://badge.fury.io/py/pychromepdf.png)](https://badge.fury.io/py/pychromepdf) [![Travis build status](https://travis-ci.org/nvnmo/pychromepdf.svg?branch=master)](https://travis-ci.org/github/nvnmo/pychromepdf) + +Pychromepdf 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. + +# Installation + +```bash +pip install pychromepdf +``` + +## Usage + +### Rendering HTML bytestring to PDF + +```python +from pychromepdf import ChromePDF + +# change to your chrome executable path +PATH_TO_CHROME_EXE = '/usr/bin/google-chrome-stable' +# if you're on MacOS +# PATH_TO_CHROME_EXE = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' + +if __name__ == '__main__': + # initialize chromepdf object + cpdf = ChromePDF(PATH_TO_CHROME_EXE) + + # the html that need to be rendered into pdf + html_bytestring = ''' + + + + + + +

Hello, World

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

Hello {{ username }}!

+

Generated using ChromePDF

+ + + +``` +# Contributors +- [nvnmo](https://github.com/nvnmo) +- [chibiegg](https://github.com/chibiegg) + +# License +MIT License + +%package -n python3-pychromepdf +Summary: Creates PDFs from HTML rendered using chrome or chromium +Provides: python-pychromepdf +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-pychromepdf +# Pychromepdf [![PyPI version](https://badge.fury.io/py/pychromepdf.png)](https://badge.fury.io/py/pychromepdf) [![Travis build status](https://travis-ci.org/nvnmo/pychromepdf.svg?branch=master)](https://travis-ci.org/github/nvnmo/pychromepdf) + +Pychromepdf 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. + +# Installation + +```bash +pip install pychromepdf +``` + +## Usage + +### Rendering HTML bytestring to PDF + +```python +from pychromepdf import ChromePDF + +# change to your chrome executable path +PATH_TO_CHROME_EXE = '/usr/bin/google-chrome-stable' +# if you're on MacOS +# PATH_TO_CHROME_EXE = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' + +if __name__ == '__main__': + # initialize chromepdf object + cpdf = ChromePDF(PATH_TO_CHROME_EXE) + + # the html that need to be rendered into pdf + html_bytestring = ''' + + + + + + +

Hello, World

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

Hello {{ username }}!

+

Generated using ChromePDF

+ + + +``` +# Contributors +- [nvnmo](https://github.com/nvnmo) +- [chibiegg](https://github.com/chibiegg) + +# License +MIT License + +%package help +Summary: Development documents and examples for pychromepdf +Provides: python3-pychromepdf-doc +%description help +# Pychromepdf [![PyPI version](https://badge.fury.io/py/pychromepdf.png)](https://badge.fury.io/py/pychromepdf) [![Travis build status](https://travis-ci.org/nvnmo/pychromepdf.svg?branch=master)](https://travis-ci.org/github/nvnmo/pychromepdf) + +Pychromepdf 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. + +# Installation + +```bash +pip install pychromepdf +``` + +## Usage + +### Rendering HTML bytestring to PDF + +```python +from pychromepdf import ChromePDF + +# change to your chrome executable path +PATH_TO_CHROME_EXE = '/usr/bin/google-chrome-stable' +# if you're on MacOS +# PATH_TO_CHROME_EXE = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' + +if __name__ == '__main__': + # initialize chromepdf object + cpdf = ChromePDF(PATH_TO_CHROME_EXE) + + # the html that need to be rendered into pdf + html_bytestring = ''' + + + + + + +

Hello, World

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

Hello {{ username }}!

+

Generated using ChromePDF

+ + + +``` +# Contributors +- [nvnmo](https://github.com/nvnmo) +- [chibiegg](https://github.com/chibiegg) + +# License +MIT License + +%prep +%autosetup -n pychromepdf-1.1 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-pychromepdf -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Fri May 05 2023 Python_Bot - 1.1-1 +- Package Spec generated diff --git a/sources b/sources new file mode 100644 index 0000000..27618f9 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +35c776d82990d4c5aa3a16eaf026744f pychromepdf-1.1.tar.gz -- cgit v1.2.3