Aspose::Words::DocumentBuilder::InsertImage method

Contents
[ ]

DocumentBuilder::InsertImage(const System::ArrayPtr<uint8_t>&) method

Inserts an image from a byte array into the document. The image is inserted inline and at 100% scale.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::ArrayPtr<uint8_t> &imageBytes)
ParameterTypeDescription
imageBytesconst System::ArrayPtr<uint8_t>&The byte array that contains the image.

ReturnValue

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.

Examples

Shows how to insert an image from a byte array into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg");

{
    auto ms = MakeObject<System::IO::MemoryStream>();
    image->Save(ms, System::Drawing::Imaging::ImageFormat::get_Png());
    ArrayPtr<uint8_t> imageByteArray = ms->ToArray();

    // Below are three ways of inserting an image from a byte array.
    // 1 -  Inline shape with a default size based on the image's original dimensions:
    builder->InsertImage(imageByteArray);

    builder->InsertBreak(BreakType::PageBreak);

    // 2 -  Inline shape with custom dimensions:
    builder->InsertImage(imageByteArray, ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

    builder->InsertBreak(BreakType::PageBreak);

    // 3 -  Floating shape with custom dimensions:
    builder->InsertImage(imageByteArray, RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0, 100.0,
                         WrapType::Square);
}

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromByteArray.docx");

See Also

DocumentBuilder::InsertImage(const System::ArrayPtr<uint8_t>&, Aspose::Words::Drawing::RelativeHorizontalPosition, double, Aspose::Words::Drawing::RelativeVerticalPosition, double, double, double, Aspose::Words::Drawing::WrapType) method

Inserts an image from a byte array at the specified position and size.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::ArrayPtr<uint8_t> &imageBytes, Aspose::Words::Drawing::RelativeHorizontalPosition horzPos, double left, Aspose::Words::Drawing::RelativeVerticalPosition vertPos, double top, double width, double height, Aspose::Words::Drawing::WrapType wrapType)
ParameterTypeDescription
imageBytesconst System::ArrayPtr<uint8_t>&The byte array that contains the image.
horzPosAspose::Words::Drawing::RelativeHorizontalPositionSpecifies where the distance to the image is measured from.
leftdoubleDistance in points from the origin to the left side of the image.
vertPosAspose::Words::Drawing::RelativeVerticalPositionSpecifies where the distance to the image measured from.
topdoubleDistance in points from the origin to the top side of the image.
widthdoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightdoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.
wrapTypeAspose::Words::Drawing::WrapTypeSpecifies how to wrap text around the image.

ReturnValue

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.

Examples

Shows how to insert an image from a byte array into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg");

{
    auto ms = MakeObject<System::IO::MemoryStream>();
    image->Save(ms, System::Drawing::Imaging::ImageFormat::get_Png());
    ArrayPtr<uint8_t> imageByteArray = ms->ToArray();

    // Below are three ways of inserting an image from a byte array.
    // 1 -  Inline shape with a default size based on the image's original dimensions:
    builder->InsertImage(imageByteArray);

    builder->InsertBreak(BreakType::PageBreak);

    // 2 -  Inline shape with custom dimensions:
    builder->InsertImage(imageByteArray, ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

    builder->InsertBreak(BreakType::PageBreak);

    // 3 -  Floating shape with custom dimensions:
    builder->InsertImage(imageByteArray, RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0, 100.0,
                         WrapType::Square);
}

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromByteArray.docx");

See Also

DocumentBuilder::InsertImage(const System::ArrayPtr<uint8_t>&, double, double) method

Inserts an inline image from a byte array into the document and scales it to the specified size.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::ArrayPtr<uint8_t> &imageBytes, double width, double height)
ParameterTypeDescription
imageBytesconst System::ArrayPtr<uint8_t>&The byte array that contains the image.
widthdoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightdoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.

ReturnValue

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.

Examples

Shows how to insert an image from a byte array into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg");

