We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Conversion from Adobe Illustrator file to PDF not working

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: https://docs.aspose.com/psd/net/ai-to-pdf/

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)

@jean.heidemann, in this case, is better to use Aspose.PDF, because file you try to open has PDF headers:
%PDF-1.5

We have the support of such AI files in our roadmap, but it’s not in the near future.