2011-01-27 6 views
5

형식이 .png 인 .pdf 파일을 변환해야하는 한 가지 문제가 있습니다. 해결책을 제안하십시오. iphone에서 .png 이미지를 .pdf로 프로그램 방식으로 변환하는 방법

은 아래 URL에서 코드를 얻을 수 마단 모한

+0

this-이 http://stackoverflow.com/questions/1360912/how-can-i-create-a-pdf-file-programmatically-in-an-iphone-application 당신이 findout 것입니다 참조하시기 바랍니다! –

+0

.png 파일 하나의 이미지가 있거나 이미지를 pdf로 변환하는 이미지 세트가 있습니까? –

답변

1

을 이동하지만 난 pdf 파일 및 디스플레이의 UIWebView에이 .tif 파일을 변환해야합니다.

+0

ANURAG 알려주십시오. 어떤 해결책이 있으면 알려주십시오. – Mangesh

-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]; 
+2

PDFDocument 및 PDFPage 란 무엇입니까? OP는 iPhone 개발에 대해 질문했습니다. –

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(); 
관련 문제