When text is updated with / characters, file cannot be opened in Photoshop


#1

Hi,
it seems that when you try to update text layer content with / (forward slash) character, resulting file cannot be opened in Photoshop.

private static void UpdateText(string filePath, string newText)
{
using (var image = Image.Load(filePath))
{
if (!(image is PsdImage)) return;

            var psdImage = (PsdImage)image;
            var layers = psdImage.Layers;

            for (var index = layers.Length - 1; index >= 0; index--)
            {
                var layer = layers[index];

                if (!(layer is TextLayer)) continue;

                var textLayer = (TextLayer)layer;
                textLayer.UpdateText("/");
            }

            var imageOptions = new PsdOptions(psdImage);

            var fileName = Path.GetFileName(filePath);
            var outputFilePath = Path.GetDirectoryName(filePath) + "\\target_" + fileName;
            psdImage.Save(outputFilePath, imageOptions);
        }
    }

program_error.zip (12.7 KB)

This issue is really critical for us, can you please give us some indication of when it will be fixed?


#2

@rlaskowski.sdl,

I have observed the issue shared by you please try using latest Aspose.PSD for .NET 19.8 on your end first. If the issue still persist then please also share the snapshot of error received while opening saved PSD in Photoshop along with Photoshop version information.


#3

image.png (14.1 KB)
And yes, we are using latest version of the PSD library


#4

@rlaskowski.sdl,

I have worked with sample code and source file shared by you using Aspose.PSD 19.8. For further investigation can you please share which Photoshop you are using on your end to open the file.


#5

We are using:
(Adobe Photoshop Version: 20.0.6 20190724.r.80 2019/07/24: 1207344 x64)


#6

@rlaskowski.sdl,

Thank you for sharing the information. An issue with ID PSDNET-203 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.


#7

Hi, can we get a fix for this, please? We are encountering this problem in production with our customers and we can’t control whether or not / is present in the content.


#8

@Rares_V,

I have verified from our issue tracking system and like to share that the issue is going to get fixed in upcoming Aspose.PSD for .NET 19.9. We request for your patience till the time the product is available online. In the Aspose.PSD 19.9 for .NETwe will provide new API that will be helpful for this case:

private static void UpdateText(string filePath, string newText)
{
     using (var image = Image.Load(filePath))
     {
        if (!(image is PsdImage)) return;

        var psdImage = (PsdImage)image;
        var layers = psdImage.Layers;

        for (var index = layers.Length - 1; index >= 0; index--)
        {
            var layer = layers[index];

            if (!(layer is TextLayer)) continue;

            var textLayer = (TextLayer)layer;
            var textPortions = textLayer.TextData.Items;
            textPortions[0].Text = "/\r";
            textPortions[0].Style.FillColor = Color.Black;
            textLayer.TextData.UpdateLayerData();
        }

        var imageOptions = new PsdOptions(psdImage);

        var fileName = Path.GetFileName(filePath);
        var outputFilePath = Path.GetDirectoryName(filePath) + "\\target_" + fileName;
        psdImage.Save(outputFilePath, imageOptions);
    }
}


#9

Hi,
this issue is not fixed - using the latest version, we are still getting error if “/” character is placed in any text layer. We used the code I provided before.


#10

So after more analysis, the problem is reproduced if you use textLayer.UpdateText("/");
Unfortunately, using the approach you shared above is not an option.
Can you please let me know when you fix the UpdateText method?
As mentioned above, this is really critical issue which renders the library not usable in production.


#11

@rlaskowski.sdl,

I have observed your comments and like to share that using following sample code, we have obtained the attached output result. Can you please verify on your end.

            string filePath = "example.psd";
            using (var image = Image.Load(filePath))
            {
                if (!(image is PsdImage)) return;

                var psdImage = (PsdImage)image;
                var layers = psdImage.Layers;

                for (var index = layers.Length - 1; index >= 0; index--)
                {
                    var layer = layers[index];

                    if (!(layer is TextLayer)) continue;

                    var textLayer = (TextLayer)layer;

                    // to update text use the method UpdateText
                    textLayer.UpdateText("/");
                    // or
                    // you can use also iText functional
                    //textLayer.TextData.RemovePortion(0);
                    //ITextPortion portion = textLayer.TextData.ProducePortion();
                    //portion.Text = "/";
                    //textLayer.TextData.AddPortion(portion);
                    //textLayer.TextData.UpdateLayerData();
                }

                var imageOptions = new PsdOptions(psdImage);

                var fileName = Path.GetFileName(filePath);
                var outputFilePath = Path.GetDirectoryName(filePath) + "\\target_" + fileName;
                psdImage.Save(outputFilePath, imageOptions);
            }

