locked
Using OpenXml to Place base64 Image on MSWORD RRS feed

  • Question

  • User-849204934 posted

    i am trying to use OpenXml to place a base 64 signature on a Word document. I have not seen how to use it tho but i decided to try something, and since I am very new (Open Xml) to this I decided to put this on here.
    I have successfully been able to use content controls to ascertain where the signature would be dropped, i got lost along the line as I am quite new to it, i know the opening of the file part but here comes the main trouble, putting the base64 string (after its being converted to image) to a content control and saving the word Document

    Code looks like this :

    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.IO;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Xml;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml.Wordprocessing;
    
    namespace ContentControlTestWord
    {
        public partial class PlaceimageText : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void Button2_Click(object sender, EventArgs e)
            {
                string constring = @"Data Source=DESKTOP-9CM4N5S\SQLEXPRESS;Initial Catalog=SignatureBox2;User ID=sa;Password=123456;";
                using (SqlConnection con = new SqlConnection(constring))
                {
                    con.Open();
                    string query = "select * from SignatureBox_DB where StaffID = @StaffID";
                    using (SqlCommand cmd = new SqlCommand(query, con))
                    {
                        cmd.Parameters.AddWithValue("@StaffID", TextBox1.Text);
                        using (SqlDataReader rd = cmd.ExecuteReader())
                        {
                            try
                            {
                                if (rd.Read())
                                {
                                    string filePath = "~/ImagesSignature/";
                                    string myFile = "sinature.jpg";
                                    string fileName = Path.Combine(filePath, myFile);
    
                                    byte[] imageBytes = Convert.FromBase64String(rd["SignatureBase64"].ToString());
                                    MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
                                    ms.Write(imageBytes, 0, imageBytes.Length);
                                    File.WriteAllBytes(Server.MapPath(fileName), imageBytes);
    
                                    string myphysicalPath = System.Web.HttpContext.Current.Server.MapPath(fileName);
                                    using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(@"C:\Users\emi\Desktop\Jasmine.docx", true))
                                    {
                                        SdtElement s3 = wordprocessingDocument.MainDocumentPart.Document.Descendants<SdtElement>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == "Jasmine").Single();
                                        //Save image in content control  and save document, where Jasmine is the name of the Content Control
                                        Text t = s3.Descendants<Text>().Single();
                                    }
                                }
                            }
                            catch(Exception ex)
                            {
                                Response.Write(ex.ToString());
                            }
                        }
                    }
                }
            }
        }
    }

    Sunday, September 22, 2019 1:37 PM

