Delete file after printing <p>I'm trying to delete a file after printing it without success.</p> <p>Practically, I need to print a PDF which is temporary generated (with text and image), then, when the printing process is done, I'd like to remove it.</p> <p>Currently the PDF is being saved in Documents directory. Is it a good idea to save it in Temp folder? But then I'd have to remove it anyways. I also have a tableView which shows the PDF the user <strong>saved</strong>, so I need to show only those (and not those <strong>temporarily</strong> generated)</p> <p>I've tried with UIPrinterInteractionController's delegate methods, but without any luck. </p> <pre><code>-(void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController{ NSError *error; NSFileManager *fileMgr = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",PDFNameString]]; if ([fileMgr removeItemAtPath:filePath error:&amp;error] != YES) { UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:NSLocalizedString(@"UnableToDeleteFile", @"Unable to delete file: %@"),[error localizedDescription]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease]; [alert show]; } NSLog(@"Dismissed"); } </code></pre> <p>The alert view pops up just when the printing options view leaves place to "Sending to printer.." view. It doesn't even delete the file, it says</p> <p>Cocoa error code 4.</p> <p>Does anyone know what method can I use to remove a file when the printing process is done?</p> <p><strong>EDIT</strong></p> <p>I NSLog'd if the file existed, and it doesn't. How is this possible?</p>