←Select platform

FileName Property

Summary
Gets the file name that was created. It can be null if the PDF content was written to a stream.
Syntax
C#
C++/CLI
Python
public string FileName { get; } 
public: 
property int FileName { 
   int get(); 
} 

Property Value

The name of the file that was created by the PdfCompressorEngine.WriteAsync(string,object) operation. If the PdfCompressorEngine.WriteAsyncCompleted Event was fired by a PdfCompressorEngine.WriteAsync(Stream,object) operation, this property will be null.

Remarks

This property is valid only if the event was fired in response to a PdfCompressorEngine.WriteAsync(string,object) operation.

The output file contains valid PDF data only if the operation succeeded. Refer to PdfCompressorWriteAsyncCompletedEventArgs for more details on determining whether the operation succeeded.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.PdfCompressor; 
 
/* This example shows a how to use the PdfCompressorEngine::WriteAsync method to create a Pdf asynchronously.  
 * The output file is very simple and contains a single image.  
 * We will store the RasterImage and RasterImage and PdfCompressorEngine in a user class so we can dispose them  
 * when WriteAsync finishes and fires the WriteAsyncCompleted event. 
*/ 
 
 
/* Class used to store the RasterImage and PdfCompressorEngine objects */ 
private class WriteAsyncDataStringObject 
{ 
   public RasterImage image;                 /* image to write as Pdf */ 
   public PdfCompressorEngine pdfCompressor; /* compressor object that will do the save */ 
}; 
 
/* Handler for the WriteAsyncCompleted event */ 
private static void OnWriteAsyncCompletedStringObject(object sender, PdfCompressorWriteAsyncCompletedEventArgs args) 
{ 
   if (args.Error != null) 
      Debug.WriteLine($"WriteAsyncThread: The save operation failed with exception = {args.Error.Message}."); 
   else if (args.Cancelled) 
      Debug.WriteLine($"WriteAsyncThread: The save operation was cancelled!"); 
   else 
      Debug.WriteLine($"WriteAsyncThread: The save operation succeeded! Saved as {args.FileName}"); 
   /* clean up the data used by WriteAsync operation */ 
   WriteAsyncDataStringObject data = (WriteAsyncDataStringObject)args.UserState; 
   data.pdfCompressor.Dispose(); 
   data.image.Dispose(); 
   if (args.Stream != null) 
      args.Stream.Close(); 
} 
 
/* Main function calling PdfCompressorEngine.WriteAsync. Note that WriteAsync will finish after this function returns */ 
public void TestPdfCompressorSaveAsyncStringObject() 
{ 
   string srcFile = Path.Combine(LEAD_VARS.ImagesDir, "loadsave.jpg"); 
   string dstFile = Path.Combine(LEAD_VARS.ImagesDir, "out.pdf"); 
 
   WriteAsyncDataStringObject data = new WriteAsyncDataStringObject(); 
   using (RasterCodecs codecs = new RasterCodecs()) 
      data.image = codecs.Load(srcFile); 
   data.pdfCompressor = new PdfCompressorEngine(); 
   data.pdfCompressor.Insert(data.image); 
 
   /* Register OnWriteAsyncCompleted as a handler for the WriteAsyncCompleted event */ 
   data.pdfCompressor.WriteAsyncCompleted += OnWriteAsyncCompletedStringObject; 
   data.pdfCompressor.WriteAsync(dstFile, data); 
 
   Debug.WriteLine("MainThread: WriteAsync returned..."); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

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

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