psdnet203_1.zip (30.0 KB)


#12

Hi,
I tested the file in your attachment and works perfectly.
But when I tried to use your code on my machine, I get the file which doesn’t work. I adapted the code to uniquely identify namespaces as there is bit of mess between PSD and Imagining namespaces:
string filePath = “example.psd”;
var asposeLicenser = new AsposeLicenser();
asposeLicenser.LoadLicense();
using (var image = Aspose.PSD.Image.Load(filePath))
{
if (!(image is Aspose.PSD.FileFormats.Psd.PsdImage)) return;

            var psdImage = (Aspose.PSD.FileFormats.Psd.PsdImage)image;
            var layers = psdImage.Layers;

            for (var index = layers.Length - 1; index >= 0; index--)
            {
                var layer = layers[index];

                if (!(layer is Aspose.PSD.FileFormats.Psd.Layers.TextLayer)) continue;

                var textLayer = (Aspose.PSD.FileFormats.Psd.Layers.TextLayer)layer;

                // to update text use the method UpdateText
                textLayer.UpdateText("/");
                // or
                // you can use also iText functional
                //textLayer.TextData.RemovePortion(0);
                //ITextPortion portion = textLayer.TextData.ProducePortion();
                //portion.Text = "/";
                //textLayer.TextData.AddPortion(portion);
                //textLayer.TextData.UpdateLayerData();
            }

            var imageOptions = new Aspose.PSD.ImageOptions.PsdOptions(psdImage);

            var fileName = Path.GetFileName(filePath);
            var outputFilePath = Path.GetDirectoryName(filePath) + "\\target_" + fileName;
            psdImage.Save(outputFilePath, imageOptions);

#13

Note, we tested this on multiple machines, Win10 EN, Visual Studio 2019


#14

@rlaskowski.sdl,

I have worked with code and source file and unable to observe issue. I have tested this issue on Windows 10 with visual studio 2019. I have also shared my generated result with you for your kind reference.ex1.zip (12.1 KB)


#15

Hi,
can you please share with us the whole project with the dependencies? We will try to compare with what we have to see what can be different.


#16

@rlaskowski.sdl,

I like to inform that i have used 19.9 and sample code shared by you and successfully generated result.


#17

Hi,
please see attached solution with all the dependencies, when I use this, on multiple machines I’m getting error with the file you send me earlier - basically generated file cannot be opened in Photoshop.
PSDIssueStarter.zip (2.6 MB)

Can you test it and see what you get? Could it be some Windows dependency missing?


#18

@rlaskowski.sdl,

Can you please try using suggested sample code on your end using Aspose.PSD for .NET 19.9 and share your feedback with us.

            string filePath = "example.psd";
            using (var image = Image.Load(filePath))
            {
                if (!(image is PsdImage)) return;

                var psdImage = (PsdImage)image;
                var layers = psdImage.Layers;

                for (var index = layers.Length - 1; index >= 0; index--)
                {
                    var layer = layers[index];

                    if (!(layer is TextLayer)) continue;

                    var textLayer = (TextLayer)layer;

                    // to update text use the method UpdateText
                    textLayer.UpdateText("/");
                    // or
                    // you can use also iText functional
                    //textLayer.TextData.RemovePortion(0);
                    //ITextPortion portion = textLayer.TextData.ProducePortion();
                    //portion.Text = "/";
                    //textLayer.TextData.AddPortion(portion);
                    //textLayer.TextData.UpdateLayerData();
                }

                var imageOptions = new PsdOptions(psdImage);

                var fileName = Path.GetFileName(filePath);
                var outputFilePath = Path.GetDirectoryName(filePath) + "\\target_" + fileName;
                psdImage.Save(outputFilePath, imageOptions);
            }

psdnet203_1.zip (30.0 KB)


#19

This is exactly same code I sent you in attached project - simply doesn’t work. Can you compile it on your machine and send me the resulting libraries - so I can test if it will work on my machine?


#20

@rlaskowski.sdl,

I have shared complete working sample project with you, from which i have successfully generated source file.ConsoleApp235.zip (2.7 MB)