0

I have inserted a text in an existing pdf document using page.insert_text function of pyMuPdf. However, on saving the document, the inserted text is not visible on the page at the location. There is an image that appears on the foreground and the text disappears behind it. When I search the pdf for the inserted text, a box is highlighted at the location where it is inserted but the text is not visible. This is the code:

doc = fitz.open("a.pdf")

for page in doc:

 page.insert_text((page.rect.height - 50, 50), "thistextthistext", 

fontsize=18,color=(0,0,0))

doc.saveIncr()

doc.close()

Also, what are the parameters stroke_capacity and render_mode for?

I tried to modify the overlay option to False. When the pdf loads, the inserted text briefly appears at the position but is immediately overwritten by the image, rendering the text invisible.

Thanks.

wndev1
  • 1
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 28 '22 at 14:59

1 Answers1

0

You successfully inserted text. Parameter overlay=True is required to let it appear above other content - including any images. Without having your PDF at hand I cannot tell what may be happening if an image is nevertheless able to cover your text. So please best open "Discussions" post at this website providing full data to recreate the problem.

As per your text insertion: The first parameter is the insertion point coordinates (x, y). You are specifying the x-value relative to the page height: (page.rect.height - 50, 50) WHY?

Concerning you other questions:

  • Render mode is a PDF term and controls whether text should be invisible, only character borders, or only charcter interior visible. Consult PDF or PyMuPDF documentation for more details.
  • Opacity controls the transparency of something. A float value in the interval [0, 1]. Zero means completely transparent (hence invisible), 1 means completely intransparent. Often also expressed as percentage values. PyMuPDF supports separate opacity values for a character's border and its interior.
Jorj McKie
  • 2,062
  • 1
  • 13
  • 17
  • My requirement is to paginate pdfs at that position. After many trials, this piece of code worked for most pdfs but not all. Hence the question. I will open a discussion post with details. Thanks again. – wndev1 Dec 30 '22 at 12:54