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.
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. 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); string pathToFile = "AddSingleImageFrame.pdf"; pdf.Save(pathToFile); pdf.Dispose(); Process.Start(pathToFile); } } }
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 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) Dim pathToFile As String = "AddSingleImageFrame.pdf" pdf.Save(pathToFile) pdf.Dispose() Process.Start(pathToFile) End Sub End Class End Namespace
