DocX icon indicating copy to clipboard operation
DocX copied to clipboard

Replace Tag to image not work

Open BenLampson opened this issue 1 year ago • 1 comments

DocX document = DocX.Load(@"C:\Users\benla\Desktop\a1.docx");
{
    var x =  document.AddImage(@"D:\Codes\BDS\Src\BDS\Z.TestNewDataConverter\bin\Debug\net6.0-windows\tmp\a.png").CreatePicture();


    document.ReplaceTextWithObject("{{@circumferential_distance_img}}", x);
    var zxc = document.ParagraphsDeepSearch;
    // Save changes made to this document.
    //document.Save();
} // Release

image Nothing changed.

BenLampson avatar Nov 27 '23 09:11 BenLampson

Hi, With the Latest version of DocX (v2.5), you can do it this way: // Load a document. using( var document = DocX.Load( "ReplaceTextWithObjects.docx" ) ) { // Create the image from disk and set its size. var image = document.AddImage( "2018.jpg" ); var picture = image.CreatePicture( 175f, 325f );

// Do the replacement of all the found tags with the specified image and ignore the case when searching for the tags. document.ReplaceTextWithObject( new ObjectReplaceTextOptions() { SearchValue = "<yEaR_IMAGE>", NewObject = picture, RegExOptions = RegexOptions.IgnoreCase } );

// Save this document to disk. document.SaveAs( "ReplacedTextWithObjects.docx" ); }

Thanks

XceedBoucherS avatar Nov 29 '23 20:11 XceedBoucherS