2017-08-28 20:56:18 -05:00
// Copyright 2017 Baliance. All rights reserved.
package main
import (
"log"
2017-09-10 20:05:47 -05:00
"baliance.com/gooxml/common"
2017-08-28 20:56:18 -05:00
"baliance.com/gooxml/document"
"baliance.com/gooxml/measurement"
2017-09-10 10:08:50 -05:00
2017-09-23 08:28:52 -05:00
"baliance.com/gooxml/schema/soo/wml"
2017-08-28 20:56:18 -05:00
)
var lorem = ` Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin lobortis, lectus dictum feugiat tempus, sem neque finibus enim, sed eleifend sem nunc ac diam. Vestibulum tempus sagittis elementum `
func main ( ) {
doc := document . New ( )
2017-09-10 20:05:47 -05:00
img , err := common . ImageFromFile ( "gophercolor.png" )
2017-08-28 20:56:18 -05:00
if err != nil {
log . Fatalf ( "unable to create image: %s" , err )
}
iref , err := doc . AddImage ( img )
if err != nil {
log . Fatalf ( "unable to add image to document: %s" , err )
}
para := doc . AddParagraph ( )
anchored , err := para . AddRun ( ) . AddDrawingAnchored ( iref )
if err != nil {
log . Fatalf ( "unable to add anchored image: %s" , err )
}
anchored . SetName ( "Gopher" )
anchored . SetSize ( 2 * measurement . Inch , 2 * measurement . Inch )
2017-09-10 10:08:50 -05:00
anchored . SetOrigin ( wml . WdST_RelFromHPage , wml . WdST_RelFromVTopMargin )
anchored . SetHAlignment ( wml . WdST_AlignHCenter )
2017-08-28 20:56:18 -05:00
anchored . SetYOffset ( 3 * measurement . Inch )
2017-09-10 10:08:50 -05:00
anchored . SetTextWrapSquare ( wml . WdST_WrapTextBothSides )
2017-08-28 20:56:18 -05:00
run := para . AddRun ( )
for i := 0 ; i < 16 ; i ++ {
run . AddText ( lorem )
2017-12-10 07:36:12 -06:00
// drop an inline image in
if i == 13 {
inl , err := run . AddDrawingInline ( iref )
if err != nil {
log . Fatalf ( "unable to add inline image: %s" , err )
}
inl . SetSize ( 1 * measurement . Inch , 1 * measurement . Inch )
}
2017-08-28 20:56:18 -05:00
}
doc . SaveToFile ( "image.docx" )
}