CreateImageFromPageTemplate(FormDocumentTemplate,FormPageTemplate) Метод (FormTemplateManager) 
 
            
                В этом разделе
            
            Создает/загружает изображение, связанное с шаблоном страницы.
            
            
Синтаксис
            
	Parameters
- document
 
- Шаблон документа.
 
- page
 
- Шаблон страницы.
 
Return Value
Изображение, связанное с шаблоном страницы.
         
Исключения
Ремарки
Этот метод можно использовать, если необходимо переопределить алгоритм создания/загрузки изображения, например, изображение необходимо загрузить из базы данных.
 
Пример
Вот C#/VB.NET код, который демонстрирует, как загрузить шаблон документа, в котором хранятся изображения шаблонов страниц в базе данных.
    
	
	    
	    
''' <summary>
''' The form template manager that loads page template images from database.
''' </summary>
Public Class MyFormTemplateManager
    Inherits Vintasoft.Imaging.FormsProcessing.FormRecognition.FormTemplateManager
    ''' <summary>
    ''' Creates/loads an image, which is associated with the page template.
    ''' </summary>
    ''' <param name="document">The document template.</param>
    ''' <param name="page">The page template.</param>
    ''' <returns>Image associated with page template.</returns>
    Protected Overrides Function CreateImageFromPageTemplate(document As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate, page As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPageTemplate) As Vintasoft.Imaging.VintasoftImage
        ' get the page template image identifier from FormTempatePage.ImageFileName property
        Dim pageTemplateImageId As String = String.Format("{0}{1}", document.FileName, page.ImageFileName)
        If String.IsNullOrEmpty(pageTemplateImageId) Then
            Throw New System.IO.InvalidDataException("Image file identifier is not specified.")
        End If
        ' load image file from database
        Using imageFileStream As System.IO.Stream = LoadImageFromDatabase(pageTemplateImageId)
            ' create image decoder for image file
            Using decoder As Vintasoft.Imaging.Codecs.Decoders.DecoderBase = Vintasoft.Imaging.Codecs.Decoders.AvailableDecoders.CreateDecoder(imageFileStream)
                ' if image file does not have image with specified index
                If page.ImagePageIndex < 0 OrElse page.ImagePageIndex >= decoder.PageCount Then
                    Throw New System.InvalidOperationException("Cannot create template image: page index is out of range.")
                End If
                ' get a page template image
                Using pageTemplateImage As Vintasoft.Imaging.VintasoftImage = decoder.GetImage(page.ImagePageIndex)
                    ' return a clone of page template image because we need to dispose decoder and image file stream
                    Return DirectCast(pageTemplateImage.Clone(), Vintasoft.Imaging.VintasoftImage)
                End Using
            End Using
        End Using
    End Function
    ''' <summary>
    ''' Loads image from database.
    ''' </summary>
    ''' <param name="imageId">An image file identifier in database.</param>
    ''' <returns>A stream that contains image file data.</returns>
    Private Function LoadImageFromDatabase(imageId As String) As System.IO.Stream
        ' load image file from file stream - change this code to the code that loads image file from database
        Return New System.IO.FileStream(imageId, System.IO.FileMode.Open, System.IO.FileAccess.Read)
    End Function
End Class
	     
	 
 
    
	
	    
	    
/// <summary>
/// The form template manager that loads page template images from database.
/// </summary>
public class MyFormTemplateManager : Vintasoft.Imaging.FormsProcessing.FormRecognition.FormTemplateManager
{
    /// <summary>
    /// Creates/loads an image, which is associated with the page template.
    /// </summary>
    /// <param name="document">The document template.</param>
    /// <param name="page">The page template.</param>
    /// <returns>Image associated with page template.</returns>
    protected override Vintasoft.Imaging.VintasoftImage CreateImageFromPageTemplate(
        Vintasoft.Imaging.FormsProcessing.FormRecognition.FormDocumentTemplate document,
        Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPageTemplate page)
    {
        // get the page template image identifier from FormTempatePage.ImageFileName property
        string pageTemplateImageId = string.Format("{0}{1}", document.FileName, page.ImageFileName);
        if (string.IsNullOrEmpty(pageTemplateImageId))
            throw new System.IO.InvalidDataException("Image file identifier is not specified.");
        // load image file from database
        using (System.IO.Stream imageFileStream = LoadImageFromDatabase(pageTemplateImageId))
        {
            // create image decoder for image file
            using (Vintasoft.Imaging.Codecs.Decoders.DecoderBase decoder = Vintasoft.Imaging.Codecs.Decoders.AvailableDecoders.CreateDecoder(imageFileStream))
            {
                // if image file does not have image with specified index
                if (page.ImagePageIndex < 0 || page.ImagePageIndex >= decoder.PageCount)
                    throw new System.InvalidOperationException("Cannot create template image: page index is out of range.");
                // get a page template image
                using (Vintasoft.Imaging.VintasoftImage pageTemplateImage = decoder.GetImage(page.ImagePageIndex))
                {
                    // return a clone of page template image because we need to dispose decoder and image file stream
                    return (Vintasoft.Imaging.VintasoftImage)pageTemplateImage.Clone();
                }
            }
        }
    }
    /// <summary>
    /// Loads image from database.
    /// </summary>
    /// <param name="imageId">An image file identifier in database.</param>
    /// <returns>A stream that contains image file data.</returns>
    private System.IO.Stream LoadImageFromDatabase(string imageId)
    {
        // load image file from file stream - change this code to the code that loads image file from database
        return new System.IO.FileStream(imageId, System.IO.FileMode.Open, System.IO.FileAccess.Read);
    }
}
	     
	 
 
 
Требования
Целевые платформы: .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
 
Смотрите также