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
| Constant | Value | Description |
|---|---|---|
e_SaveFlagNormal | 0x0000 | Normal save |
e_SaveFlagIncremental | 0x0001 | Incremental save (append changes only; faster) |
e_SaveFlagNoOriginal | 0x0002 | Do not keep original data (full rewrite) |
e_SaveFlagXRefStream | 0x0008 | Use cross-reference stream (XRef Stream) |
e_SaveFlagRemoveRedundantObjects | 0x0010 | Remove redundant objects (smaller file) |
e_SaveFlagNoUpdatingMetadataDateTime | 0x0020 | Do not update metadata date/time |
e_SaveFlagLinearized | 0x1000 | Linearized 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.