2011-01-27 10 views
5

Ho un problema, ovvero come convertire l'immagine del formato .png è necessario convertire il file .pdf. Si prega di suggerire qualsiasi soluzione.Come convertire l'immagine .png in .pdf in iphone programmaticamente

Grazie, Madan Mohan

+0

si rimanda questo- http://stackoverflow.com/questions/1360912/how-can-i-create-a-pdf-file-programmatically-in-an-iphone-application voi findout! –

+0

hai una singola immagine di file .png o hai un set di immagini per convertire l'immagine in pdf? –

risposta

1

Davvero l'applicazione funziona bene, ma ho bisogno di convertire tif file per file pdf e la visualizzazione UIWebView.

+0

ANURAG PUOI FACILMENTE FARMI CONOSCERE SE TROVATO QUALSIASI SOLUZIONE :) – 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]; 
} 

utilizzare il metodo di cui sopra come segue:

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

Che cos'è PDFDocument e PDFPage qui? OP ha chiesto dello sviluppo di iPhone. –

0

Usa seguente codice per creare file PDF da immagine.

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