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

Discussion

Discussion

Trouble writing C# Script to convert PDF to Base64

posted on January 10, 2022 Show version history

I am in the middle of trying to write a basic script to convert a PDF to base64 using examples from Answers. I have gotten this far where the build runs clean, but when I execute the workflow it says the entry point can't be found.

The problem is with the line of code docExporter.ExportElecDoc(LFDoc, MS); near the bottom of the script. I am wondering if this is because I am trying to pass a DocumentInfo to the ExportElecDoc method which does not accept this type. Yet others are successfully doing it this way.

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 : RAScriptClass110
    {
        /// <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 = "test";

                    // Get DocumentInfo object
            using (DocumentInfo doc = (DocumentInfo)BoundEntryInfo)
            {
                base64String = ExportElectronicToBase64(doc);
            }

    SetTokenValue("base64String", base64String);
        }


private String ExportElectronicToBase64(DocumentInfo LFDoc)
{

    string base64 = null;
        DocumentExporter docExporter = new DocumentExporter();
        using (System.IO.MemoryStream MS = new System.IO.MemoryStream())
        {
            docExporter.ExportElecDoc(LFDoc, MS);
            base64 = "test";

                //Convert.ToBase64String(MS.ToArray());
        }

    return base64;
}

    }
}

 

0 0
replied on January 10, 2022

It sounds like the DocumentServices reference might be pointing to a different version. Do you get a call stack with more details?

0 0
replied on January 10, 2022

Found it, it was actually this line of code throwing the error. So hard to properly narrow it down to the right line number.

SetTokenValue("base64String", base64String);

It was taken from an example, but SetToken is the correct method to use for a self contained script that can be dropped into any existing workflow.

SetTokenValue requires something be setup in the workflow outside of the script instead of the script generating tokens.

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

Sign in to reply to this post.