mirror of
				https://github.com/Frooodle/Stirling-PDF.git
				synced 2025-10-25 11:17:28 +02:00 
			
		
		
		
	change from pypdf2 to pypdf (#2666)
# Description addition to #2636 ## Checklist - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have performed a self-review of my own code - [ ] I have attached images of the change if it is UI based - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] If my code has heavily changed functionality I have updated relevant docs on [Stirling-PDFs doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) - [x] My changes generate no new warnings - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only)
This commit is contained in:
		
							parent
							
								
									cce4693aea
								
							
						
					
					
						commit
						b2da426cc1
					
				| @ -8,4 +8,3 @@ | |||||||
| 
 | 
 | ||||||
| </body> | </body> | ||||||
| </html> | </html> | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -18,4 +18,4 @@ def after_scenario(context, scenario): | |||||||
|     # Remove any temporary files |     # Remove any temporary files | ||||||
|     for temp_file in os.listdir('.'): |     for temp_file in os.listdir('.'): | ||||||
|         if temp_file.startswith('genericNonCustomisableName') or temp_file.startswith('temp_image_'): |         if temp_file.startswith('genericNonCustomisableName') or temp_file.startswith('temp_image_'): | ||||||
|             os.remove(temp_file) |             os.remove(temp_file) | ||||||
|  | |||||||
| @ -1,7 +1,8 @@ | |||||||
| import os | import os | ||||||
| import requests | import requests | ||||||
| from behave import given, when, then | from behave import given, when, then | ||||||
| from PyPDF2 import PdfWriter, PdfReader | from pypdf import PdfWriter, PdfReader | ||||||
|  | from pypdf.errors import PdfReadError | ||||||
| import io | import io | ||||||
| import random | import random | ||||||
| import string | import string | ||||||
| @ -42,7 +43,7 @@ def step_use_example_file(context, filePath, fileInput): | |||||||
|     context.file_name = filePath.split('/')[-1] |     context.file_name = filePath.split('/')[-1] | ||||||
|     if not hasattr(context, 'files'): |     if not hasattr(context, 'files'): | ||||||
|         context.files = {} |         context.files = {} | ||||||
|      | 
 | ||||||
|     # Ensure the file exists before opening |     # Ensure the file exists before opening | ||||||
|     try: |     try: | ||||||
|         example_file = open(filePath, 'rb') |         example_file = open(filePath, 'rb') | ||||||
| @ -165,17 +166,17 @@ def step_pdf_contains_pages_with_random_text(context, page_count): | |||||||
|     buffer = io.BytesIO() |     buffer = io.BytesIO() | ||||||
|     c = canvas.Canvas(buffer, pagesize=letter) |     c = canvas.Canvas(buffer, pagesize=letter) | ||||||
|     width, height = letter |     width, height = letter | ||||||
|      | 
 | ||||||
|     for _ in range(page_count): |     for _ in range(page_count): | ||||||
|         text = ''.join(random.choices(string.ascii_letters + string.digits, k=100)) |         text = ''.join(random.choices(string.ascii_letters + string.digits, k=100)) | ||||||
|         c.drawString(100, height - 100, text) |         c.drawString(100, height - 100, text) | ||||||
|         c.showPage() |         c.showPage() | ||||||
|          | 
 | ||||||
|     c.save() |     c.save() | ||||||
|      | 
 | ||||||
|     with open(context.file_name, 'wb') as f: |     with open(context.file_name, 'wb') as f: | ||||||
|         f.write(buffer.getvalue()) |         f.write(buffer.getvalue()) | ||||||
|          | 
 | ||||||
|     context.files[context.param_name].close() |     context.files[context.param_name].close() | ||||||
|     context.files[context.param_name] = open(context.file_name, 'rb') |     context.files[context.param_name] = open(context.file_name, 'rb') | ||||||
| 
 | 
 | ||||||
| @ -184,16 +185,16 @@ def step_pdf_pages_contain_text(context, text): | |||||||
|     buffer = io.BytesIO() |     buffer = io.BytesIO() | ||||||
|     c = canvas.Canvas(buffer, pagesize=letter) |     c = canvas.Canvas(buffer, pagesize=letter) | ||||||
|     width, height = letter |     width, height = letter | ||||||
|      | 
 | ||||||
|     for _ in range(len(PdfReader(context.file_name).pages)): |     for _ in range(len(PdfReader(context.file_name).pages)): | ||||||
|         c.drawString(100, height - 100, text) |         c.drawString(100, height - 100, text) | ||||||
|         c.showPage() |         c.showPage() | ||||||
|          | 
 | ||||||
|     c.save() |     c.save() | ||||||
|      | 
 | ||||||
|     with open(context.file_name, 'wb') as f: |     with open(context.file_name, 'wb') as f: | ||||||
|         f.write(buffer.getvalue()) |         f.write(buffer.getvalue()) | ||||||
|          | 
 | ||||||
|     context.files[context.param_name].close() |     context.files[context.param_name].close() | ||||||
|     context.files[context.param_name] = open(context.file_name, 'rb') |     context.files[context.param_name] = open(context.file_name, 'rb') | ||||||
| 
 | 
 | ||||||
| @ -345,7 +346,7 @@ def step_check_response_pdf_page_count(context, page_count): | |||||||
| def step_check_response_zip_file_count(context, file_count): | def step_check_response_zip_file_count(context, file_count): | ||||||
|     response_file = io.BytesIO(context.response.content) |     response_file = io.BytesIO(context.response.content) | ||||||
|     with zipfile.ZipFile(io.BytesIO(response_file.getvalue())) as zip_file: |     with zipfile.ZipFile(io.BytesIO(response_file.getvalue())) as zip_file: | ||||||
|       actual_file_count = len(zip_file.namelist()) |         actual_file_count = len(zip_file.namelist()) | ||||||
|     assert actual_file_count == file_count, f"Expected {file_count} files but got {actual_file_count} files" |     assert actual_file_count == file_count, f"Expected {file_count} files but got {actual_file_count} files" | ||||||
| 
 | 
 | ||||||
| @then('the response ZIP file should contain {doc_count:d} documents each having {pages_per_doc:d} pages') | @then('the response ZIP file should contain {doc_count:d} documents each having {pages_per_doc:d} pages') | ||||||
| @ -354,7 +355,7 @@ def step_check_response_zip_doc_page_count(context, doc_count, pages_per_doc): | |||||||
|     with zipfile.ZipFile(io.BytesIO(response_file.getvalue())) as zip_file: |     with zipfile.ZipFile(io.BytesIO(response_file.getvalue())) as zip_file: | ||||||
|         actual_doc_count = len(zip_file.namelist()) |         actual_doc_count = len(zip_file.namelist()) | ||||||
|         assert actual_doc_count == doc_count, f"Expected {doc_count} documents but got {actual_doc_count} documents" |         assert actual_doc_count == doc_count, f"Expected {doc_count} documents but got {actual_doc_count} documents" | ||||||
|          | 
 | ||||||
|         for file_name in zip_file.namelist(): |         for file_name in zip_file.namelist(): | ||||||
|             with zip_file.open(file_name) as pdf_file: |             with zip_file.open(file_name) as pdf_file: | ||||||
|                 reader = PdfReader(pdf_file) |                 reader = PdfReader(pdf_file) | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| behave | behave | ||||||
| requests | requests | ||||||
| PyPDF2 | pypdf | ||||||
| reportlab | reportlab | ||||||
| PyCryptodome | PyCryptodome | ||||||
|  | |||||||
| @ -231,9 +231,9 @@ pycryptodome==3.21.0 \ | |||||||
|     --hash=sha256:f7787e0d469bdae763b876174cf2e6c0f7be79808af26b1da96f1a64bcf47297 \ |     --hash=sha256:f7787e0d469bdae763b876174cf2e6c0f7be79808af26b1da96f1a64bcf47297 \ | ||||||
|     --hash=sha256:ff99f952db3db2fbe98a0b355175f93ec334ba3d01bbde25ad3a5a33abc02b58 |     --hash=sha256:ff99f952db3db2fbe98a0b355175f93ec334ba3d01bbde25ad3a5a33abc02b58 | ||||||
|     # via -r cucumber\requirements.in |     # via -r cucumber\requirements.in | ||||||
| pypdf2==3.0.1 \ | pypdf==5.1.0 \ | ||||||
|     --hash=sha256:a74408f69ba6271f71b9352ef4ed03dc53a31aa404d29b5d31f53bfecfee1440 \ |     --hash=sha256:3bd4f503f4ebc58bae40d81e81a9176c400cbbac2ba2d877367595fb524dfdfc \ | ||||||
|     --hash=sha256:d16e4205cfee272fbdc0568b68d82be796540b1537508cef59388f839c191928 |     --hash=sha256:425a129abb1614183fd1aca6982f650b47f8026867c0ce7c4b9f281c443d2740 | ||||||
|     # via -r cucumber\requirements.in |     # via -r cucumber\requirements.in | ||||||
| reportlab==4.2.5 \ | reportlab==4.2.5 \ | ||||||
|     --hash=sha256:5cf35b8fd609b68080ac7bbb0ae1e376104f7d5f7b2d3914c7adc63f2593941f \ |     --hash=sha256:5cf35b8fd609b68080ac7bbb0ae1e376104f7d5f7b2d3914c7adc63f2593941f \ | ||||||
| @ -249,6 +249,10 @@ six==1.17.0 \ | |||||||
|     # via |     # via | ||||||
|     #   behave |     #   behave | ||||||
|     #   parse-type |     #   parse-type | ||||||
|  | typing-extensions==4.12.2 \ | ||||||
|  |     --hash=sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d \ | ||||||
|  |     --hash=sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8 | ||||||
|  |     # via pypdf | ||||||
| urllib3==2.3.0 \ | urllib3==2.3.0 \ | ||||||
|     --hash=sha256:1cee9ad369867bfdbbb48b7dd50374c0967a0bb7710050facf0dd6911440e3df \ |     --hash=sha256:1cee9ad369867bfdbbb48b7dd50374c0967a0bb7710050facf0dd6911440e3df \ | ||||||
|     --hash=sha256:f8c5449b3cf0861679ce7e0503c7b44b5ec981bec0d1d3795a07f1ba96f0204d |     --hash=sha256:f8c5449b3cf0861679ce7e0503c7b44b5ec981bec0d1d3795a07f1ba96f0204d | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user