Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF
  • Page:
  • 1

TOPIC:

Edit pdf hangs 6 years 5 months ago #13070

  • psonawane
  • psonawane's Avatar Topic Author
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 1
  • Thank you received: 0
I am using following code to set text fields in pdf. But the app hangs

{
PDFDoc *document = [[PDFDoc alloc] init];
@try {
if ([document open:url :NULL] != 0) {
return NULL;
}
int pageCount = document.pageCount;
for (int i = 0; i < pageCount; i++) {
PDFPage *page = [document page:i];
[page objsStart];
int annotCount = [page annotCount];
for (int j = 0; j < annotCount; j++) {
PDFAnnot *annotation = [page annotAtIndex:j];
NSString *code = [annotation getEditText];
NSString *replacement = [codes objectForKey:code];
if(replacement && ![replacement isEqualToString:@"null"]){
[annotation setEditText:replacement];
}
}
page = nil;
}
} @finally {
if([document canSave]) {
[document save];
}
return url;
}
}

I keep getting this error: THREAD WARNING: took '601.202881' ms. Plugin should use a background thread.

Any idea how to solve this issue?

Please Log in or Create an account to join the conversation.

Edit pdf hangs 6 years 5 months ago #13072

  • emanuele
  • emanuele's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 580
  • Thank you received: 67
Hi,

this code seems to work correctly, but you should call it when the pdf is closed.
If you call it when the pdf is opened, "document" var will be destroyed and the reader doesn't have a valid pdf instance anymore.
To avoid it, you can add a parameter to you method to get the current document instance.
Something like this:
+ (void)testMethod:(PDFDoc *)document
{
    @try {
        int pageCount = document.pageCount;
        for (int i = 0; i < pageCount; i++) {
            PDFPage *page = [document page:i];
            [page objsStart];
            int annotCount = [page annotCount];
            for (int j = 0; j < annotCount; j++) {
                PDFAnnot *annotation = [page annotAtIndex:j];
                //NSString *code = [annotation getEditText];
                NSString *replacement = @"test";
                if(replacement && ![replacement isEqualToString:@"null"]){
                    [annotation setEditText:replacement];
                }
            }
            page = nil;
        }
    } @finally {
        if([document canSave]) {
            [document save];
        }
    }
}
The following user(s) said Thank You: pooja

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum