插入图片到Word文档TextBox
Insert image into Word document TextBox
我正在使用 GemBox.Document 从模板生成输出文档。我想在 TextBox 中插入一个图像,该图像的大小与该 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));
尝试以下操作:
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)));
希望对您有所帮助。
我正在使用 GemBox.Document 从模板生成输出文档。我想在 TextBox 中插入一个图像,该图像的大小与该 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));
尝试以下操作:
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)));
希望对您有所帮助。