小编Vin*_*nay的帖子

如何将PDF作为输入传递给打印机

我是iPhone开发的新手,我需要打印UIView.所以我将UIView转换成PDF并且它对我来说很好..但我不知道如何将这个PDF传递给打印机以便打印,任何人都可以帮助解决这个问题

提前致谢

我的代码是:

- (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    NSMutableData *pdfData = [NSMutableData data];
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    [aView.layer renderInContext:pdfContext];
    UIGraphicsEndPDFContext();
       NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}

-(void)getPDF{
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
     NSString *documentsPath = [paths objectAtIndex:0]; 
     NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myPdf"];
     NSLog(@"filePath: %@",filePath);

     NSData *pngData = [NSData dataWithContentsOfFile:filePath];
    [displayPDFView loadData:pngData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
    [self.view setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.0]];
    displayPDFView.hidden = NO;

} …
Run Code Online (Sandbox Code Playgroud)

printing pdf iphone objective-c ios

6
推荐指数
1
解决办法
4533
查看次数

发布对象是必要的吗?

我陷入了内存管理的困境.请帮我解决我的问题.

NSMutableArray *array = [[NSMutableArray alloc]init];
Object *obj = [[Object alloc]init];  
[array addObject: obj];  
[obj release];  
Run Code Online (Sandbox Code Playgroud)

是否有必要obj在上面的代码中发布?

iphone objective-c ipad ios xcode4

1
推荐指数
1
解决办法
70
查看次数

标签 统计

ios ×2

iphone ×2

objective-c ×2

ipad ×1

pdf ×1

printing ×1

xcode4 ×1