this is the code i use
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.FileFormats.Psd.Layers;
using Aspose.PSD.FileFormats.Psd.Layers.Text;
namespace Dowodzik
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//-------------------FindLayer()-------------
public static Layer FindLayer(string layerName, PsdImage image)
{
// Get aa layers in PSD file
var layers = image.Layers;
// Find desired layer
foreach (var layer in layers)
{
// Match layer's name
if (string.Equals(layer.DisplayName, layerName, StringComparison.InvariantCultureIgnoreCase))
{
return layer;
}
}
return null;
}
private void button1_Click(object sender, EventArgs e)
{
// Load PSD file
using (PsdImage image = (PsdImage)Image.Load(@"template.psd"))
{
// Find Layer using layer's name
var layerToUpdateText = (TextLayer)FindLayer("Name", image);
// Simple way to update text
layerToUpdateText.UpdateText("John Doe");
// Save the updated PSD file
image.Save("updated-psd.psd");
}
}
}
}