1
votes

I am working on the project on which I have to show the report coming from service. I get bytes array of PDF file from server end. It contains some english and some chinese language in Arial Unicode MS font. When I get the byte array, I pass it to NSData and then write PDF file on path. Then open that file from local folder. When i open that file in QLPreviewController or UIDocumentInteraction, I am unable to see the chinese language characters. When I print that file. I can see thoese characters correctly. Kindly someone help me

- (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;
}
You should see answer on following question. stackoverflow.com/questions/14729803/…Afnan