diff --git a/.version b/.version index 7204841..22cdb00 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -v1.1.11 \ No newline at end of file +v1.1.12 \ No newline at end of file diff --git a/pdfmajor/__init__.py b/pdfmajor/__init__.py index 43d7807..beeaba4 100644 --- a/pdfmajor/__init__.py +++ b/pdfmajor/__init__.py @@ -86,7 +86,7 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -__version__ = (1, 1, 11) +__version__ = (1, 1, 12) if __name__ == '__main__': print( diff --git a/pdfmajor/converters/HTMLConverter.py b/pdfmajor/converters/HTMLConverter.py index 1c7c325..59d8853 100644 --- a/pdfmajor/converters/HTMLConverter.py +++ b/pdfmajor/converters/HTMLConverter.py @@ -25,7 +25,7 @@ def get_color(col: PDFGraphicStateColor): elif color_type == 'cmyk': return f"cmyk({','.join(map(str, color_val))})" elif color_type == 'gray': - return f'rgba(0,0,0,{1-color_val})' + return f'rgba(0,0,0,{1-color_val[0]})' elif color_type == "custom": # Todo: convert these to more friendly color types return f"custom({col.custom['type']})" @@ -134,6 +134,8 @@ class HTMLConverter(PDFConverter): 'position': 'absolute', 'left': f'{item.x0}px', 'bottom': f'{item.y0}px', + 'width': f'{item.width}px', + 'height': f'{item.height}px', } path = "" svg_attr = { @@ -141,42 +143,36 @@ class HTMLConverter(PDFConverter): 'z-index': 2 } - if item.height > 0: - dy = 1.0/item.height - dx = (item.width/item.height)/(item.x1-item.x0) - svg_attr.update({ - "viewBox": "0 0 %s %s" % ( item.width/item.height, 1 ) - }) - else: - dx = 1.0/(item.x1-item.x0) - dy = 1.0 - svg_attr.update({ - "viewBox": "0 0 1 1" - }) + p_vals = { "x": [], "y": [] } - if item.height > 1: - svg_attr.update({ - 'height': f'{item.height}px', - }) - else: - svg_attr.update({ - 'height': '1px', - }) - - if item.width > 1: - svg_attr.update({ - 'width': f'{item.width}px', - }) - else: - svg_attr.update({ - 'width': '1px', - }) + for p in item.paths: + for pt in p.points: + p_vals['x'].append(pt.x) + p_vals['y'].append(pt.y) + + mx_x = max([*p_vals['x'], 1]) + mn_x = min([*p_vals['x'], 0]) + mx_y = max([*p_vals['y'], 1]) + mn_y = min([*p_vals['y'], 0]) + + if mx_x == mn_x: + mn_x -= 1 + if mx_y == mn_y: + mn_y -= 1 + + dx = 1/( mx_x - mn_x ) + dy = (item.height/item.width)/( mx_y - mn_y ) + ROUND_VAL = 5 + svg_attr.update({ + # "viewBox": f"{min(p_vals['x'])} {min(p_vals['y'])} {max(p_vals['x'])} {max(p_vals['y'])}", + "viewBox": f"{round(mn_x*dx, ROUND_VAL)} {round(mn_y*dy, ROUND_VAL)} {round(mx_x*dx , ROUND_VAL)} {round(mx_y*dy, ROUND_VAL)}", + }) for p in item.paths: if p.method == CurvePath.METHOD.MOVE_TO: - path += f'M{" ".join( f"{(item.width - (p.x-item.x0) )*dx} {(item.height- (p.y-item.y0) )*dy}" for p in p.points )} ' + path += f'M{" ".join( f"{round(dx*pt.x, ROUND_VAL)} {round(dy*pt.y, ROUND_VAL)}" for pt in p.points )} ' if p.method == CurvePath.METHOD.LINE_TO: - path += f'L{" ".join( f"{(item.width - (p.x-item.x0) )*dx} {( item.height - (p.y-item.y0) )*dy}" for p in p.points )} ' + path += f'L{" ".join( f"{round(dx*pt.x, ROUND_VAL)} {round(dy*pt.y, ROUND_VAL)}" for pt in p.points )} ' if p.method == CurvePath.METHOD.CLOSE_PATH: path += 'Z' with self.place_elm_with_child('svg', svg_attr, css): diff --git a/pdfmajor/interpreter/PDFGraphicState/PDFGraphicStateColor.py b/pdfmajor/interpreter/PDFGraphicState/PDFGraphicStateColor.py index 092e1c5..2bc0e6a 100644 --- a/pdfmajor/interpreter/PDFGraphicState/PDFGraphicStateColor.py +++ b/pdfmajor/interpreter/PDFGraphicState/PDFGraphicStateColor.py @@ -34,7 +34,7 @@ class PDFGraphicStateColor: @property def gray(self): - if self.__gray is not None: return float(self.__gray) + if self.__gray is not None: return [float(self.__gray)] else: raise self.NotSet @property diff --git a/samples/pdf/long-tables.pdf b/samples/pdf/long-tables.pdf new file mode 100644 index 0000000..bc04482 Binary files /dev/null and b/samples/pdf/long-tables.pdf differ diff --git a/setup.py b/setup.py index 44c7251..338ad12 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ import sys with open('README.md') as readme_file: SETUP = { "name": "pdfmajor", - "version": "1.1.11", + "version": "1.1.12", "packages": find_packages(include=['pdfmajor*']), "install_requires": [ 'pycryptodome',