Save a signed pdf without making a duplicate.

Good day

I’m creating an for signing pdf digitally.

I want to sign a pdf , save it without making a duplicate. I want to replace the pdf with the signed one.

I tried using the NSFileManager to create a folder in the directory, copy the pdf to the new folder but failed.

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString* baseName = [[[[m_pdfViewCtrl GetDoc] GetFileName] lastPathComponent] stringByDeletingPathExtension];
NSString* signedPDFName = [baseName stringByAppendingString:@"-signed.pdf"];

NSString *newFolderStringPath = [documentsDirectory stringByAppendingPathComponent:@“Temp”];

if ([[NSFileManager defaultManager] createDirectoryAtPath:newFolderStringPath withIntermediateDirectories:YES attributes:nil error:nil]) {

NSData *contentData = [NSData dataWithContentsOfFile:[[m_pdfViewCtrl GetDoc] GetFileName]];

[contentData writeToFile:newFolderStringPath atomically:YES];
}

I also tried saving with the pdfTron way, but it says the file doesnt exist.

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString* baseName = [[[[m_pdfViewCtrl GetDoc] GetFileName] lastPathComponent] stringByDeletingPathExtension];
NSString* signedPDFName = [baseName stringByAppendingString:@"-signed.pdf"];

NSString *newFolderStringPath = [documentsDirectory stringByAppendingPathComponent:@“Temp”];

if ([[NSFileManager defaultManager] createDirectoryAtPath:newFolderStringPath withIntermediateDirectories:YES attributes:nil error:nil]) {

[doc SaveToFile:newFolderStringPath flags:e_ptincremental];
}

I dont know if I should have permission to copy and write to… Please help,

Thank you.

Hello Sipho,

It looks like in both cases you are passing a path that points to a directory when the methods expect a path that points to a file. (The first case NSData’s writeToFile:atomically: and in the second case PTPDFDoc’s SaveToFile:flags:.)

If there is an error before this, please explain exactly what the error is (including the message, what line it occurs on, and the values of any variables.)

Thank you,

James