Skip to content

Save document

Foxit PDF SDK for iOS supports multiple save modes, including synchronous save and save to custom output streams. Use Core SDK (FSPDFDoc) or FSPDFViewCtrl depending on your scenario.

Save via FSPDFDoc

Synchronous save

objc
[doc saveAs:outputPath saveFlags:FSPDFDocSaveFlagNormal];

Asynchronous save (progressive)

For large files; use with FSPauseCallback for pause/resume:

objc
FSProgressive *progressive = [doc startSaveAs:outputPath
                                    saveFlags:FSPDFDocSaveFlagNormal
                                        pause:nil];

FSProgressState state = FSProgressiveToBeContinued;
while (state == FSProgressiveToBeContinued) {
    state = [progressive resume];
}

Save to custom output stream

Implement FSFileWriterCallback:

objc
FSProgressive *progressive = [doc startSaveAs:fileWriterCallback
                                    saveFlags:FSPDFDocSaveFlagNormal
                                        pause:nil];

FSProgressState state = FSProgressiveToBeContinued;
while (state == FSProgressiveToBeContinued) {
    state = [progressive resume];
}

Save flags

ConstantDescription
FSPDFDocSaveFlagNormalNormal save
FSPDFDocSaveFlagIncrementalIncremental save (append changes only; faster)
FSPDFDocSaveFlagNoOriginalDo not preserve original data (full rewrite)
FSPDFDocSaveFlagXRefStreamUse cross-reference stream (XRef Stream)
FSPDFDocSaveFlagRemoveRedundantObjectsRemove redundant objects (smaller file)
FSPDFDocSaveFlagLinearizedLinearized save (optimized for web viewing)

Combine flags with |:

objc
[doc saveAs:outputPath
  saveFlags:FSPDFDocSaveFlagIncremental | FSPDFDocSaveFlagRemoveRedundantObjects];

Save via FSPDFViewCtrl

UI-oriented save APIs:

objc
// Save to file path
[pdfViewCtrl saveDoc:filePath flag:FSPDFDocSaveFlagNormal];

// Save to custom output stream
[pdfViewCtrl saveDocToFileWriter:fileWriterCallback flag:FSPDFDocSaveFlagNormal];

Complete example

objc
FSPDFDoc *doc = [[FSPDFDoc alloc] initWithPath:inputPath];
[doc load:nil];

// ... modify document ...

// Incremental save to new file
[doc saveAs:outputPath saveFlags:FSPDFDocSaveFlagIncremental];

API reference

See the API reference for FSPDFDoc.