Converting .psd to pdf is not working

I’m looking for a solution convert .psd files to pdf. Tried with below sample as well but it is throwing an image loading failed exception. I am using Aspose.PSD 23.3.0 version

var filePath = @“C:\Figure1.psd”

using (var psdImage = (Aspose.PSD.FileFormats.Psd.PsdImage)Aspose.PSD.Image.Load(filePath, new Aspose.PSD.ImageLoadOptions.PsdLoadOptions()))
{
psdImage.Save(“Test.pdf”);
}

Can you please help me on this.

Figure1.zip (8.7 MB)

@amolm

Please check the Aspose.PSD Documentation

Also, if you want to find interesting features in Aspose.PSD please check our new PSD Tutorial Service

If you need the minimal code to convert PSD to PDF please check the following code:

    string sourceFile = @"Figure1.psd";
    string outputFile = @"Figure1.pdf";
    using (var image = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { ReadOnlyMode = true }))
    {
        image.Save(outputFile, new PdfOptions());
    }

Also, please note that for the loading was used PSD Load ReadOnlyMode = true property.

We find bug that transparency of one layer wasn’t applied correctly in the editable mode, so I created an issue PSDNET-1527: Transparency of layers is not applied when we saving to PDF Format. When the issue will be fixed, you’'ll be notified. Until the fix it’s better to use ReadOnlyMode or remove Layer named “Layer 3” from you input file

Hi @Dmitriy.Sorokin
Thank you for reply.

I tried with above conversion but still it is throwing an image loading failed exception, Can you please help me on this.

using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.ImageLoadOptions;
using Aspose.PSD.ImageOptions;
using System;

namespace Test
{
public class ConvertPsdToPdf
{
public void Convert()
{
try
{
string sourceFile = @“C:\Figure1.psd”;
string outputFile = @“C:\Figure1.pdf”;

    using (var image = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { ReadOnlyMode = true }))
    {
      image.Save(outputFile, new PdfOptions());
    }
  }
  catch(Exception ex)
  {
    Console.WriteLine(ex.Message);
  }
}}}

@amolm
Please check if your app has the access to save on root folder for drive C. It’s better to try with path like string sourceFile = @“C:\MyTestFolder\Figure1.psd”;
string outputFile = @“C:\MyTestFolder\Figure1.pdf”;

And before the code execution please create MyTestFolder.
Also, please check if the file Figure1.psd is located in the place from where you try to load it.

@Dmitriy.Sorokin
I tried with above code changes but still it is throwing an image loading failed exception, Can you please try this code at your end.

Please let me know if it is working or not.

The code works fine. Please check the following guide: Installation|Documentation

If you use .Net Core, or .Net 5, .Net 6 or higher you need to add additional dependencies:
dependencies.png (2.2 KB)

Thank you so much @Dmitriy.Sorokin

Hi @Dmitriy.Sorokin

I have upgraded .net target framework to 6.0, The conversion of .psd to .pdf is working fine on windows environment but we are getting “Image saving failed.” exception on linux.

@amolm could you please provide the exception text and stacktrace, description of your Linux Environment.

Please, also check the following article: How to run Aspose.PSD in Docker environment

This can be helpful, please check the packages you need to install on the Linux:

    # To use the ability to update the text layers you need to add the following packages to your container
    RUN apt-get update
    RUN yes | apt-get install -y apt-transport-https
    RUN yes | apt-get install -y libgdiplus
    RUN yes | apt-get install -y libc6-dev