我已经为iOS构建了Podofo 0.9.3以及所有其他需要的库来支持amrv7,arm64和模拟器.我的项目运行正常,但我的问题是第二次加载文档.我总是在Podofo中收到错误“Catalog object not found”.如果我使用Mac上的Preview app打开文档,并保存它,Podofo可以再次打开它.
以下是我用来打开文档并保存的代码:
self.doc = new PodoFo::PdfMemDocument([path UTF8String]);
Nsstring *tmpPath = [self createcopyForFile:self.pdfPath];
self.doc->Write([tmpPath UTF8String]);
NSData *myFile = [NSData dataWithContentsOfFile:tmpPath];
[myFile writetoFile:tmpPath atomically:YES];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if ([fileManager fileExistsAtPath:self.pdfPath] == YES) {
[fileManager removeItemAtPath:self.pdfPath error:&error];
}
[fileManager copyItemAtPath:tmpPath toPath:self.pdfPath error:&error];
错误在这里:
void PdfMemDocument::InitFromParser( PdfParser* pParser )
{
...
PdfObject* pCatalog = pTrailer->GetIndirectKey( "Root" );
if( !pCatalog )
{
PodoFO_RAISE_ERROR_INFO( ePdfError_NoObject,"Catalog object not found!" );
...
}
你们最近是否为iOS建立了Podofo?任何想法为什么会发生这种情况?
解决方法
我面临着类似的问题.问题是NSCachesDirectory的路径.它随着应用程序在模拟器中的每次运行而发生变化.要解决这个问题,我保存路径到我的文件没有缓存目录的路径:
- (Nsstring *)filePathWithoutCacheDirectoryComponent:(Nsstring *)fullPath {
Nsstring *cacheDirectoryPath =
NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)[0];
return [fullPath stringByReplacingOccurrencesOfString:cacheDirectoryPath withString:@""];
}
要打开我的文件,我下次将缓存目录路径添加到其保存的路径:
Nsstring *cacheDirectoryPath =
NSSearchPathForDirectoriesInDomains(NSCachesDirectory,YES)[0];
fullPath = [cacheDirectoryPath stringByAppendingPathComponent:savedpathToFile];
所以如果将文件保存到NSCachesDirectory或NSDocumentDirectory中,请尝试这样做.