diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-05-10 05:17:32 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-05-10 05:17:32 +0000 |
| commit | 8fb6910e16bf113f463cff7feffcbd41fe5eb91b (patch) | |
| tree | f08d50fa64ab0fd8311fe6008939acb7de3815ad | |
| parent | 12650a9638a80e32f5dfd4d4084c30e40ed26ead (diff) | |
automatic import of python-pypdfiumopeneuler20.03
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-pypdfium.spec | 270 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 272 insertions, 0 deletions
@@ -0,0 +1 @@ +/pypdfium-0.0.15.tar.gz diff --git a/python-pypdfium.spec b/python-pypdfium.spec new file mode 100644 index 0000000..2e2b6d6 --- /dev/null +++ b/python-pypdfium.spec @@ -0,0 +1,270 @@ +%global _empty_manifest_terminate_build 0 +Name: python-pypdfium +Version: 0.0.15 +Release: 1 +Summary: A simple python wrapper for PDFium +License: MIT License +URL: https://github.com/YinlinHu/pypdfium +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/29/5d/17a388df5bd2e71b7a45bd5e64e3094d17afc86f461bca107109e3f031d1/pypdfium-0.0.15.tar.gz +BuildArch: noarch + + +%description +# PyPDFium + +A simple python wrapper for [PDFium](https://opensource.google/projects/pdfium). + +## Installation +```bash +pip install pypdfium +``` + +## Quick start + +```python +import sys +from PIL import Image + +import ctypes +import pypdfium as PDFIUM +PDFIUM.FPDF_InitLibraryWithConfig(PDFIUM.FPDF_LIBRARY_CONFIG(2, None, None, 0)) + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("USAGE: demo.py somefile.pdf") + exit(0) + + fname = sys.argv[1] + + doc = PDFIUM.FPDF_LoadDocument(fname, None) # load document + page_count = PDFIUM.FPDF_GetPageCount(doc) # get page counts + assert(page_count >= 1) + + page = PDFIUM.FPDF_LoadPage(doc, 0) # load the first page + width = int(PDFIUM.FPDF_GetPageWidthF(page) + 0.5) # get page width + height = int(PDFIUM.FPDF_GetPageHeightF(page) + 0.5) # get page height + + # render to bitmap + bitmap = PDFIUM.FPDFBitmap_Create(width, height, 0) + PDFIUM.FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF) + PDFIUM.FPDF_RenderPageBitmap( + bitmap, page, 0, 0, width, height, 0, + PDFIUM.FPDF_LCD_TEXT | PDFIUM.FPDF_ANNOT + ) + + # retrieve data from bitmap + buffer = PDFIUM.FPDFBitmap_GetBuffer(bitmap) + buffer_ = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_ubyte * (width * height * 4))) + + img = Image.frombuffer("RGBA", (width, height), buffer_.contents, "raw", "BGRA", 0, 1) + img.save("out.png") + + if bitmap is not None: + PDFIUM.FPDFBitmap_Destroy(bitmap) + PDFIUM.FPDF_ClosePage(page) + + PDFIUM.FPDF_CloseDocument(doc) +``` + +## Notes + +* Working on 64bit Windows, Mac OS X and Linux. + +* The `pypdfium.py` file is generated by [ctypesgen](https://github.com/davidjamesca/ctypesgen) with command: `ctypesgen -lpdfium -L somewhere/pdfium-linux/lib somewhere/pdfium-linux/include/*.h -o pypdfium.py` + +* PDFium binaries are from https://github.com/bblanchon/pdfium-binaries + +* API documentation: https://developers.foxitsoftware.com/resources/pdf-sdk/c_api_reference_pdfium/ + +* A PDF manager based on pypdfium: https://github.com/YinlinHu/kuafu + +%package -n python3-pypdfium +Summary: A simple python wrapper for PDFium +Provides: python-pypdfium +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-pypdfium +# PyPDFium + +A simple python wrapper for [PDFium](https://opensource.google/projects/pdfium). + +## Installation +```bash +pip install pypdfium +``` + +## Quick start + +```python +import sys +from PIL import Image + +import ctypes +import pypdfium as PDFIUM +PDFIUM.FPDF_InitLibraryWithConfig(PDFIUM.FPDF_LIBRARY_CONFIG(2, None, None, 0)) + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("USAGE: demo.py somefile.pdf") + exit(0) + + fname = sys.argv[1] + + doc = PDFIUM.FPDF_LoadDocument(fname, None) # load document + page_count = PDFIUM.FPDF_GetPageCount(doc) # get page counts + assert(page_count >= 1) + + page = PDFIUM.FPDF_LoadPage(doc, 0) # load the first page + width = int(PDFIUM.FPDF_GetPageWidthF(page) + 0.5) # get page width + height = int(PDFIUM.FPDF_GetPageHeightF(page) + 0.5) # get page height + + # render to bitmap + bitmap = PDFIUM.FPDFBitmap_Create(width, height, 0) + PDFIUM.FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF) + PDFIUM.FPDF_RenderPageBitmap( + bitmap, page, 0, 0, width, height, 0, + PDFIUM.FPDF_LCD_TEXT | PDFIUM.FPDF_ANNOT + ) + + # retrieve data from bitmap + buffer = PDFIUM.FPDFBitmap_GetBuffer(bitmap) + buffer_ = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_ubyte * (width * height * 4))) + + img = Image.frombuffer("RGBA", (width, height), buffer_.contents, "raw", "BGRA", 0, 1) + img.save("out.png") + + if bitmap is not None: + PDFIUM.FPDFBitmap_Destroy(bitmap) + PDFIUM.FPDF_ClosePage(page) + + PDFIUM.FPDF_CloseDocument(doc) +``` + +## Notes + +* Working on 64bit Windows, Mac OS X and Linux. + +* The `pypdfium.py` file is generated by [ctypesgen](https://github.com/davidjamesca/ctypesgen) with command: `ctypesgen -lpdfium -L somewhere/pdfium-linux/lib somewhere/pdfium-linux/include/*.h -o pypdfium.py` + +* PDFium binaries are from https://github.com/bblanchon/pdfium-binaries + +* API documentation: https://developers.foxitsoftware.com/resources/pdf-sdk/c_api_reference_pdfium/ + +* A PDF manager based on pypdfium: https://github.com/YinlinHu/kuafu + +%package help +Summary: Development documents and examples for pypdfium +Provides: python3-pypdfium-doc +%description help +# PyPDFium + +A simple python wrapper for [PDFium](https://opensource.google/projects/pdfium). + +## Installation +```bash +pip install pypdfium +``` + +## Quick start + +```python +import sys +from PIL import Image + +import ctypes +import pypdfium as PDFIUM +PDFIUM.FPDF_InitLibraryWithConfig(PDFIUM.FPDF_LIBRARY_CONFIG(2, None, None, 0)) + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("USAGE: demo.py somefile.pdf") + exit(0) + + fname = sys.argv[1] + + doc = PDFIUM.FPDF_LoadDocument(fname, None) # load document + page_count = PDFIUM.FPDF_GetPageCount(doc) # get page counts + assert(page_count >= 1) + + page = PDFIUM.FPDF_LoadPage(doc, 0) # load the first page + width = int(PDFIUM.FPDF_GetPageWidthF(page) + 0.5) # get page width + height = int(PDFIUM.FPDF_GetPageHeightF(page) + 0.5) # get page height + + # render to bitmap + bitmap = PDFIUM.FPDFBitmap_Create(width, height, 0) + PDFIUM.FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF) + PDFIUM.FPDF_RenderPageBitmap( + bitmap, page, 0, 0, width, height, 0, + PDFIUM.FPDF_LCD_TEXT | PDFIUM.FPDF_ANNOT + ) + + # retrieve data from bitmap + buffer = PDFIUM.FPDFBitmap_GetBuffer(bitmap) + buffer_ = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_ubyte * (width * height * 4))) + + img = Image.frombuffer("RGBA", (width, height), buffer_.contents, "raw", "BGRA", 0, 1) + img.save("out.png") + + if bitmap is not None: + PDFIUM.FPDFBitmap_Destroy(bitmap) + PDFIUM.FPDF_ClosePage(page) + + PDFIUM.FPDF_CloseDocument(doc) +``` + +## Notes + +* Working on 64bit Windows, Mac OS X and Linux. + +* The `pypdfium.py` file is generated by [ctypesgen](https://github.com/davidjamesca/ctypesgen) with command: `ctypesgen -lpdfium -L somewhere/pdfium-linux/lib somewhere/pdfium-linux/include/*.h -o pypdfium.py` + +* PDFium binaries are from https://github.com/bblanchon/pdfium-binaries + +* API documentation: https://developers.foxitsoftware.com/resources/pdf-sdk/c_api_reference_pdfium/ + +* A PDF manager based on pypdfium: https://github.com/YinlinHu/kuafu + +%prep +%autosetup -n pypdfium-0.0.15 + +%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-pypdfium -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 10 2023 Python_Bot <Python_Bot@openeuler.org> - 0.0.15-1 +- Package Spec generated @@ -0,0 +1 @@ +f5f48d4a2d27eefcb97c20cc979ece68 pypdfium-0.0.15.tar.gz |
