@@ -24,6 +24,7 @@ static void Main(string[] args)
2424 HelloWorldKeepWithNext ( ) ;
2525 HelloWorldAdvancedFormatting ( ) ;
2626 HelloWorldProtectedDocument ( ) ;
27+ HelloWorldAddPictureToWord ( ) ;
2728 RightToLeft ( ) ;
2829 Indentation ( ) ;
2930 HeadersAndFooters ( ) ;
@@ -1825,7 +1826,58 @@ static void TableWithSpecifiedWidths()
18251826
18261827 }
18271828
1829+ /// <summary>
1830+ /// Create a document with two pictures. One picture is inserted normal way, the other one with rotation
1831+ /// </summary>
1832+ static void HelloWorldAddPictureToWord ( ) {
1833+ Console . WriteLine ( "\t HelloWorldAddPictureToWord()" ) ;
18281834
1835+ // Create a document.
1836+ using ( DocX document = DocX . Create ( @"docs\HelloWorldAddPictureToWord.docx" ) )
1837+ {
1838+ // Add an image into the document.
1839+ RelativeDirectory rd = new RelativeDirectory ( ) ; // prepares the files for testing
1840+ rd . Up ( 2 ) ;
1841+ Image image = document . AddImage ( rd . Path + @"\images\logo_template.png" ) ;
1842+
1843+ // Create a picture (A custom view of an Image).
1844+ Picture picture = image . CreatePicture ( ) ;
1845+ picture . Rotation = 10 ;
1846+ picture . SetPictureShape ( BasicShapes . cube ) ;
1847+
1848+ // Insert a new Paragraph into the document.
1849+ Paragraph title = document . InsertParagraph ( ) . Append ( "This is a test for a picture" ) . FontSize ( 20 ) . Font ( new FontFamily ( "Comic Sans MS" ) ) ;
1850+ title . Alignment = Alignment . center ;
1851+
1852+ // Insert a new Paragraph into the document.
1853+ Paragraph p1 = document . InsertParagraph ( ) ;
1854+
1855+ // Append content to the Paragraph
1856+ p1 . AppendLine ( "Just below there should be a picture " ) . Append ( "picture" ) . Bold ( ) . Append ( " inserted in a non-conventional way." ) ;
1857+ p1 . AppendLine ( ) ;
1858+ p1 . AppendLine ( "Check out this picture " ) . AppendPicture ( picture ) . Append ( " its funky don't you think?" ) ;
1859+ p1 . AppendLine ( ) ;
1860+
1861+ // Insert a new Paragraph into the document.
1862+ Paragraph p2 = document . InsertParagraph ( ) ;
1863+ // Append content to the Paragraph.
1864+
1865+ p2 . AppendLine ( "Is it correct?" ) ;
1866+ p2 . AppendLine ( ) ;
1867+
1868+ // Lets add another picture (without the fancy stuff)
1869+ Picture pictureNormal = image . CreatePicture ( ) ;
1870+
1871+ Paragraph p3 = document . InsertParagraph ( ) ;
1872+ p3 . AppendLine ( "Lets add another picture (without the fancy rotation stuff)" ) ;
1873+ p3 . AppendLine ( ) ;
1874+ p3 . AppendPicture ( pictureNormal ) ;
1875+
1876+ // Save this document.
1877+ document . Save ( ) ;
1878+ Console . WriteLine ( "\t Created: docs\\ HelloWorldAddPictureToWord.docx\n " ) ;
1879+ }
1880+ }
18291881
18301882
18311883 }
0 commit comments