How can I create a single page PDF file with an array of images in ios?

I need to create a pdf file with an array of images. I have tried so many types of code, but I am not getting a solution that can help me with any body.

I tried under the code.

- (void)createPDFWithImagesArray:(NSMutableArray *)array andFileName:(NSString *)fileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *PDFPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.pdf",fileName]];

UIGraphicsBeginPDFContextToFile(PDFPath, CGRectZero, nil);
for (UIImage *image in array)
{
    // Mark the beginning of a new page.
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, image.size.width, image.size.height), nil);

    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
}
UIGraphicsEndPDFContext();
}

but it doesn’t help me.

+4
source share
1 answer

Try something like:

  [self setupPDFDocumentNamed:@"NewPDF" Width:850 Height:1100];

[self beginPDFPage];

CGRect textRect = [self addText:@"This is some nice text here, don't you agree?" 
                      withFrame:CGRectMake(kPadding, kPadding, 400, 200) fontSize:48.0f];

CGRect blueLineRect = [self addLineWithFrame:CGRectMake(kPadding, textRect.origin.y + textRect.size.height + kPadding, _pageSize.width - kPadding*2, 4) 
                                   withColor:[UIColor blueColor]];

UIImage *anImage = [UIImage imageNamed:@"tree.jpg"];
CGRect imageRect = [self addImage:anImage 
                          atPoint:CGPointMake((_pageSize.width/2)-(anImage.size.width/2), blueLineRect.origin.y + blueLineRect.size.height + kPadding)];

[self addLineWithFrame:CGRectMake(kPadding, imageRect.origin.y + imageRect.size.height + kPadding, _pageSize.width - kPadding*2, 4) 
             withColor:[UIColor redColor]];

[self finishPDF];

To give you some context, finishPDF, setupPDFDocumentNamed, beginPDFPage, addImage and addText are all working methods, and they are all part of the tutorial that I link below. I felt that it was too much to bring SO into one answer ...

More on this here - http://code.tutsplus.com/tutorials/generating-pdf-documents--mobile-11265

0

All Articles