{
    auto ms = MakeObject<System::IO::MemoryStream>();
    image->Save(ms, System::Drawing::Imaging::ImageFormat::get_Png());
    ArrayPtr<uint8_t> imageByteArray = ms->ToArray();

    // Below are three ways of inserting an image from a byte array.
    // 1 -  Inline shape with a default size based on the image's original dimensions:
    builder->InsertImage(imageByteArray);

    builder->InsertBreak(BreakType::PageBreak);

    // 2 -  Inline shape with custom dimensions:
    builder->InsertImage(imageByteArray, ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

    builder->InsertBreak(BreakType::PageBreak);

    // 3 -  Floating shape with custom dimensions:
    builder->InsertImage(imageByteArray, RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0, 100.0,
                         WrapType::Square);
}

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromByteArray.docx");

See Also

DocumentBuilder::InsertImage(const System::SharedPtr<System::Drawing::Image>&) method

Inserts an image from a Image object into the document. The image is inserted inline and at 100% scale.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::SharedPtr<System::Drawing::Image> &image)
ParameterTypeDescription
imageconst System::SharedPtr<System::Drawing::Image>&The image to insert into the document.

ReturnValue

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.

Examples

Shows how to insert an image from an object into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg");

// Below are three ways of inserting an image from an Image object instance.
// 1 -  Inline shape with a default size based on the image's original dimensions:
builder->InsertImage(image);

builder->InsertBreak(BreakType::PageBreak);

// 2 -  Inline shape with custom dimensions:
builder->InsertImage(image, ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

builder->InsertBreak(BreakType::PageBreak);

// 3 -  Floating shape with custom dimensions:
builder->InsertImage(image, RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0, 100.0, WrapType::Square);

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromImageObject.docx");

See Also

DocumentBuilder::InsertImage(const System::SharedPtr<System::Drawing::Image>&, Aspose::Words::Drawing::RelativeHorizontalPosition, double, Aspose::Words::Drawing::RelativeVerticalPosition, double, double, double, Aspose::Words::Drawing::WrapType) method

Inserts an image from a Image object at the specified position and size.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::SharedPtr<System::Drawing::Image> &image, Aspose::Words::Drawing::RelativeHorizontalPosition horzPos, double left, Aspose::Words::Drawing::RelativeVerticalPosition vertPos, double top, double width, double height, Aspose::Words::Drawing::WrapType wrapType)
ParameterTypeDescription
imageconst System::SharedPtr<System::Drawing::Image>&The image to insert into the document.
horzPosAspose::Words::Drawing::RelativeHorizontalPositionSpecifies where the distance to the image is measured from.
leftdoubleDistance in points from the origin to the left side of the image.
vertPosAspose::Words::Drawing::RelativeVerticalPositionSpecifies where the distance to the image measured from.
topdoubleDistance in points from the origin to the top side of the image.
widthdoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightdoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.
wrapTypeAspose::Words::Drawing::WrapTypeSpecifies how to wrap text around the image.

ReturnValue

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.

Examples

Shows how to insert an image from an object into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg");

// Below are three ways of inserting an image from an Image object instance.
// 1 -  Inline shape with a default size based on the image's original dimensions:
builder->InsertImage(image);

builder->InsertBreak(BreakType::PageBreak);

// 2 -  Inline shape with custom dimensions:
builder->InsertImage(image, ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

builder->InsertBreak(BreakType::PageBreak);

// 3 -  Floating shape with custom dimensions:
builder->InsertImage(image, RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0, 100.0, WrapType::Square);

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromImageObject.docx");

See Also

DocumentBuilder::InsertImage(const System::SharedPtr<System::Drawing::Image>&, double, double) method

Inserts an inline image from a Image object into the document and scales it to the specified size.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::SharedPtr<System::Drawing::Image> &image, double width, double height)
ParameterTypeDescription
imageconst System::SharedPtr<System::Drawing::Image>&The image to insert into the document.
widthdoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightdoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.

ReturnValue

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.

Examples

Shows how to insert an image from an object into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg");

// Below are three ways of inserting an image from an Image object instance.
// 1 -  Inline shape with a default size based on the image's original dimensions:
builder->InsertImage(image);

builder->InsertBreak(BreakType::PageBreak);

