我正在嘗試通過將簡單的html
寫入我的iOS應用的.docx文件來創建一個word文件。內容html
有一些img標籤以及圖像的絕對路徑。創建的文件在從同一臺計算機(從模擬器創建的位置訪問它)訪問時工作正常,但是當我嘗試將docx
發送給其他人時,它丟失了圖像。我正在使用下面的代碼來創建和寫入文件。使用目標創建包含圖像的word文件c
我希望它嵌入到我的docx文件中。我如何實現這一目標?
NSString *userText = @"Hello, world!";
NSMutableString *html = [NSMutableString stringWithFormat:@"<html><body><h1>%@</h1><hr><br/> <img src=\"icon.png\"/></body></html>", userText];
NSString *docsFolder = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *filename = [docsFolder stringByAppendingPathComponent:@"sample.docx"];
NSError *error;
[html writeToFile:filename atomically:NO encoding:NSUTF8StringEncoding error:&error];
if (error) {
NSLog(@"Error occured");
}
我非常懷疑,簡單地將html內容寫入擴展名爲「.docx」的文件使其成爲有效的docx文件。 –
事實上,據我所知,docx文件實際上只是zip檔案,這就是文檔如何攜帶圖像。 –