Console: Convert an extra large PDF page to a TIFF image.

Code samples for VintaSoft Imaging .NET SDK. Here you can request a code sample.

Moderator: Alex

Post Reply
Alex
Site Admin
Posts: 1802
Joined: Thu Jul 10, 2008 2:21 pm

Console: Convert an extra large PDF page to a TIFF image.

Post by Alex »

This topic contains a code sample that shows how to convert an extra large PDF page to a TIFF image:

Code: Select all

namespace ConvertLargePdfToTiffConsoleApp
{
    /// <summary>
    /// This example shows how to convert PDF page of unlimited size to a TIFF file.<br />
    /// Size of PDF page is not limited because image renderer divides PDF page into tiles and
    /// process each tile separately.<br />
    /// Size of TIFF image is not limited because TIFF encoder divides TIFF image into tiles and
    /// process each tile separately.
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // create an image collection
                using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
                {
                    // add PDF document to the image collection
                    images.Add("documentWithLargePage.pdf");
                    // set the rendering resolution for PDF document
                    images.SetRenderingSettings(new Vintasoft.Imaging.Codecs.Decoders.RenderingSettings(new Vintasoft.Imaging.Resolution(300, 300)));

                    // create TIFF encoder
                    using (Vintasoft.Imaging.Codecs.Encoders.TiffEncoder tiffEncoder = new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder())
                    {
                        // specify that TIFF encoder must create tiles in TIFF file - this prevents loading the whole PDF image into memory
                        tiffEncoder.Settings.UseTiles = true;
                        // specify the TIFF tile size
                        tiffEncoder.Settings.TileSize = new System.Drawing.Size(2048, 2048);
                        // specify that TIFF encoder must detect the image compression automatically
                        tiffEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Auto;

                        // subscribe to the image saving progress
                        images.ImageSavingProgress += Images_ImageSavingProgress;

                        // save images to TIFF file
                        images.SaveSync("output.tif", tiffEncoder);
                    }

                    // clear image collection and dispose images
                    images.ClearAndDisposeItems();

                    System.Console.WriteLine("File is converted successfully.");
                }
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(string.Format("Error: {0}", ex.Message));
            }
            System.Console.WriteLine("Press any key...");
            System.Console.ReadKey();
        }

        private static void Images_ImageSavingProgress(object sender, Vintasoft.Imaging.ProgressEventArgs e)
        {
            // print information about image saving progress
            System.Console.Write(string.Format("{0} ", e.Progress));
        }

    }
}

VintaSoft Imaging .NET SDK (Standard) (Vintasoft.Imaging.dll) and VintaSoft PDF .NET Plug-in (Reader) (Vintasoft.Imaging.Pdf.dll) are necessary for executing this sample.

Post Reply