Some test text!

Loading...
Guides
PDF to MS Office

Convert PDF to MS Office on iOS

Additional easyPDF Cloud REST API plan required. Please contact our sales team for more information.

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.

API Key Security
For simplicity, this guide shows the client app communicating directly with the conversion server, including transmitting the client secret key. Please note that in a production app you should not ship your conversion service API keys as part of your app, as they are trivial to retrieve. These should be stored on a server that connects to the service, so that they keys are never shared with the client.
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:

  1. File is uploaded to the server
  2. Conversion starts
  3. Conversion finishes
  4. File is downloaded from the server

Starting a conversion job

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"];

Observing file upload progress and job start

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 completion and file download

// 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);
}

Handling errors

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: Support

Upcoming Webinar: How Developers Add Office Viewing Without Downloading | June 9th at 11 am PT

PDFTron SDK

The Platform

NEW

© 2022 PDFTron Systems Inc. All rights reserved.

Privacy

Terms of Use