←Select platform

PrepareToSave Method

Summary

Prepares this document for saving.

Syntax
C#
C++/CLI
public void PrepareToSave() 
public:  
   void PrepareToSave() 
Remarks

This method must be called before the LEADDocument currently in the viewer is saved or passed to a DocumentConverter instance for conversion to a new format.

The method will update all the data that might have been changed by the user including the text or annotations containers.

Example

Start with the example created in DocumentViewerAnnotations, remove all the code in the Example function and add the code below.

When the user clicks the Example button, the document is saved to a new PDF file.

C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Document; 
using Leadtools.Document.Viewer; 
using Leadtools.Document.Converter; 
using Leadtools.Codecs; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Annotations.Automation; 
using Leadtools.Annotations.WinForms; 
using Leadtools.Annotations.Designers; 
using Leadtools.Document.Writer; 
using Leadtools.Ocr; 
 
 
// Ask for output file name 
string outputFileName = null; 
using (var dlg = new SaveFileDialog()) 
{ 
   dlg.Filter = "PDF Files|*.pdf;|All Files|*.*"; 
   if (dlg.ShowDialog() != DialogResult.OK) 
      return; 
   outputFileName = dlg.FileName; 
} 
 
// Before we save, we must save any data being cached such as the annotations 
_documentViewer.PrepareToSave(); 
 
// If we have an OCR engine, use it 
// Ready, use Document Converter to save the document with its annotations 
var converter = new DocumentConverter(); 
// If we have an OCR engine, use it 
if (_ocrEngine != null) 
   converter.SetOcrEngineInstance(_ocrEngine, false); 
 
var jobData = DocumentConverterJobs.CreateJobData( 
   _documentViewer.Document, 
   outputFileName, 
   DocumentFormat.Pdf); 
// Embed the annotations 
jobData.AnnotationsMode = DocumentConverterAnnotationsMode.Embed; 
 
// Create the job 
var job = converter.Jobs.CreateJob(jobData); 
 
// Run it 
converter.Jobs.RunJob(job); 
 
if (job.Status != DocumentConverterJobStatus.Aborted) 
{ 
   Console.WriteLine("Document created successfully"); 
   System.Diagnostics.Process.Start(outputFileName); 
} 
Requirements

Target Platforms

Help Version 22.0.2023.1.30
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document.Viewer.WinForms Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.