You are viewing limited content. For full access, please sign in.

Question

Question

Add Multiple images to a word document table

asked on May 24, 2019

I would like to fill a word doc with X number of images with 2 per page.  These images are coming from a forms attachment.  I am using the script Maher suggested here to convert my images to a base64 string.

I then write the base64 string to a SQL table, because the update word doc activity only can only fill a word table from a forms table or a SQL table (as far as I know). 

The issue is that when I try to insert the images from the SQL table the word doc does not fill the image merge field. 

I am able to fill a single image if I use the simple field merge and point to the script activity directly. Is this an issue with workflow itself?  I don’t see why this wouldn’t work as is.

4 0

Answer

SELECTED ANSWER
replied on June 3, 2019

Updating Workflow to 10.4 resolved the issue.

1 0

Replies

replied on September 22, 2019

Hi Josh,

I'm attempting something similar, and i'm hoping you can help me out. I'm planning on using a Forms collection to for onsite inspection photos., and an associated description. These will be used to have an a image and associated caption.

I don't understand why you are using "For Each Row" and what the source of row data would be ?  I'm asking as according to Mahers code, it is for saving images that are already in Laserfiche repository.

 

Any enlightenment would be great

 

 

 

0 0
replied on October 2, 2019

Hi Josh,

Would you be kind to explain how you did it, I have a similar need to get data from Forms into Word.

 

Regards,

Sahil

0 0
replied on October 8, 2020

I have a similar use case where I'm needing to populate a few Word tables containing image columns. Forms is collecting the table info (including an upload field) and kicking off the workflow. I would appreciate any additional information on this topic!

I have tried converting the images to a base64 string, storing them in a SQL table, retrieving the rows and pointing to them within the Word Table Merge activity. Half the time the string would fail to be inserted in the SQL table. I saw in Maher's post that there are size limitations for tokens, so I'm assuming the images I was testing were rendering too large of a string. Even when I used smaller images, the image merge fields were showing up empty on the Word doc. I couldn't get it to work with a single merge field either. 

I'm using WF 10.4.2.246

0 0
replied on October 12, 2020

There are no size limitations to tokens. The value is truncated to 3700 characters when tracked, but not at runtime.

1 0
replied on October 12, 2020

Thanks for the info Miruna!

Are you able to provide any guidance for merging Forms tables with images into a Word table?

0 0
replied on October 19, 2020

Can you post your Workflow and any scripts you're using? Maher's example works for me with tables too.

 

0 0
replied on October 19, 2020

Here is the workflow that I am using while trying to prove concept so it doesn't have all the complications of the actual use case. I am grabbing the image file uploaded from the form, saving it to the repository, then running the script (posted below) and attempting to create the document.


Here is the script. I don't 'speak' C# so I didn't write this - it was put together by someone else from our team. But if there is anything wrong, I can certainly update it. 

namespace WorkflowActivity.Scripting.SDKScript
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using Laserfiche.RepositoryAccess;
    using Laserfiche.DocumentServices;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : RAScriptClass100
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {
            // Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
            String base64String = null;
            try
            {
                // Get EntryID from the FindEntry activity
                //int iDocID = (int)GetTokenValue("CreateEntry2_OutputEntry_ID");

                // PK 10/5/2020 Get the document using the Workflow connection
                using (DocumentInfo DocInfo = (DocumentInfo)BoundEntryInfo)
                //using (DocumentInfo DocInfo = Document.GetDocumentInfo(iDocID, RASession))

                {
                    // Create MemoryStream to hold exported document
                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                    {
                        // Create DocumentExporter object
                        DocumentExporter de = new DocumentExporter();
                        //PK 10/5/2020 Export to Electronic Document
                        de.ExportElecDoc(DocInfo, ms);

                        // Export to PDF in MemoryStream
                        //de.ExportPdf(DocInfo, DocInfo.AllPages, PdfExportOptions.None, ms);

                        // Write MemoryStream data to Base64 string
                        base64String = Convert.ToBase64String(ms.ToArray());
                    }
                }
            }
            catch (Exception ex)
            {
                // Report exception message
                WorkflowApi.TrackError(ex.Message);
                // Set return value to null
                base64String = null;
            }
            // Return the Base64 String
            SetTokenValue("tknImageData", base64String);


        }
    }
}

My SQL column containing the base64 string is configured as nvarchar(max). I also took a screenshot showing how my Word table is formatted. The 'Value' column has been left blank intentionally for testing.

0 0
replied on October 20, 2020 Show version history

@████████, my VAR was able to guide me through the issue, sorry for bugging you! 

In case it helps anyone else in the future, I found out that I needed to prepend "data:image/png;base64," before the base64 string which would start with something like "/9j/4AAQSkZJRgABAQEASABIAAD......." prior to inserting it into the table merge field. I tested the solution with JPGs, PNGs, and TIFFs and they were all successful.

Shout out to Andrew at Cities Digital for the advice that saved the day! 

3 0
replied on October 22, 2020

No worries. I got side-tracked and couldn't answer for a couple of days, but yes, that was the problem. Good to know you got an answer.

For the record, the script above does not check that document you're converting is an image. If you're not checking for the extension on the Forms' side, you might want to add that to the script.

1 0
replied on October 22, 2020

Thanks for the heads up! I am limiting the file types on the Form upload fields but that's good to know for future scenarios where that may not be the case. I made a comment on the script just in case we use it for something else smiley Thanks again!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.