2017-02-14 13 views
0

私はGemBox.Documentを使用してテンプレートから出力文書を生成しています。私はそのTextBoxと同じサイズを持つTextBoxの内部に画像を挿入したいと思います。画像をWord文書に挿入するTextBox

Word document with TextBox

私はそれをどのように行うことができますか?

DocumentModel document = DocumentModel.Load("mytemplate.dotx"); 
TextBox textBox = (TextBox)document.GetChildElements(true, ElementType.TextBox).First(); 
Picture picture = new Picture(document, "myimage.png"); 
textBox.Blocks.Add(new Paragraph(document, picture)); 

答えて

1

次のことを試してみてください。

DocumentModel document = DocumentModel.Load("mytemplate.dotx"); 
TextBox textBox = (TextBox)document.GetChildElements(true, ElementType.TextBox).First(); 

// If needed you can adjust the TextBox element's inner margin to your requirement. 
textBox.TextBoxFormat.InternalMargin = new Padding(0); 

// If needed you can remove any existing content from TextBox element. 
textBox.Blocks.Clear(); 

// Get TextBox element's size. 
var textBoxSize = textBox.Layout.Size; 

// Create and add Picture element. 
textBox.Blocks.Add(
    new Paragraph(document, 
     new Picture(document, "myimage.png", textBoxSize.Width, textBoxSize.Height))); 

私はこのことができます願っています。

+0

ありがとうございました! –

関連する問題