Docotic.Pdf Library Help > Samples > Images > Add single image frame to PDF document

This sample shows how to add single frame (page) from a multipage image to PDF document.

The PdfDocument.OpenImage method accepts path to an image file or image bytes and returns collection of image frames (pages). Each collection item is an instance of PdfImageFrame class. Any image frame can be added to a PDF document using AddImage method. Image frames can be added to a PDF document in any order. There is no need to add all loaded frames to a PDF document.

C#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class AddSingleImageFrame
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "AddSingleImageFrame.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfImageFrames frames = pdf.OpenImage(@"Sample Data\multipage.tif");
                PdfImageFrame secondFrame = frames[1];

                PdfImage image = pdf.AddImage(secondFrame);
                pdf.Pages[0].Canvas.DrawImage(image, 10, 10, 0);

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class AddSingleImageFrame
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Dim pathToFile As String = "AddSingleImageFrame.pdf"

            Using pdf As New PdfDocument()
                Dim frames As PdfImageFrames = pdf.OpenImage("Sample Data\multipage.tif")
                Dim secondFrame As PdfImageFrame = frames(1)

                Dim image As PdfImage = pdf.AddImage(secondFrame)
                pdf.Pages(0).Canvas.DrawImage(image, 10, 10, 0)

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace