VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.FormsProcessing.FormRecognition Namespace / FormDocumentTemplate Class
Члены типа Объект Синтаксис Example Иерархия Требования Смотрите также
В этом разделе
    Класс FormDocumentTemplate
    В этом разделе
    Содержит информацию о шаблонах форм страниц документа.
    Объектная модель
    FormDocumentTemplate
    Синтаксис
    'Declaration
    
    Public Class FormDocumentTemplate
    
    
    public class FormDocumentTemplate
    
    
    public __gc class FormDocumentTemplate
    
    
    public ref class FormDocumentTemplate
    
    
    Пример

    Вот C#/VB.NET код, который демонстрирует, как сохранить шаблон формы в файл и загрузить шаблон формы из файла.

    
    ''' <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;
    }
    
    

    Иерархия наследования

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

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также