From 44f28b7eaf7caadd00216c67c376b43e7267694d Mon Sep 17 00:00:00 2001 From: chinapandaman Date: Tue, 15 Nov 2022 18:04:09 -0600 Subject: [PATCH] PPF-278: rc --- PyPDFForm/__init__.py | 2 +- PyPDFForm/core/template.py | 20 +++++++++----------- PyPDFForm/core/watermark.py | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/PyPDFForm/__init__.py b/PyPDFForm/__init__.py index f6f8d8d6..128d3c4c 100644 --- a/PyPDFForm/__init__.py +++ b/PyPDFForm/__init__.py @@ -7,4 +7,4 @@ PyPDFForm = Wrapper PyPDFForm2 = WrapperV2 -__version__ = "1.0.4" +__version__ = "1.1.0" diff --git a/PyPDFForm/core/template.py b/PyPDFForm/core/template.py index ec821001..3217efac 100644 --- a/PyPDFForm/core/template.py +++ b/PyPDFForm/core/template.py @@ -24,8 +24,8 @@ def remove_all_elements(pdf: bytes) -> bytes: pdf = pdfrw.PdfReader(fdata=pdf) - for i in range(len(pdf.pages)): - elements = pdf.pages[i][TemplateCoreConstants().annotation_key] + for page in pdf.pages: + elements = page[TemplateCoreConstants().annotation_key] if elements: for j in reversed(range(len(elements))): elements.pop(j) @@ -43,8 +43,8 @@ def iterate_elements( result = [] - for i in range(len(pdf.pages)): - elements = pdf.pages[i][TemplateCoreConstants().annotation_key] + for page in pdf.pages: + elements = page[TemplateCoreConstants().annotation_key] if elements: for element in elements: if not sejda: @@ -81,8 +81,8 @@ def get_elements_by_page( result = {} - for i in range(len(pdf.pages)): - elements = pdf.pages[i][TemplateCoreConstants().annotation_key] + for i, page in enumerate(pdf.pages): + elements = page[TemplateCoreConstants().annotation_key] result[i + 1] = [] if elements: for element in elements: @@ -119,8 +119,8 @@ def get_elements_by_page_v2( result = {} - for i in range(len(pdf.pages)): - elements = pdf.pages[i][TemplateCoreConstants().annotation_key] + for i, page in enumerate(pdf.pages): + elements = page[TemplateCoreConstants().annotation_key] result[i + 1] = [] if elements: for element in elements: @@ -344,9 +344,7 @@ def assign_uuid(self, pdf: bytes) -> bytes: update_dict = { TemplateCoreConstants().annotation_field_key.replace( "/", "" - ): "{}{}{}".format( - base_key, MergeConstants().separator, existed_uuid or _uuid - ) + ): f"{base_key}{MergeConstants().separator}{existed_uuid or _uuid}" } element.update(pdfrw.PdfDict(**update_dict)) diff --git a/PyPDFForm/core/watermark.py b/PyPDFForm/core/watermark.py index 4771cbcd..e3ee9182 100644 --- a/PyPDFForm/core/watermark.py +++ b/PyPDFForm/core/watermark.py @@ -156,11 +156,11 @@ def merge_watermarks_with_pdf( pdf_file = pdfrw.PdfReader(fdata=pdf) - for i in range(len(pdf_file.pages)): + for i, page in enumerate(pdf_file.pages): if watermarks[i]: watermark = pdfrw.PdfReader(fdata=watermarks[i]) if watermark.pages: - merger = pdfrw.PageMerge(pdf_file.pages[i]) + merger = pdfrw.PageMerge(page) merger.add(watermark.pages[0]).render() return Utils().generate_stream(pdf_file)