I have used Fitz library(pymupdf sub-module) to insert text in existing pdf.
also, I have used the google trans module to translate the text
whenever I run the script the text is not rendered correctly
o/p : રવ્ નિદર નાકરાણી
Expected O/P : રવિન્દ્ર નાકરાણી
import fitz
def add_text_to_pdf(pdf_path, output_path, text_to_add):
# Open the PDF
pdf_document = fitz.open(pdf_path)
# set coordinnates for text
coordinates = (175,215)
# Get the number of pages in the PDF
num_pages = pdf_document.page_count
for page_num in range(num_pages):
# Get the page
if page_num == 2:
page = pdf_document[page_num]
new_ste = text_to_add
page.insert_text((coordinates[0], coordinates[1]), str(new_ste),fontfile = font_path ,fontsize = 13,color = (0,0,0),fontname = 'Shruti')
# Save the modified PDF
pdf_document.save(output_path)
pdf_document.close()
# Example usage
if __name__ == "__main__":
input_pdf_path = file_path
output_pdf_path = "Outpugt.pdf"
translator = Translator()
result = translator.translate('Ravindra Nakrani', src='en',dest='gu')
print(result.text)
text_to_add = result.text
add_text_to_pdf(input_pdf_path, output_pdf_path, text_to_add)

Here is a multi-language / multi-font example using Page.insert_htmlbox:
Note: I am a maintainer and the original creator of PyMuPDF.