1

私は、サービスからのレポートを表示する必要があるプロジェクトに取り組んでいます。サーバー側から 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;
}
4

0 に答える 0