Aspose.Pdf

Use Image from Local Disk

It's easy to use local disk images for embedding in PDF documents using Aspose.Pdf . Image class is also a specialization of Paragraph class. So, an Image class can be treated as a Paragraph like other Paragraphs .

 

Using ImageInfo object that is encapsulated in Image class, we can set the path of local disk image and its image file type. Aspose.Pdf supports many types of images. These types are collected as an enumeration, ImageFileType .

 

The supported image files types in ImageFileType enumeration and their descriptions are given below:

 

Image File Types

Description

Ccitt

Ccitt type

Gif

Gif type

Jpeg

Jpeg type

Png

Png type

Tiff

Tiff type

Bmp

Bmp type

Emf

Emf type

Exif

Exif type

Icon

Icon type

Wmf

Wmf type

MemoryBmp

MemoryBmp type

Unknown

Unknown type

 

To use a local disk image, just follow the steps given below:

 

 

Example:

 

[C#]

 

//Instantiate a Pdf object by calling its empty constructor

Pdf pdf1 = new Pdf();

 

//Create a section in the Pdf object

Section sec1 = pdf1.Sections.Add();

 

//Create an image object in the section

Aspose.Pdf.Image image1 = new Aspose.Pdf.Image(sec1);

 

//Add image object into the Paragraphs collection of the section

sec1.Paragraphs.Add(image1);

 

//Set the path of image file

image1.ImageInfo.File = "C:/Images/Apple.jpg";

 

//Set the type of image using ImageFileType enumeration

image1.ImageInfo.ImageFileType = ImageFileType.Jpeg;

 

//Set image title

image1.ImageInfo.Title = "JPEG image";

 

//Save the Pdf

pdf1.Save("d:\\temp\\test.pdf");

 

[VB.NET]

 

'Instantiate a Pdf object by calling its empty constructor

Dim pdf1 As Pdf = New Pdf()

 

'Create a section in the Pdf object

Dim sec1 As Section = pdf1.Sections.Add()

 

'Create an image object in the section

Dim image1 As Aspose.Pdf.Image = New Aspose.Pdf.Image(sec1)

 

'Add image object into the Paragraphs collection of the section

sec1.Paragraphs.Add(image1)

 

'Set the path of image file

image1.ImageInfo.File = "C:/Images/Apple.jpg"

 

'Set the type of image using ImageFileType enumeration

image1.ImageInfo.ImageFileType = ImageFileType.Jpeg

 

'Set image title

image1.ImageInfo.Title = "JPEG image"

 

'Save the Pdf

pdf1.Save("d:\\temp\\test.pdf")

 

[XML]

 

<?xml version="1.0" encoding="utf-8" ?>

  <Pdf xmlns="Aspose.Pdf">

   <Section>

        <Image File="C:/Images/Apple.jpg" Type="jpeg">

                <Title>JPEG image</Title>

        </Image>

   </Section>

  </Pdf>