Pictures

GemBox.Document supports pictures of various formats like JPEG, GIF, PNG, TIFF, EMF and WMF.

Following sample shows how to create pictures with sizes expressed in different units (pixels and inches) and with various positioning options.

Screenshot

Pictures Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using System;
2using System.IO;
3using System.Linq;
4using GemBox.Document;
5using GemBox.Document.Drawing;
6
7class Sample
8{
9    [STAThread]
10    static void Main(string[] args)
11    {
12        // If using Professional version, put your serial key below.
13        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
14
15        DocumentModel document = new DocumentModel();
16
17        string pathToResources = "Resources";
18
19        var section = new Section(document);
20        document.Sections.Add(section);
21
22        Paragraph paragraph = new Paragraph(document);
23        section.Blocks.Add(paragraph);
24
25        Picture picture1 = new Picture(document, Path.Combine(pathToResources, "Zahnrad.gif"), 61, 53, LengthUnit.Pixel);
26        paragraph.Inlines.Add(picture1);
27
28        paragraph.Inlines.Add(new Run(document, "GemBox.Document is a .NET component that enables developers to read, write, convert and print document files (DOCX, DOC, PDF, HTML, XPS, RTF and TXT) from .NET applications in a simple and efficient way."));
29
30        Picture picture2 = new Picture(document, Path.Combine(pathToResources, "Dices.png"));
31        picture2.Layout = new FloatingLayout(
32            new HorizontalPosition(HorizontalPositionType.Left, HorizontalPositionAnchor.Page), 
33            new VerticalPosition(2, LengthUnit.Inch, VerticalPositionAnchor.Page), 
34            picture2.Layout.Size) { WrappingStyle = TextWrappingStyle.InFrontOfText };
35        paragraph.Inlines.Add(picture2);
36
37        Picture picture3 = new Picture(document, Path.Combine(pathToResources, "Graphics1.wmf"), 378, 189, LengthUnit.Pixel);
38        picture3.Layout = new FloatingLayout(
39            new HorizontalPosition(3.5, LengthUnit.Inch, HorizontalPositionAnchor.Page),
40            new VerticalPosition(2, LengthUnit.Inch, VerticalPositionAnchor.Page),
41            picture3.Layout.Size) { WrappingStyle = TextWrappingStyle.BehindText };
42        paragraph.Inlines.Add(picture3);
43
44        document.Save("Pictures.docx");
45    }
46}
1Imports System
2Imports System.IO
3Imports System.Linq
4Imports GemBox.Document
5Imports GemBox.Document.Drawing
6
7Module Samples
8
9    Sub Main()
10
11        ' If using Professional version, put your serial key below.
12        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
13
14        Dim document As DocumentModel = New DocumentModel
15
16        Dim pathToResources As String = "Resources"
17
18        Dim section = New Section(document)
19        document.Sections.Add(section)
20
21        Dim paragraph As New Paragraph(document)
22        section.Blocks.Add(paragraph)
23
24        Dim picture1 As New Picture(document, Path.Combine(pathToResources, "Zahnrad.gif"), 61, 53, LengthUnit.Pixel)
25        paragraph.Inlines.Add(picture1)
26
27        paragraph.Inlines.Add(New Run(document, "GemBox.Document is a .NET component that enables developers to read, write, convert and print document files (DOCX, DOC, PDF, HTML, XPS, RTF and TXT) from .NET applications in a simple and efficient way."))
28
29        Dim picture2 As New Picture(document, Path.Combine(pathToResources, "Dices.png"))
30        picture2.Layout = New FloatingLayout(
31                New HorizontalPosition(HorizontalPositionType.Left, HorizontalPositionAnchor.Page),
32                New VerticalPosition(2, LengthUnit.Inch, VerticalPositionAnchor.Page),
33                picture2.Layout.Size) With {.WrappingStyle = TextWrappingStyle.InFrontOfText}
34        paragraph.Inlines.Add(picture2)
35
36        Dim picture3 As New Picture(document, Path.Combine(pathToResources, "Graphics1.wmf"), 378, 189, LengthUnit.Pixel)
37        picture3.Layout = New FloatingLayout(
38            New HorizontalPosition(3.5, LengthUnit.Inch, HorizontalPositionAnchor.Page),
39            New VerticalPosition(2, LengthUnit.Inch, VerticalPositionAnchor.Page),
40            picture3.Layout.Size) With {.WrappingStyle = TextWrappingStyle.BehindText}
41        paragraph.Inlines.Add(picture3)
42
43        document.Save("Pictures.docx")
44
45    End Sub
46
47End Module

Check next sample or find out more about GemBox.Document and GemBox Software.