VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.FormsProcessing.FormRecognition Namespace / FormDocumentTemplate Class
Members Example



In This Topic
    FormDocumentTemplate Class
    In This Topic
    Contains information about form templates of document pages.
    Object Model
    FormDocumentTemplate Class
    Syntax
    'Declaration
     
    Public Class FormDocumentTemplate 
    public class FormDocumentTemplate 
    public __gc class FormDocumentTemplate 
    public ref class FormDocumentTemplate 
    Example
    This example shows how to save a form template to a file and load the form template from the file.
    ''' <summary>
    ''' Saves the page templates as a document template to the specified stream.
    ''' </summary>
    ''' <param name="pageTemplates">The page templates.</param>
    ''' <param name="stream">The stream to save the document to.</param>
    ''' <remarks>
    ''' Use the <see cref="Vintasoft.Imaging.FormsProcessing.FormRecognition.FormTemplateManager"/> 
    ''' class to preserve links to template images.
    ''' </remarks>
    Public Sub SavePageTemplatesAsDocumentTemplate(pageTemplates As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPageTemplate(), stream As System.IO.Stream)
        ' create new template document
        Dim documentTemplate As New Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate()
        ' set arbitrary name
        documentTemplate.Name = "Combined document template"
        ' for each template page
        For Each pageTemplate As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPageTemplate In pageTemplates
            ' add to the document
            documentTemplate.Pages.Add(pageTemplate)
        Next
        ' save the document to the stream
        Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate.Serialize(stream, documentTemplate)
    End Sub
                
    ''' <summary>
    ''' Opens the document template and saves every page to a separate file.
    ''' </summary>
    ''' <param name="filename">The path to the file that contains the document template.</param>
    ''' <returns><b>true</b> if the document template contains pages; otherwise, <b>false</b>.</returns>
    Public Shared Function OpenDocumentTemplateAndSaveEveryPage(filename As String) As Boolean
        ' deserialize the document template
        Dim documentTemplate As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate = Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate.Deserialize(filename)
                
        If documentTemplate.Pages.Count = 0 Then
            Return False
        End If
        ' for each page of the document template
        For i As Integer = 0 To documentTemplate.Pages.Count - 1
            ' compose a filename
            Dim pageFilename As String = String.Format("{0}{1}_page{2}{3}", System.IO.Path.GetDirectoryName(filename), System.IO.Path.GetFileNameWithoutExtension(filename), i + 1, System.IO.Path.GetExtension(filename))
            ' save page template to a file
            Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPageTemplate.Serialize(pageFilename, documentTemplate.Pages(i))
        Next
                
        Return True
    End Function
    /// <summary>
    /// Saves the page templates as a document template to the specified stream.
    /// </summary>
    /// <param name="pageTemplates">The page templates.</param>
    /// <param name="stream">The stream to save the document to.</param>
    /// <remarks>
    /// Use the <see cref="Vintasoft.Imaging.FormsProcessing.FormRecognition.FormTemplateManager"/> 
    /// class to preserve links to template images.
    /// </remarks>
    public void SavePageTemplatesAsDocumentTemplate(
        Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPageTemplate[] pageTemplates, 
        System.IO.Stream stream)
    {
        // create new template document
        Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate documentTemplate = 
            new Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate();
        // set arbitrary name
        documentTemplate.Name = "Combined document template";
        // for each template page
        foreach (Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPageTemplate pageTemplate in pageTemplates)
        {
            // add to the document
            documentTemplate.Pages.Add(pageTemplate);
        }
        // save the document to the stream
        Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate.Serialize(stream, documentTemplate);
    }
                
    /// <summary>
    /// Opens the document template and saves every page to a separate file.
    /// </summary>
    /// <param name="filename">The path to the file that contains the document template.</param>
    /// <returns><b>true</b> if the document template contains pages; otherwise, <b>false</b>.</returns>
    public static bool OpenDocumentTemplateAndSaveEveryPage(string filename)
    {
        // deserialize the document template
        Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate documentTemplate = 
            Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate.Deserialize(filename);
                
        if (documentTemplate.Pages.Count == 0)
            return false;
        // for each page of the document template
        for (int i = 0; i < documentTemplate.Pages.Count; i++)
        {
            // compose a filename
            string pageFilename = string.Format(
                "{0}{1}_page{2}{3}",
                System.IO.Path.GetDirectoryName(filename),
                System.IO.Path.GetFileNameWithoutExtension(filename),
                i + 1,
                System.IO.Path.GetExtension(filename));
            // save page template to a file
            Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPageTemplate.Serialize(pageFilename, documentTemplate.Pages[i]);
        }
                
        return true;
    }
    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also