VintaSoft Twain .NET SDK 15.3: Documentation for .NET developer
In This Topic
    How to save TWAIN acquired image(s) to a PDF document?
    In This Topic
    TWAIN acquired image can be saved to a new PDF document or added to an existing PDF document.


    Here is an example that demonstrates how to add TWAIN acquired images to a PDF document:
    /// <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