我正在制作一个项目,我必须在该项目中显示来自服务的报告。我从服务器端获取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;
}