Adding HyperLink and images to DocxDocument

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
IntegraHarlan
Posts: 72
Joined: Fri Jan 24, 2020 3:37 am

Adding HyperLink and images to DocxDocument

Post by IntegraHarlan »

Hi,
Is there a way to add hyperlinks and images to a DocxDocuments?
For hyperlinks:
I am populating a DocxDocument form a string which is a string from a email body.
The string may have hyplinks in the string. I am using a regex to find the hypelink text and want to replace it with a hyperlink.

For images
I am trying to do something similar with in line images. The string will have a token signifying the image name. I would like to be able to replace the Token with image.

After this I am converting the DocxDocument to a pdf file.

Thanks
Alex
Site Admin
Posts: 1975
Joined: Thu Jul 10, 2008 2:21 pm

Re: Adding HyperLink and images to DocxDocument

Post by Alex »

Hi Harlan,

Current version does not allow to add hyperlink to an existing DOCX document and we will add ability to do this in next minor release. I think functionality will be available in 2 weeks.

Current version allows to add/change/delete image in existing DOCX document. Please see how to set image in DOCX document in the last example here: https://www.vintasoft.com/docs/vsimagin ... ntent.html. Let me know if you will have any question or problem.

Best regards, Alexander
IntegraHarlan
Posts: 72
Joined: Fri Jan 24, 2020 3:37 am

Re: Adding HyperLink and images to DocxDocument

Post by IntegraHarlan »

I tried the method of adding images to DocxDocuments according to the example you pointed me to.
The issue I have is that There already has to be an existing image in the DocxDocument to replace with the image I am trying to add.
I could not find a way of actually adding an image to the docxdocument.
Alex
Site Admin
Posts: 1975
Joined: Thu Jul 10, 2008 2:21 pm

Re: Adding HyperLink and images to DocxDocument

Post by Alex »

IntegraHarlan wrote: Wed Jun 30, 2021 7:29 pm I tried the method of adding images to DocxDocuments according to the example you pointed me to.
The issue I have is that There already has to be an existing image in the DocxDocument to replace with the image I am trying to add.
I could not find a way of actually adding an image to the docxdocument.
The DocxDocumentEditor class uses document template and creates new document from template.

If you want to add image to DOCX document, you need to do the following steps:
  • Using MS Word:
    • Add image object to the document template - this image object must have all necessary formatting (inline, anchor, size, etc) and will be used as a template for image in result document. You can add this object and the end of template document and delete object in the result document.
  • In the code:
    • Get template image object (instance of OpenXmlDocumentImage class) using DocxDocumentEditor.Images[X] property.
    • Create clone of template image object using OpenXmlDocumentImage.Clone method.
    • Set image (bitmap) in image object using OpenXmlDocumentImage.SetImage method.
    • Insert clone of template image object (instance of OpenXmlDocumentImage class) to the desired position in result document.
    • Delete template image object from result document if template image object is not necessary in result document.
Best regards, Alexander
Alex
Site Admin
Posts: 1975
Joined: Thu Jul 10, 2008 2:21 pm

Re: Adding HyperLink and images to DocxDocument

Post by Alex »

Hi Harlan,
Is there a way to add hyperlinks and images to a DocxDocuments?
In VintaSoft Imaging .NET SDK 10.1.2.1 we have added the DocxDocumentEditor.SetHyperlink method, which allows to set the hyperlink for specified text content. Please use this method and let me know if you will have any question or problem.

Best regards, Alexander
Post Reply