All replies

  • User665608656 posted

    Hi Samriz,

    According to your description, after you getting the content control, you need to use FileStream to insert the image into it.

    For more details, you can refer to the following code:

                string filePath = "~/ImagesSignature/";
    string myFile = "sinature.jpg";
    string fileName = Path.Combine(filePath, myFile); byte[] imageBytes = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAQYAAADACAMAAADRLT0TAAAABGdBTUEAALGPC/xhBQAAAURQTFRF////aD0bAAAAGhoa/38AGBkaaz4bFRgayHE3041fFhkaGBgYGxsbERca/4EAFhYWERERYTobDQ0NZDsbIR0aXTgb+Pj4Jh8aKyEaTDAbVzUb8fHx3d3dycnJUDIbLyMaWFhY1NTUOjo6d3d3NCUa6enptLS0Z2dnmpqajo6OMTExhYWFOScaKSkpg1pawcHBqKioYGBgSkpKRi0bIhQJQUFBbGxsNR8OtJ+fvaqqQicRFg0GLS0t1svLMx4N6XQAjGdnl3d3ooaGxoRZz2cAqI+PABIbHhEIjkcAxra2k3FxvGo06nUAnk8AAAkbXy8A1msARiMAfj8AaTQAqlUAsndQnVkrjE8mhVk8KxEAul0APx8AlksAyHdGmmdGZkQucVdXQTQ3XkNEJgoAOBcAekUhbkkyqF8uuXVRn186VDgmgFU6E/YKJAAAAAlwSFlzAAAOwwAADsMBx2+oZAAAIkpJREFUeF7dXft/2ka2N4MZJVggECBsEO+HwYB52Y4fsYMdp4ldd/Pc3Tbtbru77e69e///3+85Z0YgQLyMlNj59tMkBiw0X533nJnZeDgw0mam2qnVS7v5w+Le85aqqnuH+aNSrWoa8iPfNC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yIOWeYuQEuvpAQYWOh3ddDpWRNJdFxvqS2nkoDp7lJQoQdfh3/4IQC5OLCRgSVOEnD7PkDF0D5BEJnxa9pGadRaWiSCMLUYU1uQgrDFmP5Lx00Lka6tmfbwcFaV+cJ0Aj75YEwDw9G9dA6xdYfiMtbdh+y6bXx5TLJlZHB7XSIiftOVS5GDGVhnabXLwGjmhf7zoc84oHCM7+7Kw48QaVGW8J54y2kSnhTbXQZYpmucs9GhrmIYtVJ2/r6YeMyqAkekktsOLcixBnAD89ROqMhqnTKyrO388FFn+OjUAlCTSzTVZJuBhCisBXxYqWiV5DzOgFl271qHLGgjW8X/tBhHgqBCIRyY0ff3x80P7n1aAyDhZrMPFea158FHqVGHvfOdv9yMHsyzQgoank93eA7NCm15dXMnLfIFK18K6j4m/eeuOAxa37y8cmCAOZbxAMqR6Ccja5OBY/1xfxk5NHZBRsyXZFlIIJKMNnMJnBCT45xIYAEaybi+cNMrZeFidvgW1UZ7ADBFhictF5EBnwg1ZQkfOH5SW/QPlJHTKDNVEJKvNzfSeFZe0TIBCP4c9Ta2Bxto/pwio7rIN0u7Q1XQhCooyWkypn/bEpM7tM8fyqVbebi2PEgwJY94vcxwBCn22B/nB1WH4jooFJVsCDYCCbrrqgOay1PfZAwMrUeroqx7747D5rOIg+54LYOzHYjv0cNlZOSMQbsuXxe+jZswiwYlUK1TtuFCdBBBkJCNC1C2+So3Ub72zEJc2EY6UKbzgrt9orFvVZL9beKve5Ro9aecw6KG9jY+H9WUYeL18r74AAAAABJRU5ErkJggg=="); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); ms.Write(imageBytes, 0, imageBytes.Length); File.WriteAllBytes(Server.MapPath(filePath), imageBytes); string myphysicalPath = System.Web.HttpContext.Current.Server.MapPath(fileName);
    using (WordprocessingDocument doc = WordprocessingDocument.Open(@"C:\Users\emi\Desktop\Jasmine.docx", true)) { SdtBlock cc = doc.MainDocumentPart.Document.Body.Descendants<SdtBlock>() .FirstOrDefault(c => { SdtProperties p = c.Elements<SdtProperties>().FirstOrDefault(); if (p != null) { // Is it a picture content control? SdtContentPicture pict = p.Elements<SdtContentPicture>().FirstOrDefault(); // Get the alias. SdtAlias a = p.Elements<SdtAlias>().FirstOrDefault(); if (pict != null && a.Val == "Jasmine") return true; } return false; }); string embed = null; if (cc != null) { Drawing dr = cc.Descendants<Drawing>().FirstOrDefault(); if (dr != null) { Blip blip = dr.Descendants<Blip>().FirstOrDefault(); if (blip != null) embed = blip.Embed; } } if (embed != null) { IdPartPair idpp = doc.MainDocumentPart.Parts .Where(pa => pa.RelationshipId == embed).FirstOrDefault(); if (idpp != null) { ImagePart ip = (ImagePart)idpp.OpenXmlPart; using (FileStream fileStream = File.Open(myphysicalPath, FileMode.Open)) ip.FeedData(fileStream); } } }

    For more details, you can refer to this link : How to insert picture into Picture Content control in Word using Open XML

    Best Regards,

    YongQing.

    Monday, September 23, 2019 9:14 AM