Podofo适用于iOS;写入PDF文件后出现“未找到目录对象”

10

我已经为iOS构建了Podofo 0.9.3以及所有其他必要的库来支持amrv7、arm64和模拟器。我的项目运行良好,但我的问题是第二次加载文档。Podofo总是会出现“未找到目录对象”的错误。如果我在Mac上使用预览应用程序打开文档并保存它,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? 任何想法这是为什么发生的?


你能给出你的路径变量值的例子吗? - Vlad
1个回答

2

我遇到过类似的问题。问题出在NSCachesDirectory路径上。它会随着模拟器中应用程序每次运行而改变。为解决这个问题,我将我的文件路径保存为不包含缓存目录路径的形式:

- (NSString *)filePathWithoutCacheDirectoryComponent:(NSString *)fullPath {
    NSString *cacheDirectoryPath =
        NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    return [fullPath stringByReplacingOccurrencesOfString:cacheDirectoryPath withString:@""];
}

为了下次打开我的文件,我将缓存目录路径添加到其保存路径中:
NSString *cacheDirectoryPath =
        NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
fullPath = [cacheDirectoryPath stringByAppendingPathComponent:savedPathToFile];

如果你将文件保存到 NSCachesDirectory 或者 NSDocumentDirectory 中,请尝试以下操作。

您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Basel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接