Hi, we are developing under the premium license, and try to add the text box to PDF documents. It seems very unstable to call the function Page_setAnnotEditText and often crashed when we input long text (in fact just around 100 characters). And from the thread
www.radaeepdf.com/forum/ios-dev/1129-app...age-setannotedittext, it is said that there is a fix on this function, however we still meeting the crashing issue.
Our code basically using the logic of adding popup text from the sample app, i.e. open the TextAnnotViewController and then call the add text box function as below:
-(void)vAddTextBox:(int)x :(int)y :(NSString *)text
{
struct PDFV_POS pos;
[m_view vGetPos:&pos
* m_scale :y * m_scale];
if(pos.pageno>=0)
{
PDFVPage *vpage = [m_view vGetPage:pos.pageno];
if( !vpage ) return;
PDFPage *page = [vpage GetPage];
if (!page) {
return;
}
float pWidth=[m_doc pageWidth:pos.pageno];
float pHeight=[m_doc pageHeight:pos.pageno];
float textScale=pWidth/PDF_NORMAL_SIZE_TEXT;
if (pHeight<pWidth) {
textScale=pHeight/PDF_NORMAL_SIZE_TEXT;
}
float actualTextSize = g_text_size*textScale;
UIFont *font = [UIFont fontWithName:@"STHeitiTC-Medium" size:actualTextSize];
NSString *displayText = [text stringByAppendingString:@" "];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:displayText];
[str addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, str.length)];
CGSize textBound = [str size];
PDF_RECT rect;
rect.left=pos.x;
rect.right=pos.x + textBound.width;
rect.top=pos.y;
rect.bottom=pos.y + textBound.height * 1.3;
m_modified = true;
PDFAnnot *annot = [page annotAtPoint:pos.x :pos.y];
if (!annot) {
DLog(@"New textbox is added!!!");
[page addEditTextBox:&rect :0xFF000000 :0 :0xFFFFFFFF :actualTextSize :g_text_color];
annot = [page annotAtIndex: [page annotCount] - 1];
} else {
if ([annot getEditType]==3 && [annot fieldType]==0) {
[annot getEditRect:&rect];
rect.right = rect.left + textBound.width;
rect.bottom = rect.top + textBound.height*1.3;
if ([m_delegate isTextColorChanged]) {
[annot setEditTextColor:g_text_color];
}
[annot setRect:&rect];
}
}
[annot setEditText:text];
[m_view vRenderSync:pos.pageno];
[m_doc save];
}
}
Don't know anything make it crash, please suggest, thanks.