1
import fitz
text_rectangle = fitz.Rect(450,20,550,120)
file_handle = fitz.open(input_file)
first_page = file_handle[0]
text = 'SAS Automation'
first_page.insertTextbox(text_rectangle, f'{text}')
file_handle.save(output_file)

Above code adds text in pdf in mirror form why I dont know I tried insertText method, morph attribute with inserTextbox but still no solutions finds.you can see output hereOutPut PDF file image

Any help? Thanks In Advance

3 Answers3

3

This usually happens when the pdf has its own orientations, etc. Using page.clean_contents() standardizes the page and should be used before the first insertion of any item.

0

in my case, it seems to be an issue with the PDF file. i fixed it by generating another copy of the pdf file. i used photoshop then save as PDF. you can also try "Print to PDF". HTH

  • Your answer is ambiguous. Please, explain about the reasons. Why your solution should be worked? – Hamed Baziyad Jul 04 '20 at 08:02
  • i have no idea either. i just read from another thread that there is something how the PDF was generated. PyMuPDF has no mirror parameter, only rotation. so I decided to test another PDF file, and the mirror issue was not present. – Gingerbytes Jul 05 '20 at 11:07
0

I tried updating my existing pdf file. but it wasn't the correct solution to overcome this problem. Finally, I tried by creating new pdf file.

file_handle = fitz.open()  
first_page = file_handle.newPage() #file_handle[0] is getting issue
Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39