Skip to main content

Asynchronous Conversion

Version: 3.0

Asynchronous Conversion

DynamicPDF Converter supports converting documents asynchronously to a PDF by either writing the output to a file or to a byte array.

warning

The AsynConverter class is Obsolete, use Converter or one of the file-specific converters instead.

The Converter.ConvertAsync has ten different overloads that allow passing a PDF document's path or passing the PDF as a byte array. You can also specify conversion options when converting asynchronously.

Conversion to File​

public static async Task RunTextInputFileName(string outputPdf)
{
byte[] input = File.ReadAllBytes(@"DocumentA.txt");
byte[] result = await Converter.ConvertAsync(input,@"DocumentA.txt");

if (result != null)
{
File.WriteAllBytes(outputPdf, result);
}
}
Public Shared Async Function RunTextSaveFile(outputPdf As String) As Task
Dim result As Boolean = Await Converter.ConvertAsync("DocumentA.rtf", outputPdf)
End Function

[ConvertAsyncExample.cs](https://github.com/DynamicPDF/converter-dotnet-core/blob/master/converter-dotnet-core-console-cs/ConvertAsyncExample.cs){#gitlink-id target=_blank}


[ConvertAsyncExample.vb](https://github.com/DynamicPDF/converter-dotnet-core/blob/master/converter-dotnet-core-console-vb/ConvertAsyncExample.vb){#gitlink-id target=_blank}

Conversion to Byte Array​

The following two examples illustrate converting a PDF file to a byte array followed by an example illustrating converting a byte array containing PDF data to a byte array.

File Input​

public static async Task RunTextBytesConvOpt(string outputPdf)
{
ConversionOptions options = new(false);
byte[] result = await Converter.ConvertAsync(@"DocumentA.txt", options);

if (result != null)
File.WriteAllBytes(outputPdf, result);
}
Public Shared Async Function RunTextBytesConvOpt(outputPdf As String) As Task
Dim options As New ConversionOptions(False)
Dim result As Byte() = Await Converter.ConvertAsync("DocumentA.txt", options)

If result IsNot Nothing Then
File.WriteAllBytes(outputPdf, result)
End If
End Function

[ConvertAsyncExample.cs](https://github.com/DynamicPDF/converter-dotnet-core/blob/master/converter-dotnet-core-console-cs/ConvertAsyncExample.cs){#gitlink-id target=_blank}


[ConvertAsyncExample.vb](https://github.com/DynamicPDF/converter-dotnet-core/blob/master/converter-dotnet-core-console-vb/ConvertAsyncExample.vb){#gitlink-id target=_blank}

Byte Array Input​

public static async Task RunTextInputFileName(string outputPdf)
{
byte[] input = File.ReadAllBytes(@"DocumentA.txt");
byte[] result = await Converter.ConvertAsync(input,@"DocumentA.txt");
if (result != null)
File.WriteAllBytes(outputPdf, result);
}
Public Shared Async Function RunTextInputFileName(outputPdf As String) As Task
Dim input As Byte() = File.ReadAllBytes("DocumentA.txt")
Dim result As Byte() = Await Converter.ConvertAsync(input, "DocumentA.txt")

If result IsNot Nothing Then
File.WriteAllBytes(outputPdf, result)
End If
End Function

[ConvertAsyncExample.cs](https://github.com/DynamicPDF/converter-dotnet-core/blob/master/converter-dotnet-core-console-cs/ConvertAsyncExample.cs){#gitlink-id target=_blank}


[ConvertAsyncExample.vb](https://github.com/DynamicPDF/converter-dotnet-core/blob/master/converter-dotnet-core-console-vb/ConvertAsyncExample.vb){#gitlink-id target=_blank}