Asynchronously writes the created PDF content to a LEAD stream.
public static Task WriteAsync(
this PdfCompressorEngine pdfCompressor,
ILeadStream stream
)
pdfCompressor
The PdfCompressorEngine object to perform the operation.
stream
The stream where the PDF content will be saved.
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.
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:\LEADTOOLS22\Resources\Images";
}
Reference to Leadtools.Async.dll and Leadtools.PdfCompressor.dll are required to use this functionality.
PdfCompressorEngine.WriteAsync(ILeadStream)
PdfCompressorEngine.WriteAsync Overload List
PdfCompressorEngine.Write Overload List