Guides
PDFA Conversion
This sample shows how to convert PDF to PDFA1a and PDFA1b formats.
objective-c
// Init Methods
- (instancetype)initWithDocument:(CPDFDocument *)document {
CPDFDocument *myDocument = document;
[self convertToPDFA1a:myDocument];
[self convertToPDFA1b:myDocument];
}
// Convert PDF to PDFA1a format
- (void)convertToPDFA1a:(CPDFDocument *)oldDocument {
NSString *commandLineStr = @"";
commandLineStr = [commandLineStr stringByAppendingString:@"-------------------------------------\n"];
commandLineStr = [commandLineStr stringByAppendingString:@"Samples 1: Convert PDF to PDFA1a format\n"];
// Get Sandbox path for saving the PDF File
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFA"];
if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
[[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"ConvertToPDFA1aTest"];
// Save the document in the test PDF file
NSURL *convertToPDFA1aURL = [NSURL fileURLWithPath:writeFilePath];
[oldDocument writeToURL:convertToPDFA1aURL];
// Create a new document for test PDF file
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:convertToPDFA1aURL];
// Save as PDFA1a format
[document writePDFAToURL:convertToPDFA1aURL withType:CPDFTypePDFA1a];
commandLineStr = [commandLineStr stringByAppendingString:@"Done. Results saved in ConvertToPDFA1aTest.pdf\n\n"];
}
// Convert PDF to PDFA1b format
- (void)convertToPDFA1b:(CPDFDocument *)oldDocument {
NSString *commandLineStr = @"";
commandLineStr = [commandLineStr stringByAppendingString:@"-------------------------------------\n"];
commandLineStr = [commandLineStr stringByAppendingString:@"Samples 2: Convert PDF to PDFA1b format\n"];
// Get Sandbox path for saving the PDF File
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"PDFA"];
if (![[NSFileManager defaultManager] fileExistsAtPath:writeDirectoryPath])
[[NSFileManager defaultManager] createDirectoryAtURL:[NSURL fileURLWithPath:writeDirectoryPath] withIntermediateDirectories:YES attributes:nil error:nil];
NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@.pdf",writeDirectoryPath,@"ConvertToPDFA1bTest"];
// Save the document in the test PDF file
NSURL *convertToPDFA1bURL = [NSURL fileURLWithPath:writeFilePath];
[oldDocument writeToURL:convertToPDFA1bURL];
// Create a new document for test PDF file
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:convertToPDFA1bURL];
// Save as PDFA1b format
[document writePDFAToURL:convertToPDFA1bURL withType:CPDFTypePDFA1a];
commandLineStr = [commandLineStr stringByAppendingString:@"Done. Results saved in ConvertToPDFA1bTest.pdf\n\n"];
}