Microsoft Windows Phone 8.1 support ends (13 Jul 2017)

Microsoft has ended support for Windows Phone 8.1

Questions about iOS development and PDF

Edit pdf hangs

More
IP: 192.168.0.71 8 years 5 months ago #13070 by psonawane
Edit pdf hangs was created by psonawane
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?
More
IP: 192.168.0.71 8 years 5 months ago #13072 by emanuele
Replied by emanuele on topic Edit pdf hangs
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:
Code:
+ (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]; } } }
Time to create page: 0.436 seconds
Powered by Kunena Forum