Back to Website
Show / Hide Table of Contents

Importing templates

  • 1 minute to read

The Design Atoms Framework allows for loading Photoshop and InDesign templates by using the ITemplateParser interface. In the previous example, you have learned how to instantiate this interface through DI.

var parser = Injector.Instance.Resolve<ITemplateParser>();

Now, let us see how you can:

  • Load a multipage IDML template:

    var product = parser.FromIdml("invitation.idml");
    
  • Load a one-page template:

    var product = parser.FromFile("postcard.psd");
    
  • Load two templates for a two-page product:

    var product = parser.FromFiles("businesscard_front.psd", "businesscard_back.psd");
    

When you need to load three or more templates, you can pass an array of their file names into the FromFiles(String[]) method. You can also create a product based on a surface definition as in the following sample.

The Sample

This sample illustrates how you can create a two-page product by using the FromDefinition(SurfaceTemplate[]) method. Here, we load the card.idml into the first page.

using System.IO;
using System.Drawing;
using Aurigma.DesignAtoms.Configuration;
using Aurigma.DesignAtoms.Convert;
using Aurigma.DesignAtoms.Rendering;
using Autofac;
using Newtonsoft.Json;

namespace DesignAtomsConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // Setup dependency injection.
            Injector.CurrentFactory = () => DefaultInjectorFactory.Create();

            // Instantiate TemplateParser.
            var parser = Injector.Instance.Resolve<ITemplateParser>();
            // Create a product based on a surface definition.
            var product = parser.FromDefinition(new[] {
                new SurfaceTemplate
                {
                    // Load an IDML template.
                    DesignFilename = "card.idml"
                },
                new SurfaceTemplate
                {
                    // Create an empty surface.
                    Size = new SizeF(300, 300)
                }
            });

            // Instantiate IProductRenderer.
            var renderer = Injector.Instance.Resolve<IProductRenderer>();
            using (var fileStream = File.Create("card.pdf"))
            {
                // Render the product to a file.
                renderer.RenderHiRes(fileStream, product);
            }
        }
    }
}
Was this page helpful?
Thanks for your feedback!
Back to top Copyright © 2001–2025 Aurigma, Inc. All rights reserved.
Loading...
    Thank for your vote
    Your opinion is important to us. To provide details, send feedback.
    Send feedback