Serialization also known as saving provides the ability to write content back to a storage medium.
Apryse SDK benefits include:
Incremental save (for fast save and document persistence) Linearization (Fast Web View) Supports compressed object streams Unused object removal. This option can help you create smaller files Serialize a document to memory, stream, or a file on disk To save a PDF document.
C# C++ Go Java JavaScript Obj-C PHP Python Ruby VB 
1 PDFDoc  doc  = new  PDFDoc (filename); 
2 
3 // save the document to the filesystem 
4 doc. Save (output_filename, SDFDoc.SaveOptions.e_linearized); 
5 
6 // optionally save the document to a memory buffer 
7 byte [] buf  =  doc. Save (SDFDoc.SaveOptions.e_linearized); 
1 PDFDoc  doc ( filename ); 
2 
3 // save the document to the filesystem 
4 doc. Save (output_filename, SDFDoc :: e_linearized,  NULL ); 
5 
6 // optionally save the document to a memory buffer 
7 const char*  buf  =  0 ;  
8 size_t  buf_sz; 
9 doc. Save (buf, buf_sz, SDFDoc :: e_linearized,  NULL ); 
1 doc  :=  NewPDFDoc (filename) 
2 
3 // save the document to the filesystem 
4 doc. Save (output_filename,  uint (SDFDocE_linearized)) 
5 
6 // optionally save the document to a memory buffer 
7 buffer  :=  (doc. Save ( uint (SDFDocE_linearized))).( VectorUnChar ) 
1 PDFDoc  doc  =  new  PDFDoc (filename); 
2 
3 // save the document to the filesystem 
4 doc. save (output_filename, SDFDoc.SaveMode.LINEARIZED,  null ); 
5 
6 // optionally save the document to a memory buffer 
7 byte [] buf  =  doc. save (SDFDoc.SaveMode.LINEARIZED,  null ); 
1 async function  main () { 
2   const  doc  = await  PDFNet.PDFDoc. createFromURL (filename); 
3 
4   // save the document to a memory buffer 
5   const  buf  = await  doc. saveMemoryBuffer (PDFNet.SDFDoc.SaveOptions.e_linearized); 
6 
7   //optionally save the blob to a file or upload to a server 
8   const  blob  =  new  Blob ([buf], { type :  ' application/pdf '  }); 
9 } 
10 PDFNet. runWithCleanup (main); 
1 PTPDFDoc  * doc  =  [[PTPDFDoc  alloc ]  initWithFilePath : filename]; 
2 
3 // save the document to the filesystem 
4 [doc  SaveToFile : output_filename  flags : e_ptlinearized]; 
5 
6 // optionally save the document to a memory buffer 
7 NSData  * buf  =  [doc  SaveToBuf : e_ptlinearized]; 
1 $doc  = new  PDFDoc ($filename); 
2 
3 // save the document to the filesystem 
4 $doc -> Save ($output_filename,  SDFDoc :: e_linearized ); 
5 
6 // optionally save the document to a memory buffer 
7 $buffer  =  $doc -> Save ( SDFDoc :: e_linearized ); 
1 doc  =  PDFDoc(filename) 
2 
3 # save the document to the filesystem 
4 doc.Save(output_filename, SDFDoc.e_linearized) 
5 
6 # optionally save the document to a memory buffer 
7 buffer  =  doc.Save(SDFDoc.e_linearized) 
1 doc =  PDFDoc . new (filename) 
2 
3 # save the document to the filesystem 
4 doc. Save (output_filename,  SDFDoc :: E_linearized ) 
5 
6 # optionally save the document to a memory buffer 
7 buffer = doc. Save ( SDFDoc :: E_linearized ) 
1 Dim  doc  as  PDFDoc  = New  PDFDoc (filename) 
2 
3 ' save the document to the filesystem 
4 doc. Save (output_filename, SDF.SDFDoc.SaveOptions.e_linearized) 
5 
6 ' optionally save the document to a memory buffer 
7 Dim  buffer  As  Byte  =  doc. Save (SDF.SDFDoc.SaveOptions.e_linearized) 
Read & write a PDF file from/to memory buffer 
PDF document can be serialized (or saved) to a file on a disk, to a memory buffer, or to an arbitrary data stream such as MemoryFilter or a custom filter.
To save a PDF document to a file on disk, invoke its Save() method:
C# C++ Go Java JavaScript Obj-C PHP Python Ruby VB 
1 doc. Save (output_filename, PDFDoc.e_linearized); 
1 doc. save (output_filename, SDFDoc :: e_linearized,  NULL ); 
1 doc. Save (output_filename,  uint (SDFDocE_linearized)); 
1 doc. save (output_filename, SDFDoc.SaveOptions.LINEARIZED,  null ); 
1 async function  main () { 
2   const  buf  = await  doc. saveMemoryBuffer (PDFNet.SDFDoc.SaveOptions.e_linearized); 
3 
4   //optionally save the blob to a file or upload to a server 
5   const  blob  =  new  Blob ([buf], { type :  ' application/pdf '  }); 
6 } 
7 PDFNet. runWithCleanup (main); 
1 [doc  SaveToFile : output_filename  flags : e_ptlinearized]; 
1 $doc -> Save ($output_filename,  SDFDoc :: e_linearized ); 
1 doc.Save(output_filename, SDFDoc.e_linearized) 
1 doc. Save (output_filename,  SDFDoc :: E_linearized ) 
1 doc. Save (output_filename, SDF.SDFDoc.SaveOptions.e_linearized) 
The second argument is a bitwise disjunction of flags used as options during serialization.
Apryse SDK allows a document to be saved incrementally (see section 2.2.7 "Incremental Update" in the PDF Reference Manual). Because applications may allow users to modify PDF documents, users should not have to wait for the entire file (which can contain hundreds of pages) to be rewritten each time modifications to the document are saved. Apryse SDK allows modifications to be appended to a file, leaving the original data intact. The addendum appended when a file is incrementally updated contains only those objects that were actually added or modified. Incremental update allows an application to save modifications to a PDF document in an amount of time proportional to the size of the modification rather than the size of the file. In addition, because the original contents of the document are still present in the file, it is possible to undo saved changes by deleting one or more file updates.
Changes can be appended to an existing document using e_incremental flag:
C# C++ Go Java JavaScript Obj-C PHP Python Ruby VB 
1 doc. Save (output_filename, PDFDoc.e_incremental); 
1 doc. save (output_filename, SDFDoc :: e_incremental,  NULL ); 
1 doc. Save (output_filename,  uint (SDFDocE_incremental)); 
1 doc. save (output_filename, SDFDoc.SaveOptions.INCREMENTAL,  null ); 
1 async function  main () { 
2   const  buf  = await  doc. saveMemoryBuffer (PDFNet.SDFDoc.SaveOptions.e_incremental); 
3 
4   //optionally save the blob to a file or upload to a server 
5   const  blob  =  new  Blob ([buf], { type :  ' application/pdf '  }); 
6 } 
7 PDFNet. runWithCleanup (main); 
1 [doc  SaveToFile : output_filename  flags : e_ptincremental]; 
1 $doc -> Save ($output_filename,  SDFDoc :: e_incremental ); 
1 doc.Save(output_filename, SDFDoc.e_incremental) 
1 doc. Save (output_filename,  SDFDoc :: E_incremental ) 
1 doc. Save (output_filename, SDF.SDFDoc.SaveOptions.e_incremental) 
Note that the file output name matches the input name.
Over time, PDF documents may accumulate unused objects like old updates, modifications, unused fonts, images, and so on. To trim down the file size by removing these unused objects, use the e_remove_unused flag:
C# C++ Go Java JavaScript Obj-C PHP Python Ruby VB 
1 doc. Save (output_filename, PDFDoc.e_remove_unused); 
1 doc. save (output_filename, SDFDoc :: e_remove_unused,  NULL ); 
1 doc. Save (output_filename,  uint (SDFDocE_remove_unused)); 
1 doc. save (output_filename, SDFDoc.SaveOptions.REMOVE_UNUSED,  null ); 
1 async function  main () { 
2   const  buf  = await  doc. saveMemoryBuffer (PDFNet.SDFDoc.SaveOptions.e_remove_unused); 
3 
4   //optionally save the blob to a file or upload to a server 
5   const  blob  =  new  Blob ([buf], { type :  ' application/pdf '  }); 
6 } 
7 PDFNet. runWithCleanup (main); 
1 [doc  SaveToFile : output_filename  flags : e_ptremove_unused]; 
1 $doc -> Save ($output_filename,  SDFDoc :: e_remove_unused ); 
1 doc.Save(output_filename, SDFDoc.e_remove_unused) 
1 doc. Save (output_filename,  SDFDoc :: E_remove_unused ) 
1 doc. Save (output_filename, SDF.SDFDoc.SaveOptions.e_remove_unused) 
A PDF document can also be serialized into a memory buffer as follows:
C# C++ Go Java JavaScript Obj-C PHP Python Ruby VB 
1 byte [] buf  =  doc. Save (PDFDoc.e_linearized); 
1 const char*  buf  =  0 ;  
2 size_t  buf_sz; 
3 doc. Save (buf, buf_sz, Doc :: e_linearized,  NULL ); 
1 buffer  :=  (doc. Save ( uint (SDFDocE_linearized))).( VectorUnChar ) 
1 byte [] buf  =  doc. save (SDFDoc.SaveMode.LINEARIZED,  null ); 
1 async function  main () { 
2   const  buf  = await  doc. saveMemoryBuffer (PDFNet.SDFDoc.SaveOptions.e_linearized); 
3 } 
4 PDFNet. runWithCleanup (main); 
1 NSData  * buf  =  [doc  SaveToBuf : e_ptlinearized]; 
1 $buffer  =  $doc -> Save ( SDFDoc :: e_linearized ); 
1 buffer  =  doc.Save(SDFDoc.e_linearized) 
1 buffer = doc. Save ( SDFDoc :: E_linearized ) 
1 Dim  buffer  As  Byte  =  doc. Save (SDF.SDFDoc.SaveOptions.e_linearized)