// 2 -  Inline shape with custom dimensions:
builder->InsertImage(image, ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

builder->InsertBreak(BreakType::PageBreak);

// 3 -  Floating shape with custom dimensions:
builder->InsertImage(image, RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0, 100.0, WrapType::Square);

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromImageObject.docx");

See Also

DocumentBuilder::InsertImage(const System::SharedPtr<System::IO::Stream>&) method

Inserts an image from a stream into the document. The image is inserted inline and at 100% scale.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::SharedPtr<System::IO::Stream> &stream)
ParameterTypeDescription
streamconst System::SharedPtr<System::IO::Stream>&The stream that contains the image.

ReturnValue

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.

Examples

Shows how to insert an image from a stream into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

{
    SharedPtr<System::IO::Stream> stream = System::IO::File::OpenRead(ImageDir + u"Logo.jpg");
    // Below are three ways of inserting an image from a stream.
    // 1 -  Inline shape with a default size based on the image's original dimensions:
    builder->InsertImage(stream);

    builder->InsertBreak(BreakType::PageBreak);

    // 2 -  Inline shape with custom dimensions:
    builder->InsertImage(stream, ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

    builder->InsertBreak(BreakType::PageBreak);

    // 3 -  Floating shape with custom dimensions:
    builder->InsertImage(stream, RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0, 100.0, WrapType::Square);
}

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromStream.docx");

Shows how to insert a shape with an image from a stream into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

{
    SharedPtr<System::IO::Stream> stream = System::IO::File::OpenRead(ImageDir + u"Logo.jpg");
    builder->Write(u"Image from stream: ");
    builder->InsertImage(stream);
}

doc->Save(ArtifactsDir + u"Image.FromStream.docx");

See Also

DocumentBuilder::InsertImage(const System::SharedPtr<System::IO::Stream>&, Aspose::Words::Drawing::RelativeHorizontalPosition, double, Aspose::Words::Drawing::RelativeVerticalPosition, double, double, double, Aspose::Words::Drawing::WrapType) method

Inserts an image from a stream at the specified position and size.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::SharedPtr<System::IO::Stream> &stream, Aspose::Words::Drawing::RelativeHorizontalPosition horzPos, double left, Aspose::Words::Drawing::RelativeVerticalPosition vertPos, double top, double width, double height, Aspose::Words::Drawing::WrapType wrapType)
ParameterTypeDescription
streamconst System::SharedPtr<System::IO::Stream>&The stream that contains the image.
horzPosAspose::Words::Drawing::RelativeHorizontalPositionSpecifies where the distance to the image is measured from.
leftdoubleDistance in points from the origin to the left side of the image.
vertPosAspose::Words::Drawing::RelativeVerticalPositionSpecifies where the distance to the image measured from.
topdoubleDistance in points from the origin to the top side of the image.
widthdoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightdoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.
wrapTypeAspose::Words::Drawing::WrapTypeSpecifies how to wrap text around the image.

ReturnValue

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.

Examples

Shows how to insert an image from a stream into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

{
    SharedPtr<System::IO::Stream> stream = System::IO::File::OpenRead(ImageDir + u"Logo.jpg");
    // Below are three ways of inserting an image from a stream.
    // 1 -  Inline shape with a default size based on the image's original dimensions:
    builder->InsertImage(stream);

    builder->InsertBreak(BreakType::PageBreak);

    // 2 -  Inline shape with custom dimensions:
    builder->InsertImage(stream, ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

    builder->InsertBreak(BreakType::PageBreak);

    // 3 -  Floating shape with custom dimensions:
    builder->InsertImage(stream, RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0, 100.0, WrapType::Square);
}

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromStream.docx");

See Also

DocumentBuilder::InsertImage(const System::SharedPtr<System::IO::Stream>&, double, double) method

Inserts an inline image from a stream into the document and scales it to the specified size.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::SharedPtr<System::IO::Stream> &stream, double width, double height)
ParameterTypeDescription
streamconst System::SharedPtr<System::IO::Stream>&The stream that contains the image.
widthdoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightdoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.

ReturnValue

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.

Examples

Shows how to insert an image from a stream into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

