2011-01-27 59 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();