From c96d6ad0f8b0299f84e25706a5a30522978955cc Mon Sep 17 00:00:00 2001 From: DonRenando Date: Mon, 23 Jan 2017 17:40:17 +0100 Subject: [PATCH] TG-46 fusion pdf --- backend/app/tools/FusionPdf.py | 10 ++++++++++ .../tools/{insertTemplate.py => InsertTemplate.py} | 0 backend/app/tools/fusion_pdf.py | 12 ------------ backend/tests/tools/PyPDF2/TestFusionFichiers.py | 0 backend/tests/tools/PyPDF2/__init__.py | 0 .../{testInsertTemplate.py => TestInsertTemplate.py} | 2 +- 6 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 backend/app/tools/FusionPdf.py rename backend/app/tools/{insertTemplate.py => InsertTemplate.py} (100%) delete mode 100644 backend/app/tools/fusion_pdf.py create mode 100644 backend/tests/tools/PyPDF2/TestFusionFichiers.py create mode 100644 backend/tests/tools/PyPDF2/__init__.py rename backend/tests/tools/pdfjinja/{testInsertTemplate.py => TestInsertTemplate.py} (95%) diff --git a/backend/app/tools/FusionPdf.py b/backend/app/tools/FusionPdf.py new file mode 100644 index 0000000..9c79a71 --- /dev/null +++ b/backend/app/tools/FusionPdf.py @@ -0,0 +1,10 @@ +import os +from PyPDF2 import PdfFileReader, PdfFileMerger + + +def fusion_fichiers(chemin_des_pdf, chemin_merge_pdf, nom_merge_pdf): + pdf_files = [f for f in os.listdir(chemin_des_pdf) if f.endswith("pdf")] + merger = PdfFileMerger() + for filename in pdf_files: + merger.append(PdfFileReader(os.path.join(chemin_des_pdf, filename), "rb")) + merger.write(os.path.join(chemin_merge_pdf, nom_merge_pdf)) diff --git a/backend/app/tools/insertTemplate.py b/backend/app/tools/InsertTemplate.py similarity index 100% rename from backend/app/tools/insertTemplate.py rename to backend/app/tools/InsertTemplate.py diff --git a/backend/app/tools/fusion_pdf.py b/backend/app/tools/fusion_pdf.py deleted file mode 100644 index 1447f78..0000000 --- a/backend/app/tools/fusion_pdf.py +++ /dev/null @@ -1,12 +0,0 @@ -import os -import PyPDF2 -from PyPDF2 import PdfFileReader, PdfFileMerger - -files_dir = "C:\\olatest\\app\\pdf" -pdf_files = [f for f in os.listdir(files_dir) if f.endswith("pdf")] -merger = PdfFileMerger() - -for filename in pdf_files: - merger.append(PdfFileReader(os.path.join(files_dir, filename), "rb")) - -merger.write(os.path.join(files_dir, "merged_full.pdf")) diff --git a/backend/tests/tools/PyPDF2/TestFusionFichiers.py b/backend/tests/tools/PyPDF2/TestFusionFichiers.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/tests/tools/PyPDF2/__init__.py b/backend/tests/tools/PyPDF2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/tests/tools/pdfjinja/testInsertTemplate.py b/backend/tests/tools/pdfjinja/TestInsertTemplate.py similarity index 95% rename from backend/tests/tools/pdfjinja/testInsertTemplate.py rename to backend/tests/tools/pdfjinja/TestInsertTemplate.py index d9af502..36e68f6 100644 --- a/backend/tests/tools/pdfjinja/testInsertTemplate.py +++ b/backend/tests/tools/pdfjinja/TestInsertTemplate.py @@ -5,7 +5,7 @@ from pathlib import Path from pdfjinja import PdfJinja -from app.tools.insertTemplate import remplir_template +from app.tools.InsertTemplate import remplir_template class insertTemplateTestCase(unittest.TestCase):