How to programmatically convert .png image to .pdf in iOS

How to convert a .png image to a .pdf file?

+5
source share
4 answers

you can get the code below the url. Go through this ........

http://ipdfdev.com/2011/04/22/convert-an-image-to-pdf-on-the-iphone-and-ipad/

+3
source

Indeed your application works fine, but I need to convert the .tif file to pdf file and display uiwebview.

+1
source

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

All Articles