Interface IWPicture
Represents a picture in a word document.
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Portable.dll
Syntax
public interface IWPicture : IParagraphItem, IEntity
Properties
AlternativeText
Gets or sets the alternate text for the picture.
Declaration
string AlternativeText { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that represents the alternate text. |
CharacterFormat
Gets the character format(font properties) of the picture. Read-only.
Declaration
WCharacterFormat CharacterFormat { get; }
Property Value
Type |
---|
WCharacterFormat |
FlipHorizontal
Gets or sets a Horizontal flipping of Picture.
Declaration
bool FlipHorizontal { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
This property returns True if the specified picture is flipped around the horizontal axis, and False if not.
Examples
The following code example demonstrates how to gets or sets the horizontal flip to picture.
//Creates a new Word document
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
//Adds new text to the paragraph
IWParagraph paragraph = section.AddParagraph();
//Gets the image and convert to byte array
Image image = Image.FromFile("Image.png");
MemoryStream imageStream = new MemoryStream();
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
byte[] imageBytes = imageStream.ToArray();
//Initializes new picture
WPicture picture = new WPicture(document);
//Loads an image from the byte array
picture.LoadImage(imageBytes);
//Sets height and width for the image
picture.Height = 100;
picture.Width = 150;
//Sets horizontal flip to the picture
picture.FlipHorizontal = true;
//Adds image to the paragraph
paragraph.Items.Add(picture);
//Saves the Word document
document.Save("Sample.docx", FormatType.Docx);
//Closes the document
document.Close();
'Creates a New Word document
Dim document As WordDocument = New WordDocument
'Adds new section to the document
Dim section As IWSection = document.AddSection
'Adds new text to the paragraph
Dim paragraph As IWParagraph = section.AddParagraph
'Gets the image and convert to byte array
Dim image As Image = Image.FromFile("Image.png")
Dim imageStream As MemoryStream = New MemoryStream
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png)
Dim imageBytes() As Byte = imageStream.ToArray
'Initializes new picture
Dim picture As WPicture = New WPicture(document)
'Loads an image from the byte array
picture.LoadImage(imageBytes)
'Sets height and width for the image
picture.Height = 100
picture.Width = 150
'Sets horizontal flip to the picture
picture.FlipHorizontal = True
'Adds image to the paragraph
paragraph.Items.Add(picture)
'Saves the Word document
document.Save("Sample.docx", FormatType.Docx)
'Closes the document
document.Close()
FlipVertical
Gets or sets a Vertical flipping of Picture.
Declaration
bool FlipVertical { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
This property returns True if the specified picture is flipped around the vertical axis, and False if not.
Examples
The following code example demonstrates how to gets or sets the vertical flip to picture.
//Creates a new Word document
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
//Adds new text to the paragraph
IWParagraph paragraph = section.AddParagraph();
//Gets the image and convert to byte array
Image image = Image.FromFile("Image.png");
MemoryStream imageStream = new MemoryStream();
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
byte[] imageBytes = imageStream.ToArray();
//Initializes new picture
WPicture picture = new WPicture(document);
//Loads an image from the byte array
picture.LoadImage(imageBytes);
//Sets height and width for the image
picture.Height = 100;
picture.Width = 150;
//Sets vertical flip to the picture
picture.FlipVertical = true;
//Adds image to the paragraph
paragraph.Items.Add(picture);
//Saves the Word document
document.Save("Sample.docx", FormatType.Docx);
//Closes the document
document.Close();
'Creates a New Word document
Dim document As WordDocument = New WordDocument
'Adds new section to the document
Dim section As IWSection = document.AddSection
'Adds new text to the paragraph
Dim paragraph As IWParagraph = section.AddParagraph
'Gets the image and convert to byte array
Dim image As Image = Image.FromFile("Image.png")
Dim imageStream As MemoryStream = New MemoryStream
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png)
Dim imageBytes() As Byte = imageStream.ToArray
'Initializes new picture
Dim picture As WPicture = New WPicture(document)
'Loads an image from the byte array
picture.LoadImage(imageBytes)
'Sets height and width for the image
picture.Height = 100
picture.Width = 150
'Sets vertical flip to the picture
picture.FlipVertical = True
'Adds image to the paragraph
paragraph.Items.Add(picture)
'Saves the Word document
document.Save("Sample.docx", FormatType.Docx)
'Closes the document
document.Close()
Height
Gets or sets the picture height in points
Declaration
float Height { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the height. |
HeightScale
Gets or sets the picture height scale factor in percent.
Declaration
float HeightScale { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the height scale factor. |
HorizontalAlignment
Gets or sets the horizontal alignment of the picture.
Declaration
ShapeHorizontalAlignment HorizontalAlignment { get; set; }
Property Value
Type | Description |
---|---|
ShapeHorizontalAlignment | The ShapeHorizontalAlignment member that specifies the horizontal alignment. |
Remarks
If the alignment is set as None, then the picture is explicitly positioned using position properties. Otherwise it is positioned according to the alignment specified. The position of the object is relative to HorizontalOrigin.
HorizontalOrigin
Gets or sets the horizontal origin of the picture.
Declaration
HorizontalOrigin HorizontalOrigin { get; set; }
Property Value
Type | Description |
---|---|
HorizontalOrigin | The HorizontalOrigin member that specifies the horizontal origin. |
HorizontalPosition
Gets or sets absolute horizontal position of the picture in points.
Declaration
float HorizontalPosition { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the horizontal position. |
Remarks
The horizontal position is relative to the HorizontalOrigin.
ImageBytes
Gets the image as byte array. Read-only.
Declaration
byte[] ImageBytes { get; }
Property Value
Type | Description |
---|---|
System.Byte[] | The System.Byte array that represents image bytes. |
IsBelowText
Gets or sets a value indicating whether the picture is below the text.
Declaration
bool IsBelowText { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if the picture is below text; otherwise, false. |
Name
Gets or sets the name of the picture.
Declaration
string Name { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that represents the name. |
Rotation
Gets or sets the picture rotation in degree.
Declaration
float Rotation { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the rotation value of the picture. |
Remarks
A positive value indicates clockwise rotation; a negative value indicates counterclockwise rotation.
SvgData
Gets the SVG image as byte array. Read-only.
Declaration
byte[] SvgData { get; }
Property Value
Type | Description |
---|---|
System.Byte[] | The System.Byte array that represents SVG image bytes. |
TextWrappingStyle
Gets or sets the text wrapping style of the picture.
Declaration
TextWrappingStyle TextWrappingStyle { get; set; }
Property Value
Type | Description |
---|---|
TextWrappingStyle | The TextWrappingStyle member that specifies the text wrapping style. |
TextWrappingType
Gets or sets the text wrapping type of the picture.
Declaration
TextWrappingType TextWrappingType { get; set; }
Property Value
Type | Description |
---|---|
TextWrappingType | The TextWrappingType member that specifies the text wrapping type. |
Title
Gets or sets the picture title.
Declaration
string Title { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that represents the title. |
VerticalAlignment
Gets or sets the vertical alignment of the picture.
Declaration
ShapeVerticalAlignment VerticalAlignment { get; set; }
Property Value
Type |
---|
ShapeVerticalAlignment |
Remarks
If the alignment is set as None, then the picture is explicitly positioned using position properties. Otherwise it is positioned according to the alignment specified. The position of the object is relative to VerticalOrigin.
VerticalOrigin
Gets or sets the vertical origin of the picture.
Declaration
VerticalOrigin VerticalOrigin { get; set; }
Property Value
Type | Description |
---|---|
VerticalOrigin | The VerticalOrigin member that specifies the vertical origin. |
VerticalPosition
Gets or sets absolute vertical position of the picture in points.
Declaration
float VerticalPosition { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the vertical position. |
Remarks
The vertical position is relative to the VerticalOrigin.
Visible
Gets or sets a value indicating whether the picture is visible.
Declaration
bool Visible { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if the picture is visible; otherwise, false. |
Width
Gets or sets the picture width in points.
Declaration
float Width { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the width. |
WidthScale
Gets or sets the picture width scale factor in percent.
Declaration
float WidthScale { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the width scale factor. |
Methods
AddCaption(String, CaptionNumberingFormat, CaptionPosition)
Adds caption for the current picture with specified name, caption format and caption position.
Declaration
IWParagraph AddCaption(string name, CaptionNumberingFormat format, CaptionPosition captionPosition)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The string that specifies the name. |
CaptionNumberingFormat | format | The CaptionNumberingFormat member that specifies the format for caption numbering. |
CaptionPosition | captionPosition | The CaptionPosition member that specifies the position of caption. |
Returns
Type | Description |
---|---|
IWParagraph | The paragraph instance with the specified caption. |
Examples
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("This paragraph has picture. ");
//Append new picture to the paragraph
IWPicture picture = paragraph.AppendPicture(Image.FromFile("Image.png"));
//Set width and height for the paragraph
picture.Width = 150;
picture.Height = 100;
//Set caption for picture
picture.AddCaption("Figure 1.1", CaptionNumberingFormat.Number, CaptionPosition.AboveImage);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("This paragraph has picture. ")
'Append new picture to the paragraph
Dim picture As IWPicture = paragraph.AppendPicture(Image.FromFile("Image.png"))
'Set width and height for the paragraph
picture.Width = 150
picture.Height = 100
'Set caption for picture
picture.AddCaption("Figure 1.1", CaptionNumberingFormat.Number, CaptionPosition.AboveImage)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
LoadImage(Byte[])
Loads the image from the specified byte array.
Declaration
void LoadImage(byte[] imageBytes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | imageBytes | The byte array that specifies the image as bytes. |
Examples
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Get the image and convert to byte array
Image image = Image.FromFile("Image.png");
MemoryStream imageStream = new MemoryStream();
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
byte[] imageBytes = imageStream.ToArray();
//Initialize new picture
WPicture picture = new WPicture(document);
//Load image from the byte array
picture.LoadImage(imageBytes);
//Set width and height
picture.Height = 100;
picture.Width = 150;
//Add picture to the paragraph
paragraph.Items.Add(picture);
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Get the image and convert to byte array
Dim image__1 As Image = Image.FromFile("Image.png")
Dim imageStream As New MemoryStream()
image__1.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png)
Dim imageBytes As Byte() = imageStream.ToArray()
'Initialize new picture
Dim picture As New WPicture(document)
'Load image from the byte array
picture.LoadImage(imageBytes)
'Set width and height
picture.Height = 100
picture.Width = 150
'Add picture to the paragraph
paragraph.Items.Add(picture)
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
LoadImage(Byte[], Byte[])
Declaration
void LoadImage(byte[] svgData, byte[] imageBytes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | svgData | |
System.Byte[] | imageBytes |
Examples
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Get the SVG image as byte array.
byte[] imageBytes = File.ReadAllBytes("Image.png");
//Get the SVG image as byte array.
byte[] svgData = File.ReadAllBytes("Image.svg");
//Initialize new picture
WPicture picture = new WPicture(document);
//Load both fallback and SVG image from the byte array
picture.LoadImage(svgData, imageBytes);
//Set width and height
picture.Height = 100;
picture.Width = 150;
//Add picture to the paragraph
paragraph.Items.Add(picture);
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Get the image byte array
Dim imageBytes As Byte() = File.ReadAllBytes("Image.png")
'Get the SVG image as byte array.
Dim svgData As Byte() = File.ReadAllBytes("Image.svg")
'Initialize new picture
Dim picture As New WPicture(document)
'Load both fallback and SVG image from the byte array
picture.LoadImage(svgData, imageBytes)
'Set width and height
picture.Height = 100
picture.Width = 150
'Add picture to the paragraph
paragraph.Items.Add(picture)
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
LoadImage(Stream)
Loads the image from the specified stream.
Declaration
void LoadImage(Stream imageStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | imageStream | The stream that represents the image. |