-
| each time i use reload_page i have : i certainly do somthing wrong ! in with case reload_page assertion is fired? thank's in advance for help | 
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
| Please upload the document you're using and your Python code. Otherwise it's not possible to know what's going wrong. | 
Beta Was this translation helpful? Give feedback.
-
| just simple code as exemple on my problem : when i change somes properties on annotations in page , after that reload_page (last one) crash ! thank's in advance for explainatiçon on rugth use ! Patrice !/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from pymupdf.utils import getColor
from pymupdf import open as fitz_open
from pymupdf import mupdf 
import json
import io
import pymupdf
def try_reload(doc,page):
    pp=page
    return doc.reload_page(page)
    #return doc[page.number]
def create_my_annot_text(offset):
    annot=page.add_text_annot(pymupdf.Point(page.rect.width - 75+offset, 36+offset),
                                      text="Testde text_annot",icon="Tag")
    annot.set_colors(stroke=(1.0,
                             0.8431372549019608,
                             0.8431372549019608))
    annot.update()
    r=annot.rect
    print("annot base rect:", r,"x0:",r.x0,"y0:",r.y0)
    
    rr=pymupdf.Rect(r.x0-400,r.y0,r.x0-400+6,r.y0+6)
    annot.set_rect(rr)
    
    
    print("annot new rect:", rr)
    
    annot.set_info({'content': "text text"})
    annot.update()
    annot.set_rect(rr)
    rrr=annot.rect
    print("annot after set_info rect:", rrr)
    return r 
opacity = 0.3  # all annotation use this opacity
tcol = (0, 0, 1)  # text color
gold = (1, 1, 0)  # highlight color
bg_color = "white"
background = getColor(bg_color)  # background color
fname = "hebo"  # Helvetica Bold
fsize = 12  # generous font size
thisdir = lambda f: os.path.join(os.path.dirname(__file__), f)
#### "create or udpate file indexed"
filename="test_text_annot.pdf"
try:
    ftoto=fitz_open(thisdir(filename))
    for p in len(ftoto):
        ftoto.delepage(p)
except:
    ftoto= fitz_open()
page=ftoto.new_page()
page.insert_text(pymupdf.Point(10,36), "word0 word1 word2 word3 word4 word5 word6 word7 word8 word9 word10", 
                 fontsize=fsize, 
                 fontname=fname, 
                 color=tcol, 
                 fill=getColor("lightblue"), 
                 render_mode=0, 
                 border_width=1, 
                 encoding=pymupdf.TEXT_ENCODING_LATIN, 
                 rotate=0, 
                 morph=None,
                 overlay=True)
r=create_my_annot_text(0)
page = try_reload(ftoto,page)
create_my_annot_text(30)
pannot=page.add_polygon_annot([pymupdf.Point(r.x0-200,r.y0),
                                pymupdf.Point(r.x0,r.y0),
                                pymupdf.Point(r.x0,r.y0+200),
                                pymupdf.Point(r.x0-200,r.y0+200),
                                pymupdf.Point(r.x0-200,r.y0)])
pannot.set_colors(stroke=getColor('red'), 
                  fill=getColor('lightblue'))
pannot.set_info({'subject':"toto"})
pannot.set_border(5,style="P")
pannot.set_opacity(1.0)
pannot.update()
#rect=pannot.rect
#pannot.set_rect(pymupdf.Rect(rect.x0,rect.y0,rect.x0+6,rect.y0+6))
def get_pannots(p):
    a = p.first_annot
    res= []
    while a is not None:
        tmp=a.info
        if 'subject' in tmp:
            if "toto"==tmp['subject']:
                if (a.type[0]==mupdf.PDF_ANNOT_POLYGON ):
                    #print("findPolyAnnotationsInPage",tmp['id'])
                    res.insert(-1,a)
        a=a.next
    return res 
pannots=get_pannots(page)
for p in pannots:
    p.set_colors(stroke=getColor('blue'), 
                  fill=getColor('red'))
    p.update()
#### ------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Crash here!!!
page= ftoto.reload_page(page)
filename="./test.pdf"
ftoto.save(thisdir(filename), garbage=3, deflate=True)
ftoto.close() | 
Beta Was this translation helpful? Give feedback.
-
| I'm glad you've got thnig working. But could you still upload test_text_annot.pdf to this issue so i can have a look at what was going wrong? | 
Beta Was this translation helpful? Give feedback.
if i change get_pannots defintion to :
No errors ! !