←Select platform

SaveToFile Method

Summary

Exports this document to the specified file using the specified format.

Syntax

C#
VB
Java
C++
public void SaveToFile( 
   string fileName, 
   SaveDocumentOptions options 
) 
Public Sub SaveToFile( 
   ByVal fileName As String, 
   ByVal options As SaveDocumentOptions 
) 
public:  
   void SaveToFile( 
      String^ fileName, 
      SaveDocumentOptions^ options 
   ) 
public void saveToFile(String fileName, SaveDocumentOptions options) 

Parameters

fileName

Target file name. This cannot be null.

options

Options to use when saving the document. If this is null, then the document will be saved

using default options.

Remarks

Use SaveToFile or SaveToUri to export this document to an external file or remote URL.

These methods support saving the document to a raster image format, not a document. In most cases, converting a document should be performed with more options and control using the DocumentConverter class.

The document will be saved with the latest changed if it has been modified, for example, if the original file has 4 pages and the user deleted page number 1, then the saved file will contain 3 pages. Similarly, if the user called SetImage to replace the raster image for any of the pages, then the saved file will contain the new version for this page.

SaveDocumentOptions is used as follows:

Member Description
Format

Any of the LEADTOOLS supported RasterImageFormat values can be used.

If this value is the default (RasterImageFormat.Unknown), then this document will be saved using the format of the original document.
BitsPerPixel Bits per pixel value to use. Use 0 for the default value supported by Format.
AnnotationsUri If not null, then it should contain the path to where the annotations file will be saved.
WebClient

The .NET System.Net.WebClient object to use when uploading the data to the remote URL.

Only used with SaveToUri.
Example

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
using Leadtools.Documents; 
using Leadtools.Caching; 
using Leadtools.Annotations.Core; 
using Leadtools.Forms.Ocr; 
using Leadtools.Barcode; 
 
public static void DocumentSaveToFileExample() 
{ 
   var options = new LoadDocumentOptions(); 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(ImagesPath.Path, "Protected.tif"), options)) 
   { 
      // The document is read-only by default. Ensure that we can modify it 
      document.IsReadOnly = false; 
      var page = document.Pages[1]; 
      var container = page.GetAnnotations(true); 
      var obj = new AnnEllipseObject(); 
      obj.Rect = LeadRectD.Create(0, 0, 1 * 720, 1 * 720); 
      obj.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("red"), LeadLengthD.Create(1)); 
      container.Children.Add(obj); 
      page.SetAnnotations(container); 
 
      var outName = Path.GetFileName(document.Uri.AbsolutePath).Replace(".", "_") + ".tif"; 
 
      var outFileName = Path.Combine(ImagesPath.Path, outName); 
      if (File.Exists(outFileName)) 
         File.Delete(outFileName); 
 
      var saveOptions = new SaveDocumentOptions(); 
      saveOptions.Format = RasterImageFormat.CcittGroup4; 
      saveOptions.BitsPerPixel = 1; 
      var annFileName = Path.ChangeExtension(outFileName, ".xml"); 
      if (File.Exists(annFileName)) File.Delete(annFileName); 
      saveOptions.AnnotationsUri = new Uri(annFileName); 
      document.SaveToFile(outFileName, saveOptions); 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms.DocumentWriters 
Imports Leadtools.Svg 
Imports Leadtools.Documents 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Core 
Imports Leadtools.Barcode 
Imports Leadtools.Forms.Ocr 
Imports LeadtoolsDocumentsExamples.LeadtoolsExamples.Common 
'Imports LeadtoolsDocumentsExamples.LeadtoolsExamples.Common 
 
Public Shared Sub DocumentSaveToFileExample() 
   Dim options As New LoadDocumentOptions() 
   Using document As Leadtools.Documents.Document = DocumentFactory.LoadFromFile(Path.Combine(ImagesPath.Path, "Protected.tif"), options) 
      ' The document Is read-only by default. Ensure that we can modify it 
      document.IsReadOnly = False 
 
      Dim page As Leadtools.Documents.DocumentPage = document.Pages(0) 
      Dim container As AnnContainer = page.GetAnnotations(True) 
      Dim obj As New AnnEllipseObject() 
      obj.Rect = LeadRectD.Create(0, 0, 1 * 720, 1 * 720) 
      obj.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("red"), LeadLengthD.Create(1)) 
      container.Children.Add(obj) 
      page.SetAnnotations(container) 
 
      Dim outName As String = Path.GetFileName(document.Uri.AbsolutePath).Replace(".", "_") & ".tif" 
 
      Dim outFileName As String = Path.Combine(ImagesPath.Path, outName) 
      If File.Exists(outFileName) Then 
         File.Delete(outFileName) 
      End If 
 
      Dim saveOptions As New SaveDocumentOptions() 
      saveOptions.Format = RasterImageFormat.CcittGroup4 
      saveOptions.BitsPerPixel = 1 
      Dim annFileName As String = Path.ChangeExtension(outFileName, ".xml") 
      If File.Exists(annFileName) Then 
         File.Delete(annFileName) 
      End If 
      saveOptions.AnnotationsUri = New Uri(annFileName) 
      document.SaveToFile(outFileName, saveOptions) 
   End Using 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Documents Assembly