From 00d8fe72d8ac5106435d31428d8d5c0ea17bf7a4 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Fri, 6 Nov 2020 14:02:33 -0500 Subject: [PATCH] added numpy export --- pdfmajor/document/structures.py | 16 ++++++++++++++++ setup.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pdfmajor/document/structures.py b/pdfmajor/document/structures.py index c368ea2..30cd469 100644 --- a/pdfmajor/document/structures.py +++ b/pdfmajor/document/structures.py @@ -1,6 +1,8 @@ from decimal import Decimal from typing import List, NamedTuple +import numpy as np + from pdfmajor.document.exceptions import BrokenFilePDF, TooManyRectField from pdfmajor.pdf_parser.objects import PDFArray, PDFInteger, PDFReal @@ -30,3 +32,17 @@ class PDFRectangle(NamedTuple): f"Insufficient number of fields for rectangle {arr} {vals}" ) return cls(*vals) + + def to_numpy(self) -> np.ndarray: + """convert the rectangle to a numpy array + + Returns: + np.ndarray[np.float64] + """ + return np.array( + [ + [np.float64(self.llx), np.float64(self.lly)], + [np.float64(self.urx), np.float64(self.ury)], + ], + dtype=np.float64, + ) diff --git a/setup.py b/setup.py index 689ace4..10144dd 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ with open("README.md") as readme_file: "name": "pdfmajor", "version": "1.3.13", "packages": find_packages(include=["pdfmajor*"]), - "install_requires": ["numpy==1.19.4", "typing-extensions==3.7.4.3"], + "install_requires": ["numpy==1.19.4", "data-science-types==0.2.19"], "extras_require": { "dev": [ "tqdm==4.32.1",