# How to debug - no insert\_text found in new pdf

**URL:** https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201
**Category:** PyMuPDF
**Tags:** text-insertion
**Created:** [November 19, 2025, 3:39pm UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201 "2025-11-19T15:39:28Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![edzob](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@edzob](https://forum.mupdf.com/u/edzob)
#### Post date: [November 19, 2025, 3:39pm UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201/1 "2025-11-19T15:39:28Z")

</div>

Hi, my goal is to write text to a pdf. When I open the pdf I only see a white page.  
I think I have an error in my setup and not in my code. Below a minimal working example.

**Q: How can I debug this, to find out what is going on?**

Thanks, regards Edzo

- Linux fedora 6.17.7-300.fc43.x86\_64 #1 SMP PREEMPT\_DYNAMIC Sun Nov 2 15:30:09 UTC 2025 x86\_64 GNU/Linux
- Python 3.14.0
- pymupdf 1.26.6

**MWE**

```auto

import pymupdf
from pymupdf.utils import getColor

# set defaults
file_name = “PyMuPDF_test.pdf”
text_color = getColor(“black”)
font_size = 32.0
font_name = “spacemo”
p = pymupdf.Point(10, 10)
# debug reasons
text = “Some text.”

# create pdf
newDocument = pymupdf.open()
fmt = pymupdf.paper_rect(“a4”)
newPage = newDocument.new_page(
                width = fmt.width, height = fmt.height)
# write to new page
newPage.clean_contents()
newPage.insert_text = ( p,
                        text,
                        fontsize := font_size,
                        fontname := font_name,
                        color := text_color,
                        border_width := 1,
                        overlay := True
                      )
# write to disk
newDocument.save(file_name,
                 garbage = 3,
                 deflate = True,)
newDocument.close()

```

---

<div class="post-metadata">

### Author: ![Jamie\_Lemon](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.mupdf.com/jamie_lemon/32/5_2.png) [@Jamie\_Lemon](https://forum.mupdf.com/u/Jamie_Lemon)
#### Post date: [November 19, 2025, 5:25pm UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201/2 "2025-11-19T17:25:04Z")

</div>

Hi @edzob Welcome to the forum!

looking at your code doesn’t `newPage.insert_text = ( ... `redefine the function?

If I do:

```python

newPage.insert_text( p,
text,
fontsize = font_size,
color = text_color,
border_width = 1,
overlay = True )

```

Then it works okay.

---

<div class="post-metadata">

### Author: ![HaraldLieder](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.mupdf.com/haraldlieder/32/14_2.png) [@HaraldLieder](https://forum.mupdf.com/u/HaraldLieder)
#### Post date: [November 19, 2025, 8:19pm UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201/3 "2025-11-19T20:19:20Z")

</div>

Additional comments:  
Please do not use `page.clean_contents()` here. This is no longer necessary since a many versions.

---

<div class="post-metadata">

### Author: ![edzob](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@edzob](https://forum.mupdf.com/u/edzob)
#### Post date: [November 20, 2025, 7:33am UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201/4 "2025-11-20T07:33:27Z")

</div>

Dear @Jamie_Lemon . TY for your advice.

I thought at the start also this was the issue, but with this code I recieve a strange error. I thought I sort of had a new version of test\_insert that needed a different syntax. Apparantly that is not the issue.

I also tried to remove all the spaces and pot it on 1 line, same error.

So I am a bit stuck

@HaraldLieder : Thanks. I removed the line in the code below.

Error

```auto
$ python3 write_pdf.py 
  File " ****** /write_pdf.py", line 20
    fontsize = font_size,
    ^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
$ 

```

With code

```auto
import pymupdf
from pymupdf.utils import getColor

    # set defaults
file_name = "PyMuPDF_test.pdf"
text_color = getColor("black")
font_size = 32.0
font_name = "spacemo"
p = pymupdf.Point(10, 10)
    # debug reasons
text = "Some text."
    # create pdf
newDocument = pymupdf.open()
fmt = pymupdf.paper_rect("a4")
newPage = newDocument.new_page(width = fmt.width,
                                   height = fmt.height)
    # write to new page
newPage.insert_text = ( p,
                        text,
                        fontsize = font_size,
                        fontname = font_name,
                        color = text_color,
                        border_width = 1,
                        overlay = True
                      )
    # write to disk
newDocument.save(file_name,
                 garbage = 3,
                 deflate = True,)
newDocument.close()

```

---

<div class="post-metadata">

### Author: ![Jamie\_Lemon](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.mupdf.com/jamie_lemon/32/5_2.png) [@Jamie\_Lemon](https://forum.mupdf.com/u/Jamie_Lemon)
#### Post date: [November 20, 2025, 1:30pm UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201/5 "2025-11-20T13:30:35Z")

</div>

> [@edzob](#):
>
> `newPage.insert_text = ( `

I think this should be:  
`newPage.insert_text( ...`

---

<div class="post-metadata">

### Author: ![Jamie\_Lemon](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.mupdf.com/jamie_lemon/32/5_2.png) [@Jamie\_Lemon](https://forum.mupdf.com/u/Jamie_Lemon)
#### Post date: [November 20, 2025, 1:31pm UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201/6 "2025-11-20T13:31:27Z")

</div>

@edzob Please also confirm your version of PyMuPDF that you are using!

---

<div class="post-metadata">

### Author: ![edzob](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@edzob](https://forum.mupdf.com/u/edzob)
#### Post date: [November 20, 2025, 3:54pm UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201/7 "2025-11-20T15:54:21Z")

</div>

> [@Jamie\_Lemon](#):
>
> version of P

haha .. the = should be the thing. I will test..  
my dyslexia hits hard in this one

---

<div class="post-metadata">

### Author: ![edzob](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@edzob](https://forum.mupdf.com/u/edzob)
#### Post date: [November 20, 2025, 4:00pm UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201/8 "2025-11-20T16:00:34Z")

</div>

@Jamie_Lemon the wrong calling of the function was the error. **TY so much**.  
I had no clue where to find the error and now I know a little bit more.

The version of pymupdf is 1.26.6

the code now is..

```auto
import pymupdf
from pymupdf.utils import getColor

   # set defaults
file_name = “PyMuPDF_test.pdf”
text_color = getColor(“black”)
font_size = 32.0
font_name = “spacemo”
p = pymupdf.Point(10, 10)
   # debug reasons
text = “Some text.”
   # create pdf
newDocument = pymupdf.open()
fmt = pymupdf.paper_rect(“a4”)
newPage = newDocument.new_page(
                    width = fmt.width,
                    height = fmt.height
                   )
   # write to new page
newPage.insert_text( p,
                     text,
                     fontsize = font_size,
                     fontname = font_name,
                     color = text_color,
                     border_width = 1,
                     overlay = True
                   )
   # write to disk
newDocument.save(file_name,
                 garbage = 3,
                 deflate = True,)
newDocument.close()

```

---

<div class="post-metadata">

### Author: ![Jamie\_Lemon](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.mupdf.com/jamie_lemon/32/5_2.png) [@Jamie\_Lemon](https://forum.mupdf.com/u/Jamie_Lemon)
#### Post date: [November 20, 2025, 10:19pm UTC](https://forum.mupdf.com/t/how-to-debug-no-insert-text-found-in-new-pdf/201/9 "2025-11-20T22:19:00Z")

</div>

@edzob No worries! Glad you got it working okay.
