Convert TIFF to PDF in memory using C# and VB.Net

Convert TIFF to PDF in memory
using C# and VB.Net.


Complete code

using System;
using System.IO;
using System.Collections;


namespace Sample
{
    class Test
    {
        static void Main(string[] args)
        {
            //Convert TIFF to PDF in memory			
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();

            //v.Serial = "XXXXXXXXXXXXXXX";

            //specify converting options
            v.PageStyle.PageSize.Auto();
            //v.PageStyle.PageMarginLeft.Inch(1);
            //v.ImageStyle.Heightmm(150);
            //v.ImageStyle.WidthInch(10);

            //Specify a path to a TIFF file, e.g. "d:\my Funny Picture.tiff"
            string inpFile = Path.GetFullPath(@"..\..\image-tiff.tiff");
            FileInfo outFile = new FileInfo(@"Result.pdf");

            //1. Read bytes from TIFF file.
            byte[] imageBytes = File.ReadAllBytes(inpFile);

            //2. Convert TIFF bytes into PDF bytes in memory.
            byte[] pdfBytes = v.ConvertImageStreamToPdfStream(imageBytes);

            //3. Save PDF bytes to file
            if (pdfBytes != null)
            {
                File.WriteAllBytes(outFile.FullName, pdfBytes);
				// Open the resulting PDF document in a default PDF Viewer.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName) { UseShellExecute = true });
            }
        }
    }
}

Download.

        
            Imports System
Imports System.IO
Imports System.Collections


Namespace Sample
    Friend Class Test
        Shared Sub Main(ByVal args() As String)
            'Convert TIFF to PDF in memory			
            Dim v As New SautinSoft.PdfVision()

            'v.Serial = "XXXXXXXXXXXXXXX"

            'specify converting options
            v.PageStyle.PageSize.Auto()
            'v.PageStyle.PageMarginLeft.Inch(1);
            'v.ImageStyle.Heightmm(150);
            'v.ImageStyle.WidthInch(10);

            'Specify a path to a TIFF file, e.g. "d:\my Funny Picture.tiff"
            Dim inpFile As String = Path.GetFullPath("..\..\image-tiff.tiff")
            Dim outFile As New FileInfo("Result.pdf")

            '1. Read bytes from TIFF file.
            Dim imageBytes() As Byte = File.ReadAllBytes(inpFile)

            '2. Convert TIFF bytes into PDF bytes in memory.
            Dim pdfBytes() As Byte = v.ConvertImageStreamToPdfStream(imageBytes)

            '3. Save PDF bytes to file
            If pdfBytes IsNot Nothing Then
                File.WriteAllBytes(outFile.FullName, pdfBytes)
                ' Open the resulting PDF document in a default PDF Viewer.
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile.FullName) With {.UseShellExecute = True})
            End If
        End Sub
    End Class
End Namespace

Download.


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.