我已经为iOS编译了GDAL 1.11.0。我可以列出所有驱动程序,但如果我打开一个已知的Georeferenced PDF,我会收到错误4 ...无法识别为支持的文件格式。我正在尝试使用geoPDF文件开发一个映射应用程序。这是我的代码;
-(void)gdalTests
{
NSLog(@"GDAL Testing");
GDALAllRegister();
int a = GDALGetDriverCount();
for (int b=1; b<a; b++) {
NSLog(@"GDAL Driver (%d) %s",b,GDALGetDriverLongName(GDALGetDriver(b)));
if (b==95) {
GDALDriverH drv = GDALGetDriver(b);
GDALRegisterDriver(drv);
NSLog(@"PDF DRIVER REGISTERED");
}
}
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"9030-4N KURRAJONG" ofType:@"pdf"];
GDALDatasetH dataset = GDALOpen ([filePath cStringUsingEncoding:[NSString defaultCStringEncoding]], GA_ReadOnly);
}
以下是错误输出的一部分。
2015-03-17 16:52:05.800 pdfTest[46322:4110504] GDAL Driver (94) HF2/HFZ heightfield raster
2015-03-17 16:52:05.800 pdfTest[46322:4110504] GDAL Driver (95) Geospatial PDF
2015-03-17 16:52:05.800 pdfTest[46322:4110504] PDF DRIVER REGISTERED
2015-03-17 16:52:05.800 pdfTest[46322:4110504] GDAL Driver (96) OziExplorer Image File
2015-03-17 16:52:05.800 pdfTest[46322:4110504] GDAL Driver (97) USGS LULC Composite Theme Grid
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (98) Arc/Info Export E00 GRID
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (99) ZMap Plus Grid
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (100) NOAA NGS Geoid Height Grids
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (101) MBTiles
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (102) IRIS data (.PPI, .CAPPi etc)
ERROR 4: `/Users/michealcumming/Library/Developer/CoreSimulator/Devices/83827FA6-0626-4A6F-8A43-516AD495430B/data/Containers/Bundle/Application/4249E572-0813-4C79-87BF-B1406E139552/pdfTest.app/9030-4N KURRAJONG.pdf' not recognised as a supported file format.
答案 0 :(得分:1)
我使用https://github.com/yllan/YLPDFKit解决了这个问题 以下是用于访问文档数据的代码。我希望这会对你有所帮助。
NSString *documentName = @"9030-4N KURRAJONG";
NSString *filePath = [[NSBundle mainBundle]pathForResource:documentName ofType:@"pdf"];
NSURL *documentUrl = [NSURL fileURLWithPath:filePath];
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)documentUrl);
CGPDFStringRef string;
CGPDFDictionaryRef infoDict;
infoDict = CGPDFDocumentGetInfo(document);
NSDictionary *d = YLGetDictionaryFromCGPDFDictionary(infoDict);
NSLog(@"DOCUMENT INFO %@",d);
CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);
NSLog(@"#rekt: %@",NSStringFromCGRect(CGPDFPageGetBoxRect(page, kCGPDFMediaBox)));
CGPDFDictionaryRef firstPage = CGPDFPageGetDictionary(page);
d = YLGetDictionaryFromCGPDFDictionary(firstPage);
NSArray *viewPortArray = [d objectForKey:@"VP"];
for (NSDictionary *d in viewPortArray) {
NSString *name = [d objectForKey:@"Name"];
NSLog(@"---- %@",name);
NSLog(@"%@",d);
}
for (int x = 0; x<5; x++) {
CGRect box = CGPDFPageGetBoxRect(page, x);
NSLog(@"PDF BOX %d = %0.4f %0.4f %0.4f %0.4f",x,box.origin.x,box.origin.y,box.size.width,box.size.height);
}