2019-07-25 19:43:46 +03:00
// Copyright 2017 FoxyUtils ehf. All rights reserved.
2017-08-28 20:56:18 -05:00
package main
import (
2019-03-29 17:26:52 +01:00
"io/ioutil"
2017-08-28 20:56:18 -05:00
"log"
2019-05-04 11:18:06 +03:00
"github.com/unidoc/unioffice/common"
"github.com/unidoc/unioffice/document"
"github.com/unidoc/unioffice/measurement"
2017-09-10 10:08:50 -05:00
2019-05-04 11:18:06 +03:00
"github.com/unidoc/unioffice/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 ( )
2019-03-29 17:26:52 +01:00
img1 , err := common . ImageFromFile ( "gophercolor.png" )
if err != nil {
log . Fatalf ( "unable to create image: %s" , err )
}
img2data , err := ioutil . ReadFile ( "gophercolor.png" )
if err != nil {
log . Fatalf ( "unable to read file: %s" , err )
}
img2 , err := common . ImageFromBytes ( img2data )
2017-08-28 20:56:18 -05:00
if err != nil {
log . Fatalf ( "unable to create image: %s" , err )
}
2019-03-29 17:26:52 +01:00
img1ref , err := doc . AddImage ( img1 )
if err != nil {
log . Fatalf ( "unable to add image to document: %s" , err )
}
img2ref , err := doc . AddImage ( img2 )
2017-08-28 20:56:18 -05:00
if err != nil {
log . Fatalf ( "unable to add image to document: %s" , err )
}
para := doc . AddParagraph ( )
2019-03-29 17:26:52 +01:00
anchored , err := para . AddRun ( ) . AddDrawingAnchored ( img1ref )
2017-08-28 20:56:18 -05:00
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 {
2019-03-29 17:26:52 +01:00
inl , err := run . AddDrawingInline ( img1ref )
if err != nil {
log . Fatalf ( "unable to add inline image: %s" , err )
}
inl . SetSize ( 1 * measurement . Inch , 1 * measurement . Inch )
}
if i == 15 {
inl , err := run . AddDrawingInline ( img2ref )
2017-12-10 07:36:12 -06:00
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" )
}