make use of pdf_project_manager
This commit is contained in:
parent
337e638ff0
commit
93b7f68b54
22
app.py
22
app.py
|
@ -1,9 +1,7 @@
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
from flask import Flask, render_template, request, redirect, jsonify, send_from_directory
|
from flask import Flask, render_template, request, redirect, jsonify, send_from_directory
|
||||||
from pathlib import Path
|
from pdf_util.pdf_project_manager import pdf_project_manager
|
||||||
from pdf_util.pdf_util import pdf_util
|
|
||||||
# from pdf_util.pdf_project_manager import pdf_project_manager
|
|
||||||
|
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
import logging
|
import logging
|
||||||
|
@ -57,20 +55,17 @@ def split_to_zip():
|
||||||
filename = os.path.join(app.config['UPLOAD_FOLDER'], pdf_file.filename)
|
filename = os.path.join(app.config['UPLOAD_FOLDER'], pdf_file.filename)
|
||||||
pdf_file.save(filename)
|
pdf_file.save(filename)
|
||||||
|
|
||||||
# Use pdf_utils Module to split File
|
# Use pdf_project_manager to split File
|
||||||
out_filenames = pdf_util(filename).split_pdf()
|
pdf_project = pdf_project_manager()
|
||||||
logging.debug(out_filenames)
|
pdf_project.add_pdf(filename)
|
||||||
|
|
||||||
logging.debug(in_filename)
|
logging.debug(in_filename)
|
||||||
logging.debug(os.path.splitext(pdf_file.filename)[0])
|
logging.debug(os.path.splitext(pdf_file.filename)[0])
|
||||||
|
|
||||||
shutil.make_archive(in_filename + '_splitted', 'zip', os.path.dirname(filename) + "/split_pdf")
|
shutil.make_archive(in_filename + '_splitted', 'zip', "/app/projects/" + pdf_project.uuid + '/splitted')
|
||||||
zip_filename = in_filename + "_splitted.zip"
|
zip_filename = in_filename + "_splitted.zip"
|
||||||
os.rename("/app/" + zip_filename, "/app/split/" + zip_filename)
|
os.rename("/app/" + zip_filename, "/app/split/" + zip_filename)
|
||||||
|
|
||||||
for temp_file in out_filenames:
|
|
||||||
Path.unlink(temp_file)
|
|
||||||
|
|
||||||
response = jsonify({"url": "/split/" + zip_filename, "name": zip_filename})
|
response = jsonify({"url": "/split/" + zip_filename, "name": zip_filename})
|
||||||
# response.headers.add("Access-Control-Allow-Origin", "*")
|
# response.headers.add("Access-Control-Allow-Origin", "*")
|
||||||
return response
|
return response
|
||||||
|
@ -99,8 +94,11 @@ def merge_to_pdf():
|
||||||
logging.debug(filename_1)
|
logging.debug(filename_1)
|
||||||
logging.debug(filename_2)
|
logging.debug(filename_2)
|
||||||
|
|
||||||
# Use pdf_utils Module to split File
|
# Use pdf_project_manager to split File
|
||||||
out_path = pdf_util(filename_1).merge_pdf_with(filename_2)
|
pdf_project = pdf_project_manager()
|
||||||
|
pdf_project.add_pdf(filename_1)
|
||||||
|
pdf_project.add_pdf(filename_2)
|
||||||
|
out_path = "/app/projects/" + pdf_project.uuid + "/complete.pdf"
|
||||||
logging.debug(out_path)
|
logging.debug(out_path)
|
||||||
os.rename(out_path, "/app/merge/merger.pdf")
|
os.rename(out_path, "/app/merge/merger.pdf")
|
||||||
|
|
||||||
|
|
|
@ -16,26 +16,23 @@
|
||||||
<input type="file" @change="handleFileSelect($event, 'merge_pdfFile_1')" accept=".pdf"><br>
|
<input type="file" @change="handleFileSelect($event, 'merge_pdfFile_1')" accept=".pdf"><br>
|
||||||
<input type="file" @change="handleFileSelect($event, 'merge_pdfFile_2')" accept=".pdf"><br>
|
<input type="file" @change="handleFileSelect($event, 'merge_pdfFile_2')" accept=".pdf"><br>
|
||||||
<button @click="uploadPDF('merge_pdfFile_1', 'merge_pdfFile_2')">Merge the two selected PDFs</button>
|
<button @click="uploadPDF('merge_pdfFile_1', 'merge_pdfFile_2')">Merge the two selected PDFs</button>
|
||||||
|
|
||||||
<div id="output">{{ outputMessage }}</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@3"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
|
||||||
<script>
|
<script>
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
data: {
|
data: {
|
||||||
split_pdfFile: null,
|
split_pdfFile: null,
|
||||||
merge_pdfFile_1: null,
|
merge_pdfFile_1: null,
|
||||||
merge_pdfFile_2: null,
|
merge_pdfFile_2: null
|
||||||
outputMessage: ''
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleFileSelect(event, inputId) {
|
handleFileSelect(event, inputId) {
|
||||||
const fileInput = event.target;
|
const fileInput = event.target;
|
||||||
this[inputId] = fileInput.files[0];
|
this[inputId] = fileInput.files[0];
|
||||||
console.debug("fileInput", fileInput)
|
console.debug("fileInput", fileInput);
|
||||||
console.debug("this[inputId]", this[inputId])
|
console.debug("this[inputId]", this[inputId]);
|
||||||
},
|
},
|
||||||
uploadPDF(fileInputId1, fileInputId2) {
|
uploadPDF(fileInputId1, fileInputId2) {
|
||||||
const file1 = this[fileInputId1];
|
const file1 = this[fileInputId1];
|
||||||
|
|
Loading…
Reference in New Issue