簡體   English   中英

適用於iOS的Podofo;編寫PDF文件后“找不到目錄對象”

[英]Podofo for iOS; “Catalog object not found” after writing a PDF file

我已經為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嗎? 知道為什么會這樣嗎?

我遇到了類似的問題。 問題出在NSCachesDirectory路徑上。 它隨着模擬器中的每次運行而變化。 為了解決這個問題,我保存了我的文件的路徑,沒有路徑到緩存目錄:

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

下次我將caches目錄路徑添加到其保存的路徑時打開我的文件:

NSString *cacheDirectoryPath =
        NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
fullPath = [cacheDirectoryPath stringByAppendingPathComponent:savedPathToFile];

因此,如果您將文件保存到NSCachesDirectoryNSDocumentDirectory,請嘗試此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM