file_path = itsm.getParameter('File_Path') ##Provide your file path here which to be edited (e.g) C:\\Users\\user1\\Downloads\\sample.prn
New_file = itsm.getParameter('New_File_Name') ## provide name for your converted file with extention (e.g) conversion file.prn
import binascii
import re
import os
import subprocess
import ctypes
remove_char = "0d"
non_remove_char = "0d0a"
l = []

with open(file_path, 'rb') as f:
    hexdata = binascii.hexlify(f.read())
    l.append(hexdata)
    val = re.findall(remove_char+"..",hexdata)
f.close()

for i in val:
    if i == non_remove_char:
        pass
    else:
        new= l[0]
        del l[:]
        string = new.replace(i,i[-2:])
        l.append(string)
new_file = "C:\\"+New_file
if os.path.exists(new_file):
    os.remove(new_file)
    with open(new_file,"wb") as f:
        f.write(bytes(l[-1].decode("hex").encode('utf-8')))
    f.close()
    print("Your "+New_file+" is saved in "+new_file)
else:
    with open(new_file,"wb") as f:
        f.write(bytes(l[-1].decode("hex").encode('utf-8')))
    f.close()
    print("Your "+New_file+" is saved in "+new_file)

 
