Skip to content

Commit

Permalink
Merge pull request #279 from chinapandaman/PPF-278
Browse files Browse the repository at this point in the history
PPF-278: pylint and rc
  • Loading branch information
chinapandaman authored Nov 16, 2022
2 parents efe69b9 + 44f28b7 commit 524136d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion PyPDFForm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
PyPDFForm = Wrapper
PyPDFForm2 = WrapperV2

__version__ = "1.0.4"
__version__ = "1.1.0"
20 changes: 9 additions & 11 deletions PyPDFForm/core/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions PyPDFForm/core/watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 524136d

Please sign in to comment.