PDFKIT IOS PDFDocument无法复制文本

时间:2019-01-08 04:30:59

标签: ios objective-c pdf ios-pdfkit

我试图在合并两个pdf文件后将pdf文档写入设备的文档目录。写入成功,但是当我尝试复制和粘贴文本时,它只是给了我符号。这是我的代码:

NSString *outputFileNameAndExtension = [NSString stringWithFormat:@"%@temp.pdf"];
NSString *outputPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:outputFileNameAndExtension];
NSString b64Str1 = @"J123asdasdkjajan..."
NSData* docData = [self sp_dataFromBase64String: b64Str1];
PDFDocument * doc1 = [[PDFDocument alloc]initWithData:docData];

NSString b64Str2 = @"J123asasdasdasdaqwe..."
NSData* pdfContent = [self sp_dataFromBase64String: b64Str2];                
PDFDocument * doc2 =[[PDFDocument alloc]initWithData:pdfContent];
PDFPage * page= [doc2 pageAtIndex:0];
[doc1 insertPage:page atIndex:[doc1 pageCount]];
[doc1 writeToFile:outputPath];


+ (NSData *)sp_dataFromBase64String:(NSString *)aString
{
    NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding];
    size_t outputLength;
    void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength);
    NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength];
    free(outputBuffer);
    return result;
}

0 个答案:

没有答案