Reputation: 4222
I am trying to convert my doc and png files to PDF and merge them using ConvertAPI, Whenever I try to run the code snippet provided on their site it just doesn't return any file result.
The online stats on my page shows it has been converted
This is the code I am using
var convertApi = new ConvertApi("<my secret key>");
convertApi.ConvertAsync(fileFormatFrom, "pdf",
new ConvertApiFileParam(FileToConvert)
).Result.SaveFiles(MyOutputFolder);
I was able to get the conversion then done using WebClient's UploadFile function, but I am not sure how to achieve Merge using the same.
Any help will be appreciated.
Upvotes: 0
Views: 426
Reputation: 18097
The problem lies in Asynchronous handling in ASP.NET Web Forms. I am posting a working solution on how to handle async methods in ASP.NET Web Forms.
First, make your Web Form asynchronous by putting Async=true
like this
<%@ Page Language="C#" CodeBehind="Default.aspx.cs" Inherits="Default" Async="true" %>
Next, you need to register the async method using RegisterAsyncTask
and only after that execute the async method itself.
protected void Page_Load(object sender, EventArgs e)
{
RegisterAsyncTask(new PageAsyncTask(ConvertAsync));
}
public async Task ConvertAsync()
{
var convertApi = new ConvertApi("<secret>");
var convertApiResponse = await convertApi.ConvertAsync("docx", "pdf", new ConvertApiFileParam(@"C:\TestFiles\test3.docx"));
convertApiResponse.SaveFiles(@"C:\TestFiles");
}
Upvotes: 1