Meet us at PRINT 19. Chicago, IL. Oct. 3 - 5.
This documentation is for the old version. Go to the latest Graphics Mill docs

Loading Text Layers

In addition to raster layers, Advanced PSD Add-on for Graphics Mill can work with text layers. These layers keep not only bitmap but also a text string and its appearance settings (font, color, paragraph). It is very convenient if you store templates in PSD files and use text layers as placeholders. So you can change the text in these placeholder when merging the PSD file and create personalized graphics this way.

Class Structure

The main class you should use to load layers with Advanced PSD Add-on is Aurigma.GraphicsMill.Codecs.AdvancedPsdReader . Text layers are represented by the Aurigma.GraphicsMill.Codecs.AdvancedPsdTextFrame class (inherited from Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame class).

Extract Text from Layer

To get text layers, you should work with the advanced PSD reader in the same way as described in the Loading Raster Layers section. When you iterate through PSD layers, you should verify whether the current layer is text or not. For this purpose check the AdvancedPsdFrame.Type property. If the type of the layer is Text you should cast the current frame to the AdvancedPsdTextFrame class. This class exposes all properties necessary to get information about the text layer. These properties are:

Let's consider the example where we log the PSD layers settings into a text file. The following code snippet demonstrates how to do it:

Visual Basic
' Create advanced PSD reader object to work with PSD files.
Dim psdReader As New Aurigma.GraphicsMill.Codecs.AdvancedPsdReader

' Create advanced PSD text frame object to be able to work with text layers.        
Dim textFrame As New Aurigma.GraphicsMill.Codecs.AdvancedPsdTextFrame

' Open advanced PSD reader to be able to get layers.
psdReader.Open("C:\Temp\WorkingWithLayers.psd")

' This code creates text file and saves layers' settings into it.
Dim resultFile As New System.IO.StreamWriter("C:\Temp\PsdLayersDescription.txt")

Dim frame As Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame
For Each frame In psdReader

    ' Write the number and the type of the layer.
    resultFile.WriteLine("-------------------")
    resultFile.WriteLine("frame_{0}", frame.Index)
    resultFile.WriteLine("Type: {0}", frame.Type)

    ' Check out the layer type.
    Select Case (frame.Type)

        ' If the layer is text then output text string, 
        ' font type and font size of the text sting.
    Case Aurigma.GraphicsMill.Codecs.PsdFrameType.Text
            textFrame = frame
            resultFile.WriteLine("String: {0}", textFrame.Text)
            resultFile.WriteLine("Font Name: {0}", textFrame.Font.Name)
            resultFile.WriteLine("Font Size: {0}", textFrame.Font.Size)


            ' If the layer is raster then output width and height of the layer.
        Case Aurigma.GraphicsMill.Codecs.PsdFrameType.Raster
            resultFile.WriteLine("Width: {0}", frame.Width)
            resultFile.WriteLine("Height: {0}", frame.Height)

            resultFile.WriteLine("")

    End Select
Next

' Clean up.
psdReader.Close()
resultFile.Close()
C#
// Create advanced PSD reader object to work with PSD files.
Aurigma.GraphicsMill.Codecs.AdvancedPsdReader psdReader = 
    new Aurigma.GraphicsMill.Codecs.AdvancedPsdReader();

// Create advanced PSD text frame object to be able to work with text layers.        
Aurigma.GraphicsMill.Codecs.AdvancedPsdTextFrame textFrame;

// Open advanced PSD reader to be able to get layers.
psdReader.Open(@"C:\Temp\WorkingWithLayers.psd");

// This code creates text file and saves layers' settings into it.
using (System.IO.StreamWriter resultFile = new System.IO.StreamWriter(@"C:\Temp\PsdLayersDescription.txt")) 
{
    foreach (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame frame in psdReader)
    {
        // Write the number and the type of the layer.
        resultFile.WriteLine("-------------------");
        resultFile.WriteLine("frame_{0}", frame.Index);
        resultFile.WriteLine("Type: {0}", frame.Type);
        
        // Check out the layer type.
        switch(frame.Type)
        {
            // If the layer is text then output text string, 
            // font type and font size of the text string.
            case Aurigma.GraphicsMill.Codecs.PsdFrameType.Text:
                textFrame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdTextFrame)frame;
                resultFile.WriteLine("String: {0}", textFrame.Text);
                resultFile.WriteLine("Font Name: {0}", textFrame.Font.Name);
                resultFile.WriteLine("Font Size: {0}", textFrame.Font.Size);
                break;
            
            // If the layer is raster then output width and height of the layer.
            case Aurigma.GraphicsMill.Codecs.PsdFrameType.Raster:
                resultFile.WriteLine("Width: {0}", frame.Width);
                resultFile.WriteLine("Height: {0}", frame.Height);
                break;
        }
        resultFile.WriteLine("");
    }
 }

// Clean up.
psdReader.Close();

See Also

Manual