Я пытаюсь получить strings
от pdfFile
, отправленных в мое приложение через меню ... из другого приложения. я написал pdfscanner
, к которому я прохожу pdfPage
и сканер должен уволить CallBack "getString"
я использую SWIFT в основном, но сканер кода в Objective-C проблема заключается в том, что, когда я отправить pdfDoc мое приложение из другого приложения , callBack «getString» не срабатывает. и когда я отправляю один и тот же документ в свое приложение, используя URL-адрес из каталога в моем macbook pro, , тогда он работает и вызывается callBack getString. , когда я проверяю отладчик, поскольку я всегда передаю действительный CGPDFPageRef, в метод extractStringsFromPDFPage:. я также в обоих случаях имеют действительный CGPDFContentStream и CGPDFOperatorTableCGPDFScannerScan не вызывает функцию обратного вызова
вот код для сканера:
@implementation FFStringExtractor
- (instancetype)init
{
self = [super init];
if (self) {
self.pdfStrings = [[NSMutableArray alloc] init];
}
return self;
}
- (void) extractStringsFromPDFPage: (CGPDFPageRef) page {
CGPDFContentStreamRef contentStream = CGPDFContentStreamCreateWithPage(page);
// get the strings
CGPDFOperatorTableRef operatorTable = CGPDFOperatorTableCreate();
CGPDFOperatorTableSetCallback(operatorTable, "Tj", getString);
FFStringExtractor *currentExtractor = self;
CGPDFScannerRef scanner = CGPDFScannerCreate(contentStream, operatorTable, (__bridge void*)currentExtractor);
CGPDFScannerScan(scanner);
//releases
CGPDFOperatorTableRelease(operatorTable);
CGPDFScannerRelease(scanner);
CGPDFContentStreamRelease(contentStream);
}
@end
void getString (CGPDFScannerRef pageScanner, void *info) {
CGPDFStringRef pdfString;
CGPDFScannerPopString(pageScanner, &pdfString);
const unsigned char *byteString = CGPDFStringGetBytePtr(pdfString);
NSString *macRomanDecode = [NSString stringWithCString:byteString encoding:NSMacOSRomanStringEncoding];
FFStringExtractor *currentObject = (__bridge FFStringExtractor*) info;
[currentObject.pdfStrings addObject:macRomanDecode];
}
вот как я отправить документы в мое приложение от AppDelegate
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
//Get the Data from the preview open in... menu
//let macBookUrl = NSURL(fileURLWithPath: "/Users/vmalterre/Documents/Xcodes/TESTDOC.pdf")
let doc = CGPDFDocumentCreateWithURL(url)
//let doc = = CGPDFDocumentCreateWithURL(macBookUrl)
let sharedStore = FFDataStore.sharedStore
sharedStore.addFileWithDoc(doc)
return true
}
я В течение всего этого дня всякая помощь была бы весьма признательна.