Replace image inside .docx or .pdf in .net core c#

Hi,

I have a document in word (.docx), which then I transform it into .pdf, either within the word or the pdf I need to change an image (the image is always the same), 
I have looked for examples without reaching any solution

this is my c# net core code

var templatePath = "mypath\file.docx";
var docStream = new FileStream(templatePath, FileMode.Open, FileAccess.Read);
var wordDocument = new WordDocument(docStream, FormatType.Automatic);
//code replacing some values insde .docx
var docIORenderer = new DocIORenderer();
PdfDocument pdfDocument = docIORenderer.ConvertToPDF(wordDocument);
docIORenderer.Dispose();
wordDocument.Dispose();

var memoryStream = new MemoryStream();
pdfDocument.Save(memoryStream);
memoryStream.Position = 0;
pdfDocument.Close(true);

string fileName = "Output.pdf";
var file = File(memoryStream, "application/pdf", fileName);

Could you help me solve the problem described based on this code?

1 Reply 1 reply marked as answer

HC Hemalatha Chiranjeevulu Syncfusion Team January 28, 2021 07:52 PM UTC

Hi Patricio,

Thank you for contacting Syncfusion support.

From the given details, we suspect that your requirement is to replace the existing image in the Word document. To achieve your requirement, we suggest you to use the code snippet in the below UG documentation at your end.

https://help.syncfusion.com/file-formats/docio/working-with-paragraph?cs-save-lang=1&cs-lang=asp.net%20core#replace-image

Please let us know if you have any other questions.

Regards,
Hemalatha C 


Marked as answer
Loader.
Up arrow icon