Hi.
I’m trying to convert an Adobe Illustrator file (.ai) to PDF in my .NET 5 Web API application, but it’s not working.
I’m following this guide: Ai to PDF|Documentation
The problem occurs at this point: using (AiImage image = (AiImage)Aspose.PSD.Image.Load(aiFile))
This is my code:
public class AdobeIllustratorConverter
{
public static string Convert(IFormFile file)
{
string aiFile = Path.GetTempPath() + Guid.NewGuid().ToString() + ".ai";
using (FileStream fs = new FileStream(aiFile, FileMode.Create, FileAccess.Write))
{
file.CopyTo(fs);
}
using (AiImage image = (AiImage)Aspose.PSD.Image.Load(aiFile))
{
string pdfname = Path.GetTempPath() + Guid.NewGuid().ToString() + ".pdf";
ImageOptionsBase options = new PdfOptions();
image.Save(pdfname, options);
return pdfname;
}
}
}
The exception stacktrace
at Aspose.PSD.Image.(StreamContainer , LoadOptions )
at Aspose.PSD.Image.Load(String filePath)
at PDFConversionAsposeWebApi.Services.AdobeIllustratorConverter.Convert(IFormFile file) in C:\Users\jeanl\source\repos\PDFConversionAsposeWebApi\PDFConversionAsposeWebApi\Services\AdobeIllustratorConverter.cs:line 22
at PDFConversionAsposeWebApi.Controllers.WordConverterController.Convert(IFormFile file) in C:\Users\jeanl\source\repos\PDFConversionAsposeWebApi\PDFConversionAsposeWebApi\Controllers\WordConverterController.cs:line 61
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
This is the sample files to convert: illustrator.zip (1.2 MB)