PDFServicesSDK Execute command does not work when invoked from Windows Forms UI
Hi
I am new to using PDFServicesSDK - I have used example code from:
https://developer.adobe.com/document-services/docs/overview/pdf-services-api/quickstarts/dotnet/
To create a test example that will convert pdf to docx.
I wrapped the example in the following class:
public class AdobeAPI
{
private const string PDF_SERVICES_CLIENT_ID = "clientid";
private const string PDF_SERVICES_CLIENT_SECRET = "secret";
public static void ExportToDocx()
{
try
{
var input = "d:\\Test.pdf";
var output = "d:\\Test.docx";
if (File.Exists(output))
{
File.Delete(output);
}
// Initial setup, create credentials instance.
Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()
.WithClientId(PDF_SERVICES_CLIENT_ID)
.WithClientSecret(PDF_SERVICES_CLIENT_SECRET)
.Build();
// Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.Create(credentials);
ExportPDFOperation exportPdfOperation = ExportPDFOperation.CreateNew(ExportPDFTargetFormat.DOCX);
// Provide an input FileRef for the operation.
FileRef sourceFileRef = FileRef.CreateFromLocalFile(input);
exportPdfOperation.SetInput(sourceFileRef);
// Execute the operation.
FileRef result = exportPdfOperation.Execute(executionContext);
// Save the result to the specified location.
result.SaveAs(output);
}
catch (Exception ex)
{
throw ex;
}
}
}When I invoke this from Console Application:
namespace AdobeAPIConsole
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start");
AdobeAPI.ExportToDocx();
Console.WriteLine("Done");
}
}
}It works fine and file is being converted.
When I create a simple Windows Forms App with a single button and invoke this on button click:
namespace AdobeAPIWindowsForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void sbTest_Click(object sender, EventArgs e)
{
AdobeAPI.ExportToDocx();
}
}
}Then execution stops at:
// Execute the operation.
FileRef result = exportPdfOperation.Execute(executionContext);It doesn't crash, it doesn't throw any error. It simply hangs there forever.
What am I doing wrong, I need to be able to use PDFServicesSDK from Windows Forms app. Can anyone point me what can be the possible cause of this behaviour?
Thanks
