backend improvements
- move_page - merge_all_single_pages - constructor with optional parameter
This commit is contained in:
parent
f4b8029593
commit
6b74b89029
|
@ -24,6 +24,6 @@ services:
|
||||||
./init.sh
|
./init.sh
|
||||||
"
|
"
|
||||||
ports:
|
ports:
|
||||||
- 8001:8000
|
- 8002:8000
|
||||||
|
|
||||||
|
|
||||||
|
|
2
init.sh
2
init.sh
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# (cd /app/ && pytest tests/test_pdf_util.py)
|
# (cd /app/ && pytest tests/test_pdf_util.py)
|
||||||
(cd /app/ && pytest)
|
(cd /app/ && pytest -o log_cli=true)
|
||||||
|
|
||||||
# (cd /app/ && gunicorn -w 4 -b 0.0.0.0:8000 wsgi:app)
|
# (cd /app/ && gunicorn -w 4 -b 0.0.0.0:8000 wsgi:app)
|
||||||
(cd /app/ && gunicorn --access-logfile '-' --error-logfile '-' -w 4 -b 0.0.0.0:8000 wsgi:app) # Dev (Logging to console)
|
(cd /app/ && gunicorn --access-logfile '-' --error-logfile '-' -w 4 -b 0.0.0.0:8000 wsgi:app) # Dev (Logging to console)
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
from pypdf import PdfReader, PdfWriter
|
|
||||||
import uuid
|
import uuid
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import traceback
|
||||||
|
import glob
|
||||||
|
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
from pdf_util.pdf_util import pdf_util
|
from pdf_util.pdf_util import pdf_util
|
||||||
|
|
||||||
|
base_path = "/app/projects/"
|
||||||
|
|
||||||
# Setup Logging
|
# Setup Logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
@ -23,26 +24,74 @@ logging.basicConfig(
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
base_path = "/app/projects/"
|
|
||||||
|
|
||||||
class pdf_project_manager:
|
class pdf_project_manager:
|
||||||
def __init__(self):
|
def __init__(self, uuid4=None):
|
||||||
|
if uuid4 is not None:
|
||||||
|
self.uuid = uuid4
|
||||||
|
else:
|
||||||
self.uuid = str(uuid.uuid4())
|
self.uuid = str(uuid.uuid4())
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.pdf_init = os.path.isfile('/app/projects/' + self.uuid + '/complete.pdf')
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning("Error looking up file: " + str(e))
|
||||||
|
logging.warning("Stacktrace: " + str(traceback.format_exc()))
|
||||||
self.pdf_init = False
|
self.pdf_init = False
|
||||||
self.project_name = ""
|
|
||||||
os.makedirs(base_path + self.uuid, exist_ok=True)
|
os.makedirs(base_path + self.uuid, exist_ok=True)
|
||||||
|
self.pdf_handler = None
|
||||||
|
|
||||||
|
def merge_all_single_pages(self):
|
||||||
|
listing = glob.glob(base_path + self.uuid + '/splitted/*.pdf')
|
||||||
|
listing.sort()
|
||||||
|
shutil.copyfile(listing.pop(0), base_path + self.uuid + "/complete.pdf")
|
||||||
|
|
||||||
|
for pdf_file in listing:
|
||||||
|
print(pdf_file)
|
||||||
|
pdf_util(base_path + self.uuid + "/complete.pdf").merge_pdf_with_and_location(pdf_file, base_path + self.uuid + "/tmp_complete.pdf")
|
||||||
|
shutil.copyfile(base_path + self.uuid + "/tmp_complete.pdf", base_path + self.uuid + "/complete.pdf")
|
||||||
|
os.remove(base_path + self.uuid + "/tmp_complete.pdf")
|
||||||
|
|
||||||
"""
|
|
||||||
def add_pdf(self, pdf_path):
|
def add_pdf(self, pdf_path):
|
||||||
if self.pdf_init:
|
if not self.pdf_init:
|
||||||
shutil.copyfile(pdf_path, base_path + self.uuid + "/complete.pdf")
|
shutil.copyfile(pdf_path, base_path + self.uuid + "/complete.pdf")
|
||||||
|
self.pdf_handler = pdf_util(base_path + self.uuid + "/complete.pdf")
|
||||||
|
self.pdf_init = True
|
||||||
else:
|
else:
|
||||||
shutil.copyfile(pdf_path, base_path + self.uuid + "/tmp.pdf")
|
shutil.copyfile(pdf_path, base_path + self.uuid + "/tmp.pdf")
|
||||||
pdf_util(base_path + self.uuid + "/complete.pdf").merge_pdf_with_and_location(base_path + self.uuid + "/tmp.pdf", base_path + self.uuid + "/tmp_complete.pdf")
|
pdf_util(base_path + self.uuid + "/complete.pdf").merge_pdf_with_and_location(base_path + self.uuid + "/tmp.pdf", base_path + self.uuid + "/tmp_complete.pdf")
|
||||||
shutil.copyfile(base_path + self.uuid + "/tmp_complete.pdf", base_path + self.uuid + "/complete.pdf")
|
shutil.copyfile(base_path + self.uuid + "/tmp_complete.pdf", base_path + self.uuid + "/complete.pdf")
|
||||||
os.remove(base_path + self.uuid + "/tmp_complete.pdf")
|
os.remove(base_path + self.uuid + "/tmp_complete.pdf")
|
||||||
os.remove(base_path + self.uuid + "/tmp.pdf")
|
os.remove(base_path + self.uuid + "/tmp.pdf")
|
||||||
|
self.pdf_handler = pdf_util(base_path + self.uuid + "/complete.pdf")
|
||||||
|
|
||||||
# Splitt files in all single Pages in Subdirectory...
|
self.pdf_handler.split_pdf_with_location(base_path + self.uuid + '/splitted/', True, True)
|
||||||
"""
|
|
||||||
|
def move_page(self, from_location, to_location):
|
||||||
|
try:
|
||||||
|
if from_location <= 0 or to_location <= 0:
|
||||||
|
raise ValueError("Pagenumber smaller/equal Zero")
|
||||||
|
|
||||||
|
if from_location < to_location:
|
||||||
|
shutil.move(base_path + self.uuid + '/splitted/' + str(from_location).zfill(4) + '.pdf', base_path + self.uuid + '/splitted/tmp.pdf')
|
||||||
|
for num in range(from_location, to_location):
|
||||||
|
print(num)
|
||||||
|
shutil.move(base_path + self.uuid + '/splitted/' + str(num + 1).zfill(4) + '.pdf', base_path + self.uuid + '/splitted/' + str(num).zfill(4) + '.pdf')
|
||||||
|
shutil.move(base_path + self.uuid + '/splitted/tmp.pdf', base_path + self.uuid + '/splitted/' + str(to_location).zfill(4) + '.pdf')
|
||||||
|
|
||||||
|
elif from_location > to_location:
|
||||||
|
shutil.move(base_path + self.uuid + '/splitted/' + str(from_location).zfill(4) + '.pdf', base_path + self.uuid + '/splitted/tmp.pdf')
|
||||||
|
for num in reversed(range(to_location, from_location)):
|
||||||
|
print(num)
|
||||||
|
print("move: " + str(num).zfill(4) + " | to: " + str(num + 1).zfill(4))
|
||||||
|
shutil.move(base_path + self.uuid + '/splitted/' + str(num).zfill(4) + '.pdf', base_path + self.uuid + '/splitted/' + str(num + 1).zfill(4) + '.pdf')
|
||||||
|
shutil.move(base_path + self.uuid + '/splitted/tmp.pdf', base_path + self.uuid + '/splitted/' + str(to_location).zfill(4) + '.pdf')
|
||||||
|
else:
|
||||||
|
raise ValueError("from_location and to_location are the same")
|
||||||
|
|
||||||
|
self.merge_all_single_pages()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logging.error("Error while moving page: " + str(e))
|
||||||
|
logging.error("Stacktrace: " + str(traceback.format_exc()))
|
||||||
|
|
|
@ -24,22 +24,24 @@ class pdf_util:
|
||||||
self.file_name = os.path.basename(file_path)
|
self.file_name = os.path.basename(file_path)
|
||||||
self.file_name_wo_extension = os.path.splitext(os.path.basename(file_path))[0]
|
self.file_name_wo_extension = os.path.splitext(os.path.basename(file_path))[0]
|
||||||
|
|
||||||
|
def split_pdf_with_location(self, output_filepath, no_names=False, int_padding=False):
|
||||||
def split_pdf_with_location(self, output_filepath, no_names=False):
|
|
||||||
out_filenames = []
|
out_filenames = []
|
||||||
os.makedirs(os.path.dirname(output_filepath), exist_ok=True)
|
os.makedirs(os.path.dirname(output_filepath), exist_ok=True)
|
||||||
with open(self.file_path, 'rb') as pdf_file:
|
with open(self.file_path, 'rb') as pdf_file:
|
||||||
pdf_reader = PdfReader(pdf_file)
|
pdf_reader = PdfReader(pdf_file)
|
||||||
num_pages = len(pdf_reader.pages)
|
num_pages = len(pdf_reader.pages)
|
||||||
for page_num in range(num_pages):
|
for page_num in range(num_pages):
|
||||||
|
|
||||||
writer = PdfWriter()
|
writer = PdfWriter()
|
||||||
writer.add_page(pdf_reader.pages[page_num])
|
writer.add_page(pdf_reader.pages[page_num])
|
||||||
|
|
||||||
|
str_page_num = str(page_num + 1)
|
||||||
|
if int_padding:
|
||||||
|
str_page_num = str_page_num.zfill(4)
|
||||||
|
|
||||||
if no_names:
|
if no_names:
|
||||||
out_filename = os.path.dirname(output_filepath) + '/' + str(page_num + 1) + '.pdf'
|
out_filename = os.path.dirname(output_filepath) + '/' + str_page_num + '.pdf'
|
||||||
else:
|
else:
|
||||||
out_filename = os.path.dirname(output_filepath) + '/' + self.file_name_wo_extension + '_' + str(page_num + 1) + '.pdf'
|
out_filename = os.path.dirname(output_filepath) + '/' + self.file_name_wo_extension + '_' + str_page_num + '.pdf'
|
||||||
|
|
||||||
with open(out_filename, 'wb') as outfile:
|
with open(out_filename, 'wb') as outfile:
|
||||||
writer.write(outfile)
|
writer.write(outfile)
|
||||||
|
@ -48,10 +50,9 @@ class pdf_util:
|
||||||
return out_filenames
|
return out_filenames
|
||||||
|
|
||||||
# Deprecate when pdf_project_manager takes effect
|
# Deprecate when pdf_project_manager takes effect
|
||||||
def split_pdf(self):
|
def split_pdf(self, int_padding=False):
|
||||||
os.makedirs(os.path.dirname(self.file_path) + "/split_pdf", exist_ok=True)
|
os.makedirs(os.path.dirname(self.file_path) + "/split_pdf", exist_ok=True)
|
||||||
return self.split_pdf_with_location(os.path.dirname(self.file_path) + "/split_pdf/", False)
|
return self.split_pdf_with_location(os.path.dirname(self.file_path) + "/split_pdf/", False, int_padding)
|
||||||
|
|
||||||
|
|
||||||
def merge_pdf_with_and_location(self, merge_file_path, output_filepath):
|
def merge_pdf_with_and_location(self, merge_file_path, output_filepath):
|
||||||
os.makedirs(os.path.dirname(output_filepath), exist_ok=True)
|
os.makedirs(os.path.dirname(output_filepath), exist_ok=True)
|
||||||
|
@ -74,5 +75,3 @@ class pdf_util:
|
||||||
def merge_pdf_with(self, merge_file_path, merged_name="merged"):
|
def merge_pdf_with(self, merge_file_path, merged_name="merged"):
|
||||||
os.makedirs(os.path.dirname(self.file_path) + "/merge_pdf", exist_ok=True)
|
os.makedirs(os.path.dirname(self.file_path) + "/merge_pdf", exist_ok=True)
|
||||||
return self.merge_pdf_with_and_location(merge_file_path, os.path.dirname(self.file_path) + "/merge_pdf" + '/merger.pdf')
|
return self.merge_pdf_with_and_location(merge_file_path, os.path.dirname(self.file_path) + "/merge_pdf" + '/merger.pdf')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,116 @@
|
||||||
import pytest
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from pdf_util.pdf_project_manager import pdf_project_manager
|
from pdf_util.pdf_project_manager import pdf_project_manager
|
||||||
|
|
||||||
|
|
||||||
def test_basic_object_creation():
|
def test_basic_object_creation():
|
||||||
test_pdf_project_manager = pdf_project_manager()
|
test_pdf_project_manager = pdf_project_manager()
|
||||||
print(test_pdf_project_manager.uuid)
|
print(test_pdf_project_manager.uuid)
|
||||||
assert len(test_pdf_project_manager.uuid) == 36
|
assert len(test_pdf_project_manager.uuid) == 36
|
||||||
|
|
||||||
|
shutil.rmtree('/app/projects/' + test_pdf_project_manager.uuid)
|
||||||
|
|
||||||
|
|
||||||
def test_folder_creation():
|
def test_folder_creation():
|
||||||
test_pdf_project_manager = pdf_project_manager()
|
test_pdf_project_manager = pdf_project_manager()
|
||||||
print(test_pdf_project_manager.uuid)
|
print(test_pdf_project_manager.uuid)
|
||||||
assert os.path.isdir('/app/projects/' + test_pdf_project_manager.uuid)
|
assert os.path.isdir('/app/projects/' + test_pdf_project_manager.uuid)
|
||||||
|
|
||||||
|
shutil.rmtree('/app/projects/' + test_pdf_project_manager.uuid)
|
||||||
|
|
||||||
def test_Projecttest_1():
|
|
||||||
|
|
||||||
"""
|
def test_merge_all_single_pages():
|
||||||
test_project = pdf_project_manager()
|
test_pdf_project_manager = pdf_project_manager()
|
||||||
print(test_pdf_project_manager.uuid)
|
print(test_pdf_project_manager.uuid)
|
||||||
assert os.path.isdir('/app/projects/' + test_pdf_project_manager.uuid)
|
assert os.path.isdir('/app/projects/' + test_pdf_project_manager.uuid)
|
||||||
"""
|
|
||||||
|
|
||||||
assert True
|
test_pdf_project_manager.add_pdf("/app/tests/sample_pdfs/sample_10_page.pdf")
|
||||||
|
print(os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf'))
|
||||||
|
assert os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size == os.stat("/app/tests/sample_pdfs/sample_10_page.pdf").st_size
|
||||||
|
|
||||||
|
os.remove('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
assert not os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
|
||||||
|
test_pdf_project_manager.merge_all_single_pages()
|
||||||
|
print(os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf'))
|
||||||
|
assert os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size == 81291
|
||||||
|
|
||||||
|
shutil.rmtree('/app/projects/' + test_pdf_project_manager.uuid)
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_multiple_pdfs():
|
||||||
|
test_pdf_project_manager = pdf_project_manager()
|
||||||
|
print(test_pdf_project_manager.uuid)
|
||||||
|
assert os.path.isdir('/app/projects/' + test_pdf_project_manager.uuid)
|
||||||
|
|
||||||
|
test_pdf_project_manager.add_pdf("/app/tests/sample_pdfs/sample_10_page.pdf")
|
||||||
|
print(os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf'))
|
||||||
|
assert os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
|
||||||
|
print(os.path.isdir('/app/projects/' + test_pdf_project_manager.uuid + '/splitted'))
|
||||||
|
assert os.path.isdir('/app/projects/' + test_pdf_project_manager.uuid + '/splitted')
|
||||||
|
|
||||||
|
print(os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0001.pdf'))
|
||||||
|
assert os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0001.pdf')
|
||||||
|
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0001.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0001.pdf').st_size == 3167
|
||||||
|
|
||||||
|
test_pdf_project_manager.add_pdf("/app/tests/sample_pdfs/sample_2_page.pdf")
|
||||||
|
print(os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf'))
|
||||||
|
assert os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0001.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0001.pdf').st_size == 3167
|
||||||
|
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0011.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0011.pdf').st_size == 1804
|
||||||
|
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size == 48408
|
||||||
|
|
||||||
|
shutil.rmtree('/app/projects/' + test_pdf_project_manager.uuid)
|
||||||
|
|
||||||
|
|
||||||
|
def test_move_pages():
|
||||||
|
test_pdf_project_manager = pdf_project_manager()
|
||||||
|
print(test_pdf_project_manager.uuid)
|
||||||
|
assert os.path.isdir('/app/projects/' + test_pdf_project_manager.uuid)
|
||||||
|
|
||||||
|
test_pdf_project_manager.add_pdf("/app/tests/sample_pdfs/sample_10_page.pdf")
|
||||||
|
test_pdf_project_manager.add_pdf("/app/tests/sample_pdfs/sample_2_page.pdf")
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size == 48408
|
||||||
|
|
||||||
|
os.remove('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
assert not os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
test_pdf_project_manager.move_page(1, 4)
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0004.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0004.pdf').st_size == 3167
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size == 83909
|
||||||
|
|
||||||
|
os.remove('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
assert not os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
test_pdf_project_manager.move_page(4, 1)
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0001.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0001.pdf').st_size == 3167
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size == 83908
|
||||||
|
|
||||||
|
os.remove('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
assert not os.path.isfile('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf')
|
||||||
|
|
||||||
|
test_pdf_project_manager.move_page(1, 12)
|
||||||
|
test_pdf_project_manager.move_page(12, 2)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/splitted/0002.pdf').st_size == 3167
|
||||||
|
print(os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size)
|
||||||
|
assert os.stat('/app/projects/' + test_pdf_project_manager.uuid + '/complete.pdf').st_size == 83909
|
||||||
|
|
||||||
|
shutil.rmtree('/app/projects/' + test_pdf_project_manager.uuid)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import pytest
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from pdf_util.pdf_util import pdf_util
|
from pdf_util.pdf_util import pdf_util
|
||||||
|
|
||||||
|
|
||||||
def test_split_pdf():
|
def test_split_pdf():
|
||||||
# Single Pages
|
# Single Pages
|
||||||
test_file = pdf_util("/app/tests/sample_pdfs/sample_1_page.pdf").split_pdf()
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_1_page.pdf").split_pdf()
|
||||||
|
@ -45,6 +45,48 @@ def test_split_pdf():
|
||||||
shutil.rmtree("/app/tests/sample_pdfs/split_pdf/")
|
shutil.rmtree("/app/tests/sample_pdfs/split_pdf/")
|
||||||
|
|
||||||
|
|
||||||
|
def test_split_pdf_int_padding():
|
||||||
|
# Single Pages
|
||||||
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_1_page.pdf").split_pdf(True)
|
||||||
|
print(test_file)
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_1_page_0001.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_1_page_0001.pdf").st_size == 69339
|
||||||
|
|
||||||
|
# Two Pages
|
||||||
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_2_page.pdf").split_pdf(True)
|
||||||
|
print(test_file)
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_2_page_0001.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_2_page_0001.pdf").st_size == 1804
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_2_page_0002.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_2_page_0002.pdf").st_size == 1405
|
||||||
|
|
||||||
|
# Ten Pages
|
||||||
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_10_page.pdf").split_pdf(True)
|
||||||
|
print(test_file)
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0001.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0001.pdf").st_size == 3167
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0002.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0002.pdf").st_size == 2888
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0003.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0003.pdf").st_size == 6670
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0004.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0004.pdf").st_size == 3043
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0005.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0005.pdf").st_size == 9968
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0006.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0006.pdf").st_size == 5367
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0007.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0007.pdf").st_size == 10093
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0008.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0008.pdf").st_size == 8578
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0009.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0009.pdf").st_size == 30188
|
||||||
|
print(os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0010.pdf").st_size)
|
||||||
|
assert os.stat("/app/tests/sample_pdfs/split_pdf/sample_10_page_0010.pdf").st_size == 3789
|
||||||
|
|
||||||
|
shutil.rmtree("/app/tests/sample_pdfs/split_pdf/")
|
||||||
|
|
||||||
|
|
||||||
def test_split_pdf_and_location():
|
def test_split_pdf_and_location():
|
||||||
# Single Pages
|
# Single Pages
|
||||||
test_file = pdf_util("/app/tests/sample_pdfs/sample_1_page.pdf").split_pdf_with_location("/tmp/test_directory/", False)
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_1_page.pdf").split_pdf_with_location("/tmp/test_directory/", False)
|
||||||
|
@ -59,7 +101,6 @@ def test_split_pdf_and_location():
|
||||||
|
|
||||||
shutil.rmtree("/tmp/test_directory/")
|
shutil.rmtree("/tmp/test_directory/")
|
||||||
|
|
||||||
|
|
||||||
# Two Pages
|
# Two Pages
|
||||||
test_file = pdf_util("/app/tests/sample_pdfs/sample_2_page.pdf").split_pdf_with_location("/tmp/test_directory/", False)
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_2_page.pdf").split_pdf_with_location("/tmp/test_directory/", False)
|
||||||
print(test_file)
|
print(test_file)
|
||||||
|
@ -78,7 +119,6 @@ def test_split_pdf_and_location():
|
||||||
|
|
||||||
shutil.rmtree("/tmp/test_directory/")
|
shutil.rmtree("/tmp/test_directory/")
|
||||||
|
|
||||||
|
|
||||||
# Ten Pages
|
# Ten Pages
|
||||||
test_file = pdf_util("/app/tests/sample_pdfs/sample_10_page.pdf").split_pdf_with_location("/tmp/test_directory/", False)
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_10_page.pdf").split_pdf_with_location("/tmp/test_directory/", False)
|
||||||
print(test_file)
|
print(test_file)
|
||||||
|
@ -129,6 +169,88 @@ def test_split_pdf_and_location():
|
||||||
shutil.rmtree("/tmp/test_directory/")
|
shutil.rmtree("/tmp/test_directory/")
|
||||||
|
|
||||||
|
|
||||||
|
def test_split_pdf_and_location_int_padding():
|
||||||
|
# Single Pages
|
||||||
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_1_page.pdf").split_pdf_with_location("/tmp/test_directory/", False, True)
|
||||||
|
print(test_file)
|
||||||
|
print(os.stat("/tmp/test_directory/sample_1_page_0001.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_1_page_0001.pdf").st_size == 69339
|
||||||
|
|
||||||
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_1_page.pdf").split_pdf_with_location("/tmp/test_directory/", True, True)
|
||||||
|
print(test_file)
|
||||||
|
print(os.stat("/tmp/test_directory/0001.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0001.pdf").st_size == 69339
|
||||||
|
|
||||||
|
shutil.rmtree("/tmp/test_directory/")
|
||||||
|
|
||||||
|
# Two Pages
|
||||||
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_2_page.pdf").split_pdf_with_location("/tmp/test_directory/", False, True)
|
||||||
|
print(test_file)
|
||||||
|
print(os.stat("/tmp/test_directory/sample_2_page_0001.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_2_page_0001.pdf").st_size == 1804
|
||||||
|
print(os.stat("/tmp/test_directory/sample_2_page_0002.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_2_page_0002.pdf").st_size == 1405
|
||||||
|
|
||||||
|
# Two Pages
|
||||||
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_2_page.pdf").split_pdf_with_location("/tmp/test_directory/", True, True)
|
||||||
|
print(test_file)
|
||||||
|
print(os.stat("/tmp/test_directory/0001.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0001.pdf").st_size == 1804
|
||||||
|
print(os.stat("/tmp/test_directory/0002.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0002.pdf").st_size == 1405
|
||||||
|
|
||||||
|
shutil.rmtree("/tmp/test_directory/")
|
||||||
|
|
||||||
|
# Ten Pages
|
||||||
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_10_page.pdf").split_pdf_with_location("/tmp/test_directory/", False, True)
|
||||||
|
print(test_file)
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0001.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0001.pdf").st_size == 3167
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0002.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0002.pdf").st_size == 2888
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0003.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0003.pdf").st_size == 6670
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0004.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0004.pdf").st_size == 3043
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0005.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0005.pdf").st_size == 9968
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0006.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0006.pdf").st_size == 5367
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0007.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0007.pdf").st_size == 10093
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0008.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0008.pdf").st_size == 8578
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0009.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0009.pdf").st_size == 30188
|
||||||
|
print(os.stat("/tmp/test_directory/sample_10_page_0010.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/sample_10_page_0010.pdf").st_size == 3789
|
||||||
|
|
||||||
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_10_page.pdf").split_pdf_with_location("/tmp/test_directory/", True, True)
|
||||||
|
print(test_file)
|
||||||
|
print(os.stat("/tmp/test_directory/0001.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0001.pdf").st_size == 3167
|
||||||
|
print(os.stat("/tmp/test_directory/0002.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0002.pdf").st_size == 2888
|
||||||
|
print(os.stat("/tmp/test_directory/0003.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0003.pdf").st_size == 6670
|
||||||
|
print(os.stat("/tmp/test_directory/0004.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0004.pdf").st_size == 3043
|
||||||
|
print(os.stat("/tmp/test_directory/0005.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0005.pdf").st_size == 9968
|
||||||
|
print(os.stat("/tmp/test_directory/0006.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0006.pdf").st_size == 5367
|
||||||
|
print(os.stat("/tmp/test_directory/0007.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0007.pdf").st_size == 10093
|
||||||
|
print(os.stat("/tmp/test_directory/0008.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0008.pdf").st_size == 8578
|
||||||
|
print(os.stat("/tmp/test_directory/0009.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0009.pdf").st_size == 30188
|
||||||
|
print(os.stat("/tmp/test_directory/0010.pdf").st_size)
|
||||||
|
assert os.stat("/tmp/test_directory/0010.pdf").st_size == 3789
|
||||||
|
|
||||||
|
shutil.rmtree("/tmp/test_directory/")
|
||||||
|
|
||||||
|
|
||||||
def test_merge_pdf_with():
|
def test_merge_pdf_with():
|
||||||
test_file = pdf_util("/app/tests/sample_pdfs/sample_1_page.pdf").merge_pdf_with("/app/tests/sample_pdfs/sample_2_page.pdf")
|
test_file = pdf_util("/app/tests/sample_pdfs/sample_1_page.pdf").merge_pdf_with("/app/tests/sample_pdfs/sample_2_page.pdf")
|
||||||
print(test_file)
|
print(test_file)
|
||||||
|
@ -168,10 +290,12 @@ def test_merge_pdf_with_and_location():
|
||||||
|
|
||||||
shutil.rmtree("/tmp/test_directory/")
|
shutil.rmtree("/tmp/test_directory/")
|
||||||
|
|
||||||
|
|
||||||
def test_rotate_pages():
|
def test_rotate_pages():
|
||||||
# Write test code to verify the behavior of the rotate_pages method
|
# Write test code to verify the behavior of the rotate_pages method
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_ocr_pages():
|
def test_ocr_pages():
|
||||||
# Write test code to verify the behavior of the rotate_pages method
|
# Write test code to verify the behavior of the rotate_pages method
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue