DocumentBuilderInsertOnlineVideo Method (String, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType)

Inserts an online video object into the document and scales it to the specified size.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public Shape InsertOnlineVideo(
	string videoUrl,
	RelativeHorizontalPosition horzPos,
	double left,
	RelativeVerticalPosition vertPos,
	double top,
	double width,
	double height,
	WrapType wrapType
)

Parameters

videoUrl
Type: SystemString
The URL to the video.
horzPos
Type: Aspose.Words.DrawingRelativeHorizontalPosition
Specifies where the distance to the image is measured from.
left
Type: SystemDouble
Distance in points from the origin to the left side of the image.
vertPos
Type: Aspose.Words.DrawingRelativeVerticalPosition
Specifies where the distance to the image measured from.
top
Type: SystemDouble
Distance in points from the origin to the top side of the image.
width
Type: SystemDouble
The width of the image in points. Can be a negative or zero value to request 100% scale.
height
Type: SystemDouble
The height of the image in points. Can be a negative or zero value to request 100% scale.
wrapType
Type: Aspose.Words.DrawingWrapType
Specifies how to wrap text around the image.

Return Value

Type: Shape
The image node that was just inserted.
Remarks

You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

Insertion of online video from the following resources is supported:

  • https://www.youtube.com/
  • https://vimeo.com/

If your online video is not displaying correctly, use InsertOnlineVideo(String, String, Byte, Double, Double), which accepts custom embedded html code.

The code for embedding video can vary between providers, consult your corresponding provider of choice for details.

Examples
Show how to insert online video into a document using html code.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Visible url
string vimeoVideoUrl = @"https://vimeo.com/52477838";

// Embed Html code
string vimeoEmbedCode =
    "<iframe src=\"https://player.vimeo.com/video/52477838\" width=\"640\" height=\"360\" frameborder=\"0\" title=\"Aspose\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";

// This video will have an automatically generated thumbnail, and we are setting the size according to its 16:9 aspect ratio
builder.Writeln("Video with an automatically generated thumbnail at the top left corner of the page:");
builder.InsertOnlineVideo(vimeoVideoUrl, RelativeHorizontalPosition.LeftMargin, 0,
    RelativeVerticalPosition.TopMargin, 0, 320, 180, WrapType.Square);
builder.InsertBreak(BreakType.PageBreak);

// We can get an image to use as a custom thumbnail
using (WebClient webClient = new WebClient())
{
    byte[] imageBytes = webClient.DownloadData(AsposeLogoUrl);

    using (MemoryStream stream = new MemoryStream(imageBytes))
    {
        using (Image image = Image.FromStream(stream))
        {
            // This puts the video where we are with our document builder, with a custom thumbnail and size depending on the size of the image
            builder.Writeln("Custom thumbnail at document builder's cursor:");
            builder.InsertOnlineVideo(vimeoVideoUrl, vimeoEmbedCode, imageBytes, image.Width, image.Height);
            builder.InsertBreak(BreakType.PageBreak);

            // We can put the video at the bottom right edge of the page too, but we'll have to take the page margins into account 
            double left = builder.PageSetup.RightMargin - image.Width;
            double top = builder.PageSetup.BottomMargin - image.Height;

            // Here we use a custom thumbnail and relative positioning to put it and the bottom right of tha page
            builder.Writeln("Bottom right of page with custom thumbnail:");

            builder.InsertOnlineVideo(vimeoVideoUrl, vimeoEmbedCode, imageBytes,
                RelativeHorizontalPosition.RightMargin, left, RelativeVerticalPosition.BottomMargin, top,
                image.Width, image.Height, WrapType.Square);
        }
    }
}

doc.Save(ArtifactsDir + "DocumentBuilder.InsertOnlineVideo.docx");
See Also