2011-01-27 58 views
5

我有一个问题,那就是如何将.png格式的图像转换为需要转换.pdf文件。请提出任何解决方案。如何将.png图像转换为.pdf在iphone中编程方式

谢谢 马丹磨憨

+0

请参考这个 - http://stackoverflow.com/questions/1360912/how-can-i-create-a-pdf-file-programmatically-in-an-iphone-application你会findout! – 2011-01-27 12:51:14

+0

你有一个.png文件的图像,或者你有一组图像将图像转换为pdf? – 2013-11-21 07:59:40

回答

1

真的是你的应用程序工作正常,但我需要.tif文件转换为PDF文件,并显示UIWebView的。

+0

ANURAG能否让我知道,如果找到任何解决方案:) – Mangesh 2013-05-11 07:24:51

-2
-(void)createPdf:(NSImage*)image 
{ 
    PDFDocument *pdf = [[PDFDocument alloc] init]; 
    NSImage *image = [[NSImage alloc] initWithContentsOfFile:fileName]; 
    PDFPage *page = [[PDFPage alloc] initWithImage:image]; 
    [pdf insertPage:page atIndex: [pdf pageCount]]; 
    [pdf writeToFile:path]; 
} 

使用上面的方法如下:

NSImage *image = [[NSImage alloc] initWithContentsOfFile:PATH_OF_YOUR_PNG_FILE]; 
    [self createPdf:image]; 
0

使用下面的代码从图像创建PDF文件。

UIImage* image = [UIImage imageNamed:@"sample.png"]; 
CGRect frame = CGRectMake(20, 100, 300, 60); 
NSString* fileName = @"FileName.PDF"; 

NSArray *arrayPaths = 
NSSearchPathForDirectoriesInDomains(
            NSDocumentDirectory, 
            NSUserDomainMask, 
            YES); 
NSString *path = [arrayPaths objectAtIndex:0]; 
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName]; 
// Create the PDF context using the default page size of 612 x 792. 
UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil); 
// Mark the beginning of a new page. 
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil); 

[image drawInRect:frame]; 

// Close the PDF context and write the contents out. 
UIGraphicsEndPDFContext();