diff --git a/main.py b/main.py index 58e7c9c..e825e03 100644 --- a/main.py +++ b/main.py @@ -23,11 +23,11 @@ @app.post("/upload") -async def upload_files(pdf_file: UploadFile = File(...), xml_file: UploadFile = File(...)): +async def upload_files(pdf_file: UploadFile = File(...), xml_file: UploadFile = File(...),xml_file_name=None): session_id = secrets.token_hex(8) pdf_file_path = await save_temp_file(await pdf_file.read(), '.pdf', session_id) xml_file_path = await save_temp_file(await xml_file.read(), '.xml', session_id) - ps_file = await create_post_script_file(xml_file_path, session_id) + ps_file = await create_post_script_file(xml_file_path, session_id,xml_file_name=xml_file_name) result_file_path = os.path.join(tempfile.mkdtemp(), session_id) + '.pdf' command = f"gs -sDEVICE=pdfwrite -dNOSAFER -dPDFA=3 -sColorConversionStrategy=RGB -dPDFACompatibilityPolicy=2 -o {result_file_path} {pdf_file_path} {ps_file} -dDEBUG" subprocess.run(command, shell=True) diff --git a/utils.py b/utils.py index 69d5f4a..a36bdda 100644 --- a/utils.py +++ b/utils.py @@ -28,8 +28,8 @@ async def save_temp_file(file_data: bytes, file_extension: str, folder: str) -> return temp_file_path -async def create_post_script_file(xml_file_path: str, session_id): - content = ps_content_template.format(xml_path=xml_file_path, xml_filename='invoice.xml', gs_version=get_gs_version()) +async def create_post_script_file(xml_file_path: str, session_id,xml_file_name=None): + content = ps_content_template.format(xml_path=xml_file_path, xml_filename=xml_file_name or 'invoice.xml', gs_version=get_gs_version()) return await save_temp_file(content.encode('utf-8'), '.ps', session_id) def get_gs_version():