Some test text!
iOS / Guides / PDF to MS Office
We are very pleased to introduce improved PDF to Office conversion in iOS.
The PTDocumentConversionService
class provides convenient APIs for creating server-side PDF to Office and HTML conversion jobs.
There is also a PTDocumentConversionServiceDelegate
protocol for monitoring the job progress and receiving updates once the conversion is completed.
Before you get started you will need to obtain a clientID
and clientSecret
by contacting our sales team.
PTDocumentConversionService.clientID = <your client ID>;
PTDocumentConversionService.clientSecret = <your client secret>;
PTDocumentConversionService *conversionService = [[PTDocumentConversionService alloc] init];
conversionService.delegate = self; // delegate must be an object which conforms to the PTDocumentConversionServiceDelegate protocol
Internally, the steps involved in a conversion job are:
To start a conversion job, you just need to provide the conversion task type, a PTPDFDoc
object, and a filename which will be used to create the output filename.
NSString* pdfPath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"pdf"];
// Instantiate a new PDFDoc with the path to the file.
PTPDFDoc* doc = [[PTPDFDoc alloc] initWithFilepath:pdfPath];
[conversionService startConversionJobOfType:PTConversionTaskTypeWord withDoc:doc filename:@"sample.pdf"];
There are a number of delegate methods which inform the delegate about the current status of the active conversion job. See the sample code below for examples.
// File Upload Progress
- (void)documentConversionService:(PTDocumentConversionService *)documentConversionService didReceiveFileUploadProgressUpdate:(float)progress forJobID:(NSString *)jobID
{
NSLog(!"File Upload Progress: .0f%@%%", progress*100.0);
}
// Job Started
- (void)documentConversionService:(PTDocumentConversionService *)documentConversionService didStartConversionJobWithID:(NSString *)jobID
{
NSLog(@"Conversion Started");
}
// Job Finished
- (void)documentConversionService:(PTDocumentConversionService *)documentConversionService didFinishConversionJobWithStatus:(PTDocumentConversionJobStatus)status forJobID:(NSString *)jobID
{
NSLog(@"Conversion Finished");
}
// File Download Progress
- (void)documentConversionService:(PTDocumentConversionService *)documentConversionService didReceiveFileDownloadProgressUpdate:(float)progress forJobID:(NSString *)jobID
{
NSLog(!"File Download Progress: .0f%@%%", progress*100.0);
}
// Converted File Download Location
- (void)documentConversionService:(PTDocumentConversionService *)documentConversionService didDownloadConvertedFileToPath:(NSString *)filePath forJobID:(NSString *)jobID
{
NSLog("Converted file downloaded to path: %@", filePath);
}
If the conversion job fails for any reason, the following delegate method will be called with a description of the error:
- (void)documentConversionService:(PTDocumentConversionService *)documentConversionService conversionFailedWithError:(NSError *)error
{
NSLog(@"Conversion Failed ");
}
Get the answers you need: Chat with us