|
@@ -19,7 +19,7 @@
|
|
|
return YES;
|
|
|
}
|
|
|
// 插入失败
|
|
|
- // 转换为data
|
|
|
+ // 转换为 jpg, 再插入到 document
|
|
|
NSData *data = [[[NSImage alloc] initWithContentsOfFile:imagePath] TIFFRepresentation];
|
|
|
if (!data) {
|
|
|
return NO;
|
|
@@ -33,19 +33,21 @@
|
|
|
NSData *jpgData = [bitmap representationUsingType:NSBitmapImageFileTypeJPEG properties:@{}];
|
|
|
NSString *appID = [[NSBundle mainBundle] bundleIdentifier];
|
|
|
NSString *folderPath = [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:appID] stringByAppendingPathComponent:@"KMTemp"];
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:folderPath]) {
|
|
|
+ if (![[NSFileManager defaultManager] fileExistsAtPath:folderPath]) { // 路径不存在,则去创建
|
|
|
[[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
}
|
|
|
NSString *filePath = [folderPath stringByAppendingPathComponent:@"temp_saveDocumentForCPDFDocumentInsertImage.jpg"];
|
|
|
|
|
|
BOOL result = NO;
|
|
|
- if ([jpgData writeToFile:filePath atomically:YES]) {
|
|
|
+ if ([jpgData writeToFile:filePath atomically:YES]) { // 将图片数据存入到临时路径
|
|
|
+ // 转换后再插入
|
|
|
result = [self insertPage:pageSize withImage:filePath atIndex:index];
|
|
|
}
|
|
|
+
|
|
|
+ // 清除临时数据
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
|
|
|
}
|
|
|
-
|
|
|
return result;
|
|
|
}
|
|
|
|