How do I convert HTML to PDF on iOS?

177 views
Skip to first unread message

James

unread,
Jun 3, 2015, 7:26:30 PM6/3/15
to pdfne...@googlegroups.com
Q: How can I convert HTML to PDF on iOS?

--------------------

A:

This code demonstrates how to convert an HTML file contained within the app bundle to PDF using the sample PDFViewCtrlDemo, included with the SDK.

NSString* pathToHtml = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];

[PTConvert convertOfficeToPDF:pathToHtml completion:^(NSString *pathToPDF) {

@try {

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectoryNSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString* newDoc = [documentsDirectory stringByAppendingPathComponent:@"test.pdf"];

[[NSFileManager defaultManager] copyItemAtPath:pathToPDF toPath:newDoc error:Nil];

docToOpen = [[PTPDFDoc alloc] initWithFilepath:pathToPDF];

[pdfViewCtrl SetDoc:docToOpen];

}

@catch (NSException *e) {

NSLog(@"Could not open document due to exception %@:%@", e.name, e.reason);

return;

}

}];

Reply all
Reply to author
Forward
0 new messages