Skip to content

Save a Document ​

Foxit PDF SDK for Android supports synchronous save, asynchronous (progressive) save, and saving to custom output streams. Use Core SDK (PDFDoc) or PDFViewCtrl depending on your scenario.

Save via PDFDoc ​

Synchronous Save ​

java
doc.saveAs(outputPath, PDFDoc.e_SaveFlagNormal);

Asynchronous Save (Progressive) ​

For large files; combine with PauseCallback for pause and resume:

java
Progressive progressive = doc.startSaveAs(outputPath, PDFDoc.e_SaveFlagNormal, null);

int state = Progressive.e_ToBeContinued;
while (state == Progressive.e_ToBeContinued) {
    state = progressive.resume();
}

Save to Custom Output Stream ​

Implement FileWriterCallback to write to custom targets (network streams, encrypted storage, etc.):

java
Progressive progressive = doc.startSaveAs(fileWriterCallback,
    PDFDoc.e_SaveFlagNormal, null);

int state = Progressive.e_ToBeContinued;
while (state == Progressive.e_ToBeContinued) {
    state = progressive.resume();
}

Save Flags ​

ConstantValueDescription
e_SaveFlagNormal0x0000Normal save
e_SaveFlagIncremental0x0001Incremental save (append changes only; faster)
e_SaveFlagNoOriginal0x0002Do not keep original data (full rewrite)
e_SaveFlagXRefStream0x0008Use cross-reference stream (XRef Stream)
e_SaveFlagRemoveRedundantObjects0x0010Remove redundant objects (smaller file)
e_SaveFlagNoUpdatingMetadataDateTime0x0020Do not update metadata date/time
e_SaveFlagLinearized0x1000Linearized save (optimized for web viewing)

Combine flags with |:

java
doc.saveAs(outputPath,
    PDFDoc.e_SaveFlagIncremental | PDFDoc.e_SaveFlagRemoveRedundantObjects);

Save via PDFViewCtrl ​

PDFViewCtrl provides UI-oriented save methods:

java
// Save to file path
pdfViewCtrl.saveDoc(filePath, PDFDoc.e_SaveFlagNormal);

// Save to custom output stream
pdfViewCtrl.saveDoc(fileWriterCallback, PDFDoc.e_SaveFlagNormal);

Complete Example ​

java
PDFDoc doc = new PDFDoc(inputPath);
doc.load(null);

// ... modify the document ...

// Incremental save to a new file
doc.saveAs(outputPath, PDFDoc.e_SaveFlagIncremental);

API Reference

See the API Reference for full PDFDoc documentation.