#! /usr/local/bin/python -- coding: utf-8 -- The concept behind this code is taken from…
- User
#! /usr/local/bin/python
-- coding: utf-8 --
The concept behind this code is taken from page
http://stackoverflow.com/questions/17850227/text-replace-in-docx-and-save-the-changed-file-with-python-docx
import os import sys import getopt import xml.etree.ElementTree as ET
from docx import Document
from XmlExtract import extract_xml from XmlExtract import create_newdoc from BaminiDict import bamini_dict from AmudhamDict import amudham_dict from AdhawinTamilDict import adhawintamil_dict from TamilFancyDict import tamilfancy_dict
Global variables
english_fonts = ["Times New Roman"]
Functions....
def usage(): print "" print "This tool converts word document (.docx) file with Bamini font to" print "Unicode font without changing the format of the document" print "" print "usage: python DocxUnicodeConv.py -i [ -p ]" print ""
def print_run(run): print "run font = "+str(run.font.name) print "run style.font = "+str(run.style.font.name) print "run text = "+run.text
def convert_amudham(wg): text = wg.encode("utf-8") for key in amudham_dict.keys(): text = text.replace(str(key), str(amudham_dict.get(key))) print "Amudham: "+text return text.decode("utf-8")
def convert_bamini(wg): text = wg.encode("utf-8") for key in bamini_dict.keys(): text = text.replace(str(key), str(bamini_dict.get(key))) print "Bamini: "+text return text.decode("utf-8")
def convert_tamilfancy(wg): text = wg.encode("utf-8") # dependent vowel here comes with 2 bytes igh = 'à' pos = text.find(igh) if pos != -1: # found! swap characters round the vowel to render it correctly in unicode ltext = list(text) temp = ltext[pos+2] ltext[pos+2] = ltext[pos-1] ltext[pos-1] = temp text = "".join(ltext) print text
code# real conversion for key in tamilfancy_dict.keys(): text = text.replace(str(key), str(tamilfancy_dict.get(key))) print "Tamil_Fancy: "+text return text.decode("utf-8")def convert_adhawintamil(wg): text = wg.encode("utf-8") for key in adhawintamil_dict.keys(): text = text.replace(str(key), str(adhawintamil_dict.get(key))) print "Adhawin-Tamil: "+text return text.decode("utf-8")
arg1: run object, arg2: paragraph font
def convert_runfont(run, p_font): print_run(run) r_font = run.font.name
code - Assistant
- User
corect this code
- Assistant