2017-02-14 2 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

고맙습니다. 작동합니다! –

관련 문제