{
    SharedPtr<System::IO::Stream> stream = System::IO::File::OpenRead(ImageDir + u"Logo.jpg");
    // Below are three ways of inserting an image from a stream.
    // 1 -  Inline shape with a default size based on the image's original dimensions:
    builder->InsertImage(stream);

    builder->InsertBreak(BreakType::PageBreak);

    // 2 -  Inline shape with custom dimensions:
    builder->InsertImage(stream, ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

    builder->InsertBreak(BreakType::PageBreak);

    // 3 -  Floating shape with custom dimensions:
    builder->InsertImage(stream, RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0, 100.0, WrapType::Square);
}

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromStream.docx");

See Also

DocumentBuilder::InsertImage(const System::String&) method

Inserts an image from a file or URL into the document. The image is inserted inline and at 100% scale.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::String &fileName)
ParameterTypeDescription
fileNameconst System::String&The file with the image. Can be any valid local or remote URI.

ReturnValue

The image node that was just inserted.

Remarks

This overload will automatically download the image before inserting into the document if you specify a remote URI.

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

Examples

Shows how to insert an image from the local file system into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

// Below are three ways of inserting an image from a local system filename.
// 1 -  Inline shape with a default size based on the image's original dimensions:
builder->InsertImage(ImageDir + u"Logo.jpg");

builder->InsertBreak(BreakType::PageBreak);

