2011-01-27 17 views
5

Tengo un problema, que es cómo convertir la imagen del formato .png necesario para convertir el archivo .pdf. Por favor sugiera cualquier solución.Cómo convertir la imagen .png a .pdf en iphone programáticamente

Gracias, Madan Mohan

+0

remítase esto- http://stackoverflow.com/questions/1360912/how-can-i-create-a-pdf-file-programmatically-in-an-iphone-application que se findout! –

+0

¿tiene una sola imagen del archivo .png o tiene un conjunto de imágenes para convertir la imagen al pdf? –

Respuesta

1

realmente su aplicación funcionando bien pero necesito para convertir tif archivo a archivo PDF y UIWebView pantalla.

+0

ANURAG PUEDE USTED FAVOR DEJARME SABER, SI SE ENCUENTRA CUALQUIER SOLUCIÓN :) – 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]; 
} 

utilizar el método anterior de la siguiente manera:

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

¿Qué es PDFDocument y PDFPage aquí? OP ha preguntado sobre el desarrollo de iPhone. –

0

Use el código siguiente para crear un archivo PDF a partir de imágenes.

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();