我正在处理我必须展示来自服务的报告的项目。我从服务器端获取 PDF 文件的字节数组。它包含 Arial Unicode MS 字体的一些英文和一些中文。当我得到字节数组时,我将它传递给 NSData,然后在路径上写入 PDF 文件。然后从本地文件夹中打开该文件。当我在 QLPreviewController 或 UIDocumentInteraction 中打开该文件时,我看不到中文字符。当我打印该文件时。我可以正确地看到那些字符。请有人帮助我
- (void)saveFileToPDF:(NSData *)pdfContent{
/******************************************
CHECK IF FILE ALREADY EXISTS REMOVE FIRST
*****************************************/
NSFileManager *manager = [[NSFileManager alloc] init];
if ([manager fileExistsAtPath:[self.documentsDirectory stringByAppendingPathComponent:@"/ABC.pdf"]]) {
[manager removeItemAtPath:[self.documentsDirectory stringByAppendingPathComponent:@"/ABC.pdf"] error:nil];
}
/******************************************
WRITE FILE TO PATH AS 'DIARY REPORT'
*****************************************/
self.fileURL = [NSURL fileURLWithPath:[self.documentsDirectory stringByAppendingPathComponent:@"/ABC.pdf"]];
[pdfContent writeToURL:self.fileURL atomically:YES];
[self openPreviewControllerWithPath:@"/ABC.pdf""];
}
-(void) openPreviewControllerWithPath:(NSString *) str {
Global *obj = [Global getInstance];
LocalizationSetLanguage(obj.languageSelected);
self.fileURL = [NSURL fileURLWithPath:[self.documentsDirectory stringByAppendingPathComponent:@"/ABC.pdf"]];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
if (self.isSubmitPressed) {
doneTool = [[UIBarButtonItem alloc] initWithTitle:AMLocalizedString(@"submit", @"") style:UIBarButtonItemStylePlain target:self action:@selector(onToolbarSubmitTapped)];
} else {
doneTool = [[UIBarButtonItem alloc] initWithTitle:AMLocalizedString(@"Done",@"") style:UIBarButtonItemStylePlain target:self action:@selector(onDoneTapped)];
}
printTool = [[UIBarButtonItem alloc] initWithTitle:AMLocalizedString(@"Print",@"") style:UIBarButtonItemStylePlain target:self action:@selector(onPrintTapped:)];
mytoolbar = [[UIToolbar alloc] init];
mytoolbar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
mytoolbar.tintColor = [UIColor blackColor];
NSMutableArray *items = [NSMutableArray arrayWithObjects:doneTool, spaceItem, printTool, nil];
[mytoolbar setItems:items animated:NO];
[self.view addSubview:mytoolbar];
QLPreviewController* preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
preview.delegate = self;
[self addChildViewController:preview];//view controller containment
//set the frame from the parent view
CGFloat w= super.view.frame.size.width;
CGFloat h= super.view.frame.size.height;
preview.view.frame = CGRectMake(0, 44,w, h);
[super.view addSubview:preview.view];
[preview didMoveToParentViewController:self];
//save a reference to the preview controller in an ivar
self.previewController = preview;
}
// returns the item that the preview controller should preview
- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)idx
{
return self.fileURL;
}