I am trying to save the PDFs of all the graphs generated by Core Plot into a single pdf file. Hence I am iterating over my graphs array and appending the NSData pdfforeach graph to pdfData and in the end writing the Pdfdata to a file. However only the pdf of the last graph in the graph array appears in the written file. Am I missing something here.
Code Snippet:
NSMutableData *pdfData = [[NSMutableData alloc] init];
for (CPTGraph *eachGraph in _graphsArray) {
NSData *pdfDataForGraph = [eachGraph dataForPDFRepresentationOfLayer];
if(pdfDataForGraph)
{
[pdfData appendData:pdfDataForGraph];
}
}
if(0 < pdfData.length)
{
NSLog(@"Content Present");
NSURL *documentPathUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString *pdfSaved = "example.pdf";
NSURL *pdfUrl = [documentPathUrl URLByAppendingPathComponent:pdfSaved];
[pdfData writeToURL:pdfUrl atomically:NO];
}