Skip to content

Commit

Permalink
Not defaulting to invoice.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedshabib authored Dec 4, 2023
1 parent 83e4eb6 commit 9f94172
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 9f94172

Please sign in to comment.