Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt

To insert an image into your PowerPointWriter presentation use a data marker with the image modifier.

Using the Image Modifier

ExcerptThe image modifier can be used to insert images into a data marker. If dimensions are not specified, the image will take on the dimensions of the text box. Dimensions are specified in inches. To insert an image into a data marker using the image modifier:

  1. Create or open a PowerPointTemplate

  2. Add the image modifier in

    parenthese

    to the data marker in which you want to insert the image. For example, change %%=Company.Logo

    to

     to %%=Company.Logo(image)

  3. If desired, set the

    '

    image

    '

    modifier's dimensions and sizing mode.

Setting the Image

...

Size

There are three ways to set the size of the imported image.

...

  1. Import the image with its original dimensions
    If the image modifier is used without arguments the image will maintain its original dimensions.

...

  1. Code Block
    %%=Company.Logo(image)

...

  1.  

  2. Size the image to match the text box containing the data marker.
    If the image modifier is used with a scaling [mode|#modes] as its only parameter, the image will be scaled accordingly and sized to fit the containing text box.

...

  1. Code Block
    %%=Company.Logo(image(1))

...

  1. Specify the dimensions as parameters in the image modifier.
    The image modifier can take parameters specifying the image dimensions. Dimensions can also be used with a scaling [mode|#modes].

...

  1. Dimensions are in inches.
    The syntax for specifying an images dimensions without the scaling mode is image(width, height).

...

  1. Code Block
     %%=Company.Logo(1,2)

    To use a scaling mode, add it as the

...

  1. third parameter in your modifier.

...

  1. Code Block
    %%=Company.Logo(

...

  1. 1,4.25,2)

...

Anchor
modes
modes

The scaling mode can  can have the following values:

ValueMeaning
1

The image will always be the width and height specified regardless of its natural size.

2

The image will always be enlarged or shrunk to fit within the bounds specified by width and height but it will keep its natural aspect ratio.

3

The image will be scaled down to within the bounds specified by width and height but it will keep its natural aspect ratio.

Writing the Code

Image

...

Datatypes

If you are using a database as a data source, the column that corresponds to the data marker containing the image must be of the type BLOB("Image" in SQL Server).

If the data source is an array of objects, the value that corresponds to the data marker containing the image should be a simple byte array.

Aligning the Image

Note: This  This feature requires PowerPointApplication

To programmatically set the alignment of the picture on the slide, use the [Picture.Align|Picture.Align(Alignment)] method. Picture.Align takes an [Alignment] object as a parameter. The Alignment object can have the following values:

TopTopAligns the picture at the top of the slide.

MiddleAligns the picture in the middle of the slide.

BottomAligns the picture on the bottom of the slide.

LeftAligns the picture on the left side of the slide.

CenterAligns the picture in the center of the slide.

Right
NameDescription
Anchor

Top
Anchor
Middle

Middle
Anchor
Bottom

Bottom
Anchor
Left

Left
Anchor
Center

Center
Anchor
RightRight

Aligns the picture on the right side of the slide.

Sample

...

Code

The code below demonstrates importing the image from an array and setting the alignment of the image.

Code Block
titleInserting an Image from a byte array C#
languagecsharp

//The ReadAllBytes method can be used to create a byte array from an image filepath.
byte[] imgArray = File.ReadAllBytes(@"C:\image.png");

//create an object array of values to be populated
object[] valuesArray = {imgArray};

//create a string array of column names.
//the field names must match the data marker column names in the template.
string[] colNamesArray = {"Logo(image(1,2,2))"};

//set the data source
pptt.BindData(valuesArray, colNamesArray, "Company",pptt.CreateDataBindingProperties());

//Bind the image to the template
pptt.Process();

//Pass the template to PowerPointApplication
PowerPointApplication ppta = new PowerPointApplication();
Presentation pres = ppta.Open(pptt);

//Get the first slide in the presentation
Slide slide1 = pres.Slides[0];

//Get the first picture on the slide 
Pictures allPics = slide1.Pictures;
Picture pic = allPics[0];
            
//Set the alignment to be in the center of the slide, both horizontally and veritcally
pic.Align(Alignment.Center);
pic.Align(Alignment.Middle);

Code Block
titleInserting an Image from a byte array VB
languagevbnetvb

 'The ReadAllBytes method can be used to create a byte array from an image filepath.
Dim imgArray as Byte() = File.ReadAllBytes(@"C:\image.png")

'create an object array of values to be populated
Dim valuesArray as Object() = new Object() {imgArray}

'create a string array of column names.
'the field names must match the data marker column names in the template.
Dim colNames = New String() {"Logo(image(1,2,2))"}

Dim DataProps As DataBindingProperties = pptt.CreateDataBindingProperties()

'Bind the data to the template
pptt.BindData(valuesArray, colNamesArray, "Company",pptt.CreateDataBindingProperties())
pptt.Process()

'Pass the template to PowerPointApplication
Dim ppta As PowerPointApplication = new PowerPointApplication()
Dim pres As Presentation = ppta.Open(pptt)

'Get the first slide in the presentation
Dim slide1 As Slide = pres.Slides(0)

'Get the first picture on the slide 
Dim allPics As Pictures = slide1.Pictures
Dim pic As Picture = allPics(0)
            
'Set the alignment to be in the center of the slide, both horizontally and veritcally
pic.Align(Alignment.Center)
pic.Align(Alignment.Middle)