VintaSoft Twain .NET SDK 15.1: Руководство для .NET разработчика
В этом разделе
    Как сохранить TWAIN отсканированные изображения в PDF документ?
    В этом разделе
    Изображение, которое получено от TWAIN сканера, можно сохранить в новый PDF документ или добавить в существующий PDF документ.


    Вот C#/VB.NET код, который демонстрирует, как получить изображения от TWAIN сканера и сохранить изображения в PDF документ:
    /// <summary>
    /// Synchronously acquires not compressed images from TWAIN device and saves images to PDF file.
    /// </summary>
    static void AcquireNotCompressedImagesFromTwainDeviceAndSaveImagesToPdfFile()
    {
        // create the device manager
        using (Vintasoft.Twain.DeviceManager deviceManager = new Vintasoft.Twain.DeviceManager())
        {
            // open the device manager
            deviceManager.Open();
    
            // get reference to the default device
            Vintasoft.Twain.Device device = deviceManager.DefaultDevice;
    
            // specify that device UI must not be used
            device.ShowUI = false;
    
            // open the device
            device.Open();
    
            // specify that Memory transfer mode must be used
            device.TransferMode = Vintasoft.Twain.TransferMode.Memory;
    
            // acquire images from device
            Vintasoft.Twain.AcquireModalState acquireModalState = Vintasoft.Twain.AcquireModalState.None;
            do
            {
                acquireModalState = device.AcquireModal();
                switch (acquireModalState)
                {
                    case Vintasoft.Twain.AcquireModalState.ImageAcquired:
                        // set settings of PDF encoder
                        Vintasoft.Twain.ImageEncoders.TwainPdfEncoderSettings pdfEncoderSettings = new Vintasoft.Twain.ImageEncoders.TwainPdfEncoderSettings();
                        pdfEncoderSettings.PdfDocumentInfo.Author = "VintaSoft LLC";
                        pdfEncoderSettings.PdfDocumentInfo.Title = "Documents acquired from " + device.Info.ProductName;
                        pdfEncoderSettings.PdfDocumentInfo.Creator = "VintaSoft Twain .NET SDK";
                        pdfEncoderSettings.PdfDocumentInfo.ModificationDate = System.DateTime.Now;
    
                        // add acquired image to an existing PDF document
                        device.AcquiredImage.Save(@"d:\test.pdf", pdfEncoderSettings);
    
                        // dispose the acquired image
                        device.AcquiredImage.Dispose();
                        break;
                }
            }
            while (acquireModalState != Vintasoft.Twain.AcquireModalState.None);
    
            // close the device
            device.Close();
    
            // close the device manager
            deviceManager.Close();
        }
    }
    
    ''' <summary>
    ''' Synchronously acquires not compressed images from TWAIN device and saves images to PDF file.
    ''' </summary>
    Private Shared Sub AcquireNotCompressedImagesFromTwainDeviceAndSaveImagesToPdfFile()
            ' create the device manager
            Using deviceManager As New Vintasoft.Twain.DeviceManager()
                    ' open the device manager
                    deviceManager.Open()
    
                    ' get reference to the default device
                    Dim device As Vintasoft.Twain.Device = deviceManager.DefaultDevice
    
                    ' specify that device UI must not be used
                    device.ShowUI = False
    
                    ' open the device
                    device.Open()
    
                    ' specify that Memory transfer mode must be used
                    device.TransferMode = Vintasoft.Twain.TransferMode.Memory
    
                    ' acquire images from device
                    Dim acquireModalState As Vintasoft.Twain.AcquireModalState = Vintasoft.Twain.AcquireModalState.None
                    Do
                            acquireModalState = device.AcquireModal()
                            Select Case acquireModalState
                                    Case Vintasoft.Twain.AcquireModalState.ImageAcquired
                                            ' set settings of PDF encoder
                                            Dim pdfEncoderSettings As New Vintasoft.Twain.ImageEncoders.TwainPdfEncoderSettings()
                                            pdfEncoderSettings.PdfDocumentInfo.Author = "VintaSoft LLC"
                                            pdfEncoderSettings.PdfDocumentInfo.Title = "Documents acquired from " + device.Info.ProductName
                                            pdfEncoderSettings.PdfDocumentInfo.Creator = "VintaSoft Twain .NET SDK"
                                            pdfEncoderSettings.PdfDocumentInfo.ModificationDate = System.DateTime.Now
    
                                            ' add acquired image to an existing PDF document
                                            device.AcquiredImage.Save("d:\test.pdf", pdfEncoderSettings)
    
                                            ' dispose the acquired image
                                            device.AcquiredImage.Dispose()
                                            Exit Select
                            End Select
                    Loop While acquireModalState <> Vintasoft.Twain.AcquireModalState.None
    
                    ' close the device
                    device.Close()
    
                    ' close the device manager
                    deviceManager.Close()
            End Using
    End Sub