first commit
This commit is contained in:
commit
d0a75259ad
61
HWPToPDF.py
Normal file
61
HWPToPDF.py
Normal file
@ -0,0 +1,61 @@
|
||||
from flask import request
|
||||
|
||||
import os
|
||||
|
||||
import win32com.client
|
||||
import pythoncom
|
||||
|
||||
from PDFToJPG import converPDFToJPG
|
||||
|
||||
class converHWPtoPDF():
|
||||
def HWPtoPDF(fileNm):
|
||||
pythoncom.CoInitialize()
|
||||
|
||||
hwp_path = "E:/data"
|
||||
hwp_fileNm = fileNm
|
||||
pdf_path = "E:/pdf"
|
||||
|
||||
try:
|
||||
os.mkdir("E:/data")
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
os.mkdir(pdf_path)
|
||||
except:
|
||||
pass
|
||||
|
||||
# load hwp api
|
||||
hwp = win32com.client.gencache.EnsureDispatch('HWPFrame.HwpObject')
|
||||
hwp.RegisterModule('FilePathCheckDLL', 'FilePathCheckerModule')
|
||||
|
||||
# file_list = [f for f in os.listdir(hwp_path) if re.match('.*[.]hwp', f)]
|
||||
# for file in file_list:
|
||||
# file = os.listdir(hwp_path)
|
||||
|
||||
# pre, ext = os.path.splitext(file)
|
||||
|
||||
src = f'{hwp_path}/{hwp_fileNm}'
|
||||
oriFileNm = hwp_fileNm.replace('.hwp','')
|
||||
dst = f'{pdf_path}/{oriFileNm + ".pdf"}'
|
||||
|
||||
# open hwp file
|
||||
hwp.Open(src)
|
||||
# set save filename
|
||||
hwp.HParameterSet.HFileOpenSave.filename = dst
|
||||
# hwp.HParameterSet.HFileOpenSave.PrintMethod = '0'
|
||||
# set save format to "pdf"
|
||||
hwp.HParameterSet.HFileOpenSave.Format = "PDF"
|
||||
|
||||
# hwp.HParameterSet.HPrint.PrintMethod = f'PrintType("Nomal")';
|
||||
# hwp.HAction.GetDefault("Print", hwp.HParameterSet.HPrint.HSet)
|
||||
# hwp.HParameterSet.HPrint.PrintMethod = "0"
|
||||
# hwp.HAction.Execute("Print", hwp.HParameterSet.HPrint.HSet)
|
||||
|
||||
# save
|
||||
hwp.HAction.Execute("FileSaveAs_S", hwp.HParameterSet.HFileOpenSave.HSet)
|
||||
print(f'convert {src} to {dst}')
|
||||
|
||||
hwp.Quit()
|
||||
pythoncom.CoUninitialize()
|
||||
return dst
|
||||
10
PDFToJPG.py
Normal file
10
PDFToJPG.py
Normal file
@ -0,0 +1,10 @@
|
||||
import os
|
||||
from contextlib import suppress
|
||||
from pdf2jpg import pdf2jpg
|
||||
|
||||
class converPDFToJPG():
|
||||
def PDFToJPG(file):
|
||||
#파라미터로 pdf 파일의 절대경로를 받는다.
|
||||
dest = "E:/jpg"
|
||||
pdf2jpg.convert_pdf2jpg(file, dest, dpi = 300, pages ='ALL')
|
||||
#pdf가 여러 장으로 되어있다면 모든 장을 jpg로 바꾼다.
|
||||
BIN
__pycache__/HWPToPDF.cpython-311.pyc
Normal file
BIN
__pycache__/HWPToPDF.cpython-311.pyc
Normal file
Binary file not shown.
BIN
__pycache__/PDFToJPG.cpython-311.pyc
Normal file
BIN
__pycache__/PDFToJPG.cpython-311.pyc
Normal file
Binary file not shown.
BIN
__pycache__/reqeustFile.cpython-311.pyc
Normal file
BIN
__pycache__/reqeustFile.cpython-311.pyc
Normal file
Binary file not shown.
76
app.py
Normal file
76
app.py
Normal file
@ -0,0 +1,76 @@
|
||||
|
||||
from flask import Flask, request, send_file
|
||||
from flask_restful import Api
|
||||
from flask.views import MethodView
|
||||
|
||||
from HWPToPDF import converHWPtoPDF
|
||||
from PDFToJPG import converPDFToJPG
|
||||
from reqeustFile import RequestFileSave
|
||||
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from urllib import parse
|
||||
|
||||
import os
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
app.config['JSON_AS_ASCII'] = False
|
||||
|
||||
api = Api(app)
|
||||
|
||||
|
||||
class processingHWPtoPDF(MethodView):
|
||||
def post(self):
|
||||
|
||||
if 'file' not in request.files:
|
||||
return 'No file part in the request', 400
|
||||
|
||||
file = request.files['file']
|
||||
|
||||
print(f'fileNm {file.filename}')
|
||||
step1 = RequestFileSave.RequestFileSave(file)
|
||||
print(f'step1 {step1}')
|
||||
return send_file(converHWPtoPDF.HWPtoPDF(step1), mimetype="multipart/form-data", as_attachment=True)
|
||||
|
||||
|
||||
class processingHWPtoJPG(MethodView):
|
||||
def post(self):
|
||||
|
||||
fileNm = request.form['fileNm']
|
||||
print(f'fileNm {fileNm}')
|
||||
|
||||
converPDFToJPG.PDFToJPG(converHWPtoPDF.HWPtoPDF(fileNm))
|
||||
|
||||
return 'hello'
|
||||
|
||||
class testSendFile(MethodView):
|
||||
def get(self):
|
||||
# data = request.form['testPath']
|
||||
# returnData = data.get('testPath')
|
||||
|
||||
filePath = "E:/pdf/test.pdf"
|
||||
|
||||
return send_file(filePath, mimetype="Content-Type: multipart/form-data; charset=UTF-8", as_attachment=True)
|
||||
|
||||
# class RequestFile(MethodView):
|
||||
# def post(self):
|
||||
# RequestFileSave.RequestFileSave(request.files['file'])
|
||||
|
||||
# return ''
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def hello_world(): # put application's code here
|
||||
return 'Hello World!'
|
||||
|
||||
|
||||
api.add_resource(processingHWPtoPDF, '/converHWPtoPDF')
|
||||
api.add_resource(processingHWPtoJPG, '/converHWPtoJPG')
|
||||
api.add_resource(testSendFile, '/testSendFile')
|
||||
# api.add_resource(RequestFile, '/testRequestFile')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0')
|
||||
# app.run(host='192.168.0.11')
|
||||
23
reqeustFile.py
Normal file
23
reqeustFile.py
Normal file
@ -0,0 +1,23 @@
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from urllib.parse import unquote
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class RequestFileSave():
|
||||
def RequestFileSave(file):
|
||||
|
||||
# 클라이언트가 파일을 선택하지 않고 제출한 경우를 확인
|
||||
if file.filename == '':
|
||||
return 'No selected file', 400
|
||||
|
||||
# 파일이 존재하면, 안전한 파일 이름을 얻고 파일을 저장
|
||||
if file:
|
||||
# filename = secure_filename(file.filename)
|
||||
fileNm = unquote(file.filename)
|
||||
file.save(os.path.join('E:/data', fileNm))
|
||||
# return 'File uploaded successfully', 200
|
||||
return fileNm
|
||||
|
||||
return fileNm
|
||||
Loading…
Reference in New Issue
Block a user