Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Tag to image not work #466

Open
BenLampson opened this issue Nov 27, 2023 · 1 comment
Open

Replace Tag to image not work #466

BenLampson opened this issue Nov 27, 2023 · 1 comment

Comments

@BenLampson
Copy link

BenLampson commented Nov 27, 2023

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.

@XceedBoucherS
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants