In This Topic
Programming / TIFF / Adding pages to multipage TIFF files

Adding pages to multipage TIFF files

In This Topic

There are several ways to add pages to a TIFF file:

  1. Adding a page to the end of an existing multipage TIFF file.
    Copy Code
    'We assume that GdPicture has been correctly installed and unlocked.
    
    Dim oGdPictureImaging As New GdPictureImaging()
    
    Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("multipage.tif")
    
    If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
    
        If (oGdPictureImaging.TiffAppendPageFromFile(ImageID, "addition.tif") <> GdPictureStatus.OK) OrElse
    
           (oGdPictureImaging.TiffSaveMultiPageToFile(ImageID, "multipageAdded.tif", TiffCompression.TiffCompressionAUTO) <> GdPictureStatus.OK) Then
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
        End If
    
        oGdPictureImaging.ReleaseGdPictureImage(ImageID)
    
    Else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
    End If
    
    oGdPictureImaging.Dispose()
    Copy Code
    //We assume that GdPicture has been correctly installed and unlocked.
    
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    
    int ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("multipage.tif");
    
    if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
    
    {
    
        if ((oGdPictureImaging.TiffAppendPageFromFile(ImageID, "addition.tif") != GdPictureStatus.OK) ||
    
             (oGdPictureImaging.TiffSaveMultiPageToFile(ImageID, "multipageAdded.tif", TiffCompression.TiffCompressionAUTO) != GdPictureStatus.OK))
    
        {
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
        }
    
        oGdPictureImaging.ReleaseGdPictureImage(ImageID);
    
    }
    
    else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
    oGdPictureImaging.Dispose();

    You can use the same technique as above to add a page that exists as a GdPictureImage.

    Copy Code
    'We assume that GdPicture has been correctly installed and unlocked.
    
    Dim oGdPictureImaging As New GdPictureImaging()
    
    Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("multipage.tif")
    
    If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
    
        Dim AddImgID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("addition.tif")
    
        If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
    
            If (oGdPictureImaging.TiffAppendPageFromGdPictureImage(ImageID, AddImgID) <> GdPictureStatus.OK) OrElse
    
               (oGdPictureImaging.TiffSaveMultiPageToFile(ImageID, "multipageAdded.tif", TiffCompression.TiffCompressionAUTO) <> GdPictureStatus.OK) Then
    
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
            End If
    
            oGdPictureImaging.ReleaseGdPictureImage(AddImgID)
    
        Else
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
        End If
    
        oGdPictureImaging.ReleaseGdPictureImage(ImageID)
    
    Else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
    End If
    
    oGdPictureImaging.Dispose()
    Copy Code
    //We assume that GdPicture has been correctly installed and unlocked.
    
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    
    int ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("multipage.tif");
    
    if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
    
    {
    
        int AddImgID = oGdPictureImaging.CreateGdPictureImageFromFile("addition.tif");
    
        if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
    
        {
    
            if ((oGdPictureImaging.TiffAppendPageFromGdPictureImage(ImageID, AddImgID) != GdPictureStatus.OK) ||
    
                (oGdPictureImaging.TiffSaveMultiPageToFile(ImageID, "multipageAdded.tif", TiffCompression.TiffCompressionAUTO) != GdPictureStatus.OK))
    
            {
    
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
            }
    
            oGdPictureImaging.ReleaseGdPictureImage(AddImgID);
    
        }
    
        else
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
        oGdPictureImaging.ReleaseGdPictureImage(ImageID);
    
    }
    
    else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
    oGdPictureImaging.Dispose();

    As you can see in the two examples above, after adding the image we saved it and we released the image resources.

  2. Adding a page to the end of a multipage TIFF file using the TiffSaveAsMultiPageFile() method.
    Copy Code
    'We assume that GdPicture has been correctly installed and unlocked.
    
    Dim oGdPictureImaging As New GdPictureImaging()
    
    'Creating a handle to a multipage tiff file with the first page image1.tif.
    
    Dim TiffID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("image1.tif")
    
    If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
    
        Dim status As GdPictureStatus = oGdPictureImaging.TiffSaveAsMultiPageFile(TiffID, "multipage.tif", TiffCompression.TiffCompressionAUTO)
    
        If status = GdPictureStatus.OK Then
    
            'Adding the second page to the multipage tiff file from image2.tif.
    
            Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("image2.tif")
    
            If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
    
                status = oGdPictureImaging.TiffAddToMultiPageFile(TiffID, ImageID)
    
                If status = GdPictureStatus.OK Then
    
                    MessageBox.Show("Done!", "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
    
                Else
    
                    MessageBox.Show("Error: " + status.ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
                End If
    
            Else
    
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
            End If
    
            'Closing the tiff file.
    
            oGdPictureImaging.TiffCloseMultiPageFile(TiffID)
    
            'Releasing the image resource from the memory.
    
            oGdPictureImaging.ReleaseGdPictureImage(ImageID)
    
        Else
    
            MessageBox.Show("Error: " + status.ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
        End If
    
        oGdPictureImaging.ReleaseGdPictureImage(TiffID)
    
    Else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
    End If
    
    oGdPictureImaging.Dispose()
    Copy Code
    //We assume that GdPicture has been correctly installed and unlocked.
    
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    
    //Creating a handle to a multipage tiff file with the first page image1.tif.
    
    int TiffID = oGdPictureImaging.CreateGdPictureImageFromFile("image1.tif");
    
    if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
    
    {
    
        GdPictureStatus status = oGdPictureImaging.TiffSaveAsMultiPageFile(TiffID, "multipage.tif", TiffCompression.TiffCompressionAUTO);
    
        if (status == GdPictureStatus.OK)
    
        {
    
            //Adding the second page to the multipage tiff file from image2.tif.
    
            int ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("image2.tif");
    
            if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
    
            {
    
                status = oGdPictureImaging.TiffAddToMultiPageFile(TiffID, ImageID);
    
                if (status == GdPictureStatus.OK)
    
                    MessageBox.Show("Done!", "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
    
                else
    
                    MessageBox.Show("Error: " + status.ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
            }
    
            else
    
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
            //Closing the tiff file.
    
            oGdPictureImaging.TiffCloseMultiPageFile(TiffID);
    
            //Releasing the image resource from the memory.
    
            oGdPictureImaging.ReleaseGdPictureImage(ImageID);
    
        }
    
        else
    
            MessageBox.Show("Error: " + status.ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
        oGdPictureImaging.ReleaseGdPictureImage(TiffID);
    
    }
    
    else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
    oGdPictureImaging.Dispose();

    There exist overloads of the TiffAddToMultiPageFile() method, in which the TiffCompression type can be specified as well as the Compression Quality in case of TiffCompressionJPEG.

  3. Adding pages from an input image file at any location of a multipage Tiff file.
    Copy Code
    Dim oGdPictureImaging As New GdPictureImaging()
    
    Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("multipage.tif")
    
    If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
    
        If (oGdPictureImaging.TiffInsertPageFromFile(ImageID, 3, "addition.tif") <> GdPictureStatus.OK) OrElse
    
           (oGdPictureImaging.TiffSaveMultiPageToFile(ImageID, "multipageAdded.tif", TiffCompression.TiffCompressionAUTO) <> GdPictureStatus.OK) Then
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
        Else
    
            MessageBox.Show("Done!", "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
    
        End If
    
        oGdPictureImaging.ReleaseGdPictureImage(ImageID)
    
    Else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
    End If
    
    oGdPictureImaging.Dispose()
    Copy Code
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    
    int ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("multipage.tif");
    
    if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
    
    {
    
        if ((oGdPictureImaging.TiffInsertPageFromFile(ImageID, 3, "addition.tif") != GdPictureStatus.OK) ||
    
            (oGdPictureImaging.TiffSaveMultiPageToFile(ImageID, "multipageAdded.tif", TiffCompression.TiffCompressionAUTO) != GdPictureStatus.OK))
    
        {
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
        }
    
        else
    
            MessageBox.Show("Done!", "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
    
        oGdPictureImaging.ReleaseGdPictureImage(ImageID);
    
    }
    
    else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
    oGdPictureImaging.Dispose();

    Or adding pages from a GdPictureImage identifier.

    Copy Code
    Dim oGdPictureImaging As New GdPictureImaging()
    
    Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("multipage.tif")
    
    If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
    
        Dim AddImgID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("addition.tif")
    
        If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
    
            If (oGdPictureImaging.TiffInsertPageFromGdPictureImage(ImageID, 3, AddImgID) <> GdPictureStatus.OK) OrElse
    
               (oGdPictureImaging.TiffSaveMultiPageToFile(ImageID, "multipageAdded.tif", TiffCompression.TiffCompressionAUTO) <> GdPictureStatus.OK) Then
    
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
            Else
    
                MessageBox.Show("Done!", "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
    
            End If
    
            oGdPictureImaging.ReleaseGdPictureImage(AddImgID)
    
        Else
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
        End If
    
        oGdPictureImaging.ReleaseGdPictureImage(ImageID)
    
    Else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
    End If
    
    oGdPictureImaging.Dispose()
    Copy Code
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    
    int ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("multipage.tif");
    
    if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
    
    {
    
        int AddImgID = oGdPictureImaging.CreateGdPictureImageFromFile("addition.tif");
    
        if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
    
        {
    
            if ((oGdPictureImaging.TiffInsertPageFromGdPictureImage(ImageID, 3, AddImgID) != GdPictureStatus.OK) ||
    
                (oGdPictureImaging.TiffSaveMultiPageToFile(ImageID, "multipageAdded.tif", TiffCompression.TiffCompressionAUTO) != GdPictureStatus.OK))
    
            {
    
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
            }
    
            else
    
                MessageBox.Show("Done!", "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
    
            oGdPictureImaging.ReleaseGdPictureImage(AddImgID);
    
        }
    
        else
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
        oGdPictureImaging.ReleaseGdPictureImage(ImageID);
    
    }
    
    else
    
        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Multipage TIFF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
    oGdPictureImaging.Dispose();

    As you can see in the two examples above, after adding the image we saved it and we released the image resources.