// 2 -  Inline shape with custom dimensions:
builder->InsertImage(ImageDir + u"Transparent background logo.png", ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

builder->InsertBreak(BreakType::PageBreak);

// 3 -  Floating shape with custom dimensions:
builder->InsertImage(ImageDir + u"Windows MetaFile.wmf", RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0,
                     100.0, WrapType::Square);

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromFilename.docx");

Shows how to determine which image will be inserted.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

builder->InsertImage(ImageDir + u"Scalable Vector Graphics.svg");

// Aspose.Words insert SVG image to the document as PNG with svgBlip extension
// that contains the original vector SVG image representation.
doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertSvgImage.SvgWithSvgBlip.docx");

// Aspose.Words insert SVG image to the document as PNG, just like Microsoft Word does for old format.
doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertSvgImage.Svg.doc");

doc->get_CompatibilityOptions()->OptimizeFor(MsWordVersion::Word2003);

// Aspose.Words insert SVG image to the document as EMF metafile to keep the image in vector representation.
doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertSvgImage.Emf.docx");

Shows how to insert gif image to the document.

auto builder = MakeObject<DocumentBuilder>();

// We can insert gif image using path or bytes array.
// It works only if DocumentBuilder optimized to Word version 2010 or higher.
// Note, that access to the image bytes causes conversion Gif to Png.
SharedPtr<Shape> gifImage = builder->InsertImage(ImageDir + u"Graphics Interchange Format.gif");

gifImage = builder->InsertImage(System::IO::File::ReadAllBytes(ImageDir + u"Graphics Interchange Format.gif"));

builder->get_Document()->Save(ArtifactsDir + u"InsertGif.docx");

Shows how to insert a floating image to the center of a page.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

// Insert a floating image that will appear behind the overlapping text and align it to the page's center.
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
shape->set_WrapType(WrapType::None);
shape->set_BehindText(true);
shape->set_RelativeHorizontalPosition(RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(RelativeVerticalPosition::Page);
shape->set_HorizontalAlignment(HorizontalAlignment::Center);
shape->set_VerticalAlignment(VerticalAlignment::Center);

doc->Save(ArtifactsDir + u"Image.CreateFloatingPageCenter.docx");

See Also

DocumentBuilder::InsertImage(const System::String&, Aspose::Words::Drawing::RelativeHorizontalPosition, double, Aspose::Words::Drawing::RelativeVerticalPosition, double, double, double, Aspose::Words::Drawing::WrapType) method

Inserts an image from a file or URL at the specified position and size.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::String &fileName, Aspose::Words::Drawing::RelativeHorizontalPosition horzPos, double left, Aspose::Words::Drawing::RelativeVerticalPosition vertPos, double top, double width, double height, Aspose::Words::Drawing::WrapType wrapType)
ParameterTypeDescription
fileNameconst System::String&The file that contains the image.
horzPosAspose::Words::Drawing::RelativeHorizontalPositionSpecifies where the distance to the image is measured from.
leftdoubleDistance in points from the origin to the left side of the image.
vertPosAspose::Words::Drawing::RelativeVerticalPositionSpecifies where the distance to the image measured from.
topdoubleDistance in points from the origin to the top side of the image.
widthdoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightdoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.
wrapTypeAspose::Words::Drawing::WrapTypeSpecifies how to wrap text around the image.

ReturnValue

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.

Examples

Shows how to insert an image from the local file system into a document while preserving its dimensions.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

// The InsertImage method creates a floating shape with the passed image in its image data.
// We can specify the dimensions of the shape can be passing them to this method.
SharedPtr<Shape> imageShape = builder->InsertImage(ImageDir + u"Logo.jpg", RelativeHorizontalPosition::Margin, 0.0, RelativeVerticalPosition::Margin,
                                                   0.0, -1.0, -1.0, WrapType::Square);

// Passing negative values as the intended dimensions will automatically define
// the shape's dimensions based on the dimensions of its image.
ASPOSE_ASSERT_EQ(300.0, imageShape->get_Width());
ASPOSE_ASSERT_EQ(300.0, imageShape->get_Height());

doc->Save(ArtifactsDir + u"DocumentBuilder.InsertImageOriginalSize.docx");

Shows how to insert an image from the local file system into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

// Below are three ways of inserting an image from a local system filename.
// 1 -  Inline shape with a default size based on the image's original dimensions:
builder->InsertImage(ImageDir + u"Logo.jpg");

builder->InsertBreak(BreakType::PageBreak);

// 2 -  Inline shape with custom dimensions:
builder->InsertImage(ImageDir + u"Transparent background logo.png", ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

builder->InsertBreak(BreakType::PageBreak);

// 3 -  Floating shape with custom dimensions:
builder->InsertImage(ImageDir + u"Windows MetaFile.wmf", RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0,
                     100.0, WrapType::Square);

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromFilename.docx");

See Also

DocumentBuilder::InsertImage(const System::String&, double, double) method

Inserts an inline image from a file or URL into the document and scales it to the specified size.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(const System::String &fileName, double width, double height)
ParameterTypeDescription
fileNameconst System::String&The file that contains the image.
widthdoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightdoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.

ReturnValue

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.

Examples

Shows how to insert an image from the local file system into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

// Below are three ways of inserting an image from a local system filename.
// 1 -  Inline shape with a default size based on the image's original dimensions:
builder->InsertImage(ImageDir + u"Logo.jpg");

builder->InsertBreak(BreakType::PageBreak);

// 2 -  Inline shape with custom dimensions:
builder->InsertImage(ImageDir + u"Transparent background logo.png", ConvertUtil::PixelToPoint(250), ConvertUtil::PixelToPoint(144));

builder->InsertBreak(BreakType::PageBreak);

// 3 -  Floating shape with custom dimensions:
builder->InsertImage(ImageDir + u"Windows MetaFile.wmf", RelativeHorizontalPosition::Margin, 100.0, RelativeVerticalPosition::Margin, 100.0, 200.0,
                     100.0, WrapType::Square);

doc->Save(ArtifactsDir + u"DocumentBuilderImages.InsertImageFromFilename.docx");

See Also

DocumentBuilder::InsertImage(std::basic_istream<CharType, Traits>&) method

template<typename CharType,typename Traits> System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(std::basic_istream<CharType, Traits> &stream)

See Also

DocumentBuilder::InsertImage(std::basic_istream<CharType, Traits>&, Aspose::Words::Drawing::RelativeHorizontalPosition, double, Aspose::Words::Drawing::RelativeVerticalPosition, double, double, double, Aspose::Words::Drawing::WrapType) method

template<typename CharType,typename Traits> System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(std::basic_istream<CharType, Traits> &stream, Aspose::Words::Drawing::RelativeHorizontalPosition horzPos, double left, Aspose::Words::Drawing::RelativeVerticalPosition vertPos, double top, double width, double height, Aspose::Words::Drawing::WrapType wrapType)

See Also

DocumentBuilder::InsertImage(std::basic_istream<CharType, Traits>&, double, double) method

template<typename CharType,typename Traits> System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertImage(std::basic_istream<CharType, Traits> &stream, double width, double height)

See Also