1

I am creating a PDF file that consists of multiple screenshot, but I am facing a problem while extracting images from multiple views. I have a mutable Array which consist of views from a view controller named as "pdfViews"

var pdfViews : NSMutableArray = NSMutableArray()

and then I am adding view

self.pdfViews.addObject(generateAllComponents(kpiName))

The generateAllComponenets(:) method creates an object of the required view controller and returns the view of that view controller.

And finally I try to convert these views into images and put those images inside an array.

for var i = 0 ; i < pdfViews.count; i++
{  
    var currentView = pdfViews.objectAtIndex(i) as! UIView
    UIGraphicsBeginImageContext(currentView.frame.size)
    currentView.layer.renderInContext(UIGraphicsGetCurrentContext())
    UIGraphicsPushContext(UIGraphicsGetCurrentContext())
    var image = UIGraphicsGetImageFromCurrentImageContext() as UIImage

    tempImageArray.addObject(image);

}

It throws an EXC_BAD_ACCESS error. But if I pass only one view i.e, if pdfViews has only 1 object then it works absolutely fine. But whenever I go with two objects in the pdfViews mutable array, it shows an error like this:

The Views to be added in pdfViews mutable array also fetches some data from server.

Plus when I tried pass an array of UIImageViews as pdfViews it also worked fine. But whenever I go with an array of views it throws this error.

Thanks in advance.

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
Vikas Soni
  • 25
  • 3
  • 1
    Welcome to Stack Overflow :) When you post a question, please make sure that you actually ask a question. From what you've written, I don't know what your question is. Thanks! – ndmeiri Jul 09 '15 at 06:32
  • 1
    My question over here is how can I create different Images so that I can add them on pdf file..... Using the above strategy I am able to convert only one view but when it comes to multiple views it throws an error of EXC_BAD_ACCESS . I just want to know how can I get Images of different views stored in the array pdfViews – Vikas Soni Jul 09 '15 at 08:37

0 Answers0