WriteAsync(PdfCompressorEngine,ILeadStream) Method

Summary

Asynchronously writes the created PDF content to a LEAD stream.

Syntax

C#
public static Task WriteAsync( 
   this PdfCompressorEngine pdfCompressor, 
   ILeadStream stream 
) 

Parameters

pdfCompressor

The PdfCompressorEngine object to perform the operation.

stream

The stream where the PDF content will be saved.

Remarks

This method is the .NET framework equivalent of PdfCompressorEngine.WriteAsync(ILeadStream). Both methods use the async/await mechanism for waiting for the task to finish.

The methods perform the same task, the difference being this method is for .NET framework, whereas PdfCompressorEngine.WriteAsync(ILeadStream) is for .NET Core.

The method is implemented in Leadtools.Async.dll, as an extension to the Leadtools.PdfCompressor namespace. The method will not show up unless you add a reference to Leadtools.Async.dll to your project. The method is part of the Leadtools.PdfCompressor.PdfCompressorExtensions class.

Refer to PdfCompressorEngine.WriteAsync(ILeadStream) for more information.

Example

C#
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.PdfCompressor; 
 
public void TestPdfCompressorSaveAsyncAwait() 
{ 
   string srcFile = Path.Combine(LEAD_VARS.ImagesDir, "glare.jpg"); 
   string dstFile = Path.Combine(LEAD_VARS.ImagesDir, "out.pdf"); 
 
   using (PdfCompressorEngine pdfCompressor = new PdfCompressorEngine()) 
   using (RasterCodecs codecs = new RasterCodecs()) 
   using (RasterImage image = codecs.Load(srcFile)) 
   { 
      pdfCompressor.Insert(image); 
      using (ILeadStream dstLeadStream = new Leadtools.LeadFileStream(dstFile, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) 
      { 
         Task task = Leadtools.PdfCompressor.PdfCompressorExtensions.WriteAsync(pdfCompressor, dstLeadStream); 
         task.Wait(); 
      } 
   } 
 
   Console.WriteLine("MainThread: WriteAsync returned..."); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 

Requirements

Reference to Leadtools.Async.dll and Leadtools.PdfCompressor.dll are required to use this functionality.

Target Platforms

See Also

PdfCompressorEngine.WriteAsync(ILeadStream)

PdfCompressorEngine.WriteAsync Overload List

PdfCompressorEngine.Write Overload List

PdfCompressorExtensions Class

PdfCompressorExtensions Members

Leadtools.PdfCompressor Namespace

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.