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

Question

Question

SDK script to delete PDF after page generation in Workflow

asked on September 4, 2020

I have been using the following script to generate tiff pages from pdf documents:

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.ClientAutomation;
    using System.Diagnostics;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : RAScriptClass104
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {
            //Variables to change for each setup
            string repositoryName = "RepositoryName";
            string ServerNameIp = "LaserficheServerName";
            string entryToBeConv = "EntryIDofEntryToBeConverted";
            int timeToWaitIfFails = 30000;

            //Script
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName = @"C:\Program Files (x86)\Laserfiche\Client\LF.exe";
            startInfo.Arguments = "-W -L\""+repositoryName+"\"";
            process.StartInfo = startInfo;
            process.Start();
            System.Threading.Thread.Sleep(5000);
            try
            {
                using (ClientManager lfclient = new ClientManager())
                {
                    IList<ClientInstance> OpenLFClients = lfclient.GetAllClientInstances();
                    ClientInstance singleLF = OpenLFClients[0];
                    LaunchOptions options = new LaunchOptions();
                    options.ServerName = ServerNameIp;
                    options.RepositoryName = repositoryName;
                    options.HiddenWindow = true;
                    MainWindow main;
                    singleLF = lfclient.LogIn(options, out main);
                    GeneratePagesOptions optionsPages = new GeneratePagesOptions();
                    optionsPages.ShowUI = false;
                    int entryid = Convert.ToInt32(GetTokenValue(entryToBeConv));
                    List<int> id =  new List<int>();
                    id.Add(entryid);
                    main.GeneratePages(id, optionsPages);
                    singleLF.Close(false);
                    SetTokenValue("Completed", true);
                }
            }
            catch(Exception ex)
            {
                System.Threading.Thread.Sleep(timeToWaitIfFails);
            }
            process.Kill();
        }
    }
}

Ordinarily, I'd use this in conjunction with "Create Entry" and "Move Pages" to create a new Tiff version of the document, then use "Delete Entry" to get rid of the PDF.

The question is, is there a way to delete the PDF version of the original document, leaving the Tiff version with the original Entry ID/metadata/etc?  I have a use case where this would be useful.  I know there must be a way to do this with an SDK script, since it's a functionality built into the client, like page generation, but I don't know how to script it.

Any ideas?

0 0

Replies

replied on September 4, 2020

Hi Paul!

You can use DocumentInfo.DeleteEdoc() ... so ....

DocumentInfo docInfo = new DocumentInfo(entryId, RASession);

docInfo.DeleteEdoc();

That being said ... how are these documents making it into the repository?  I'm only asking because generating pages could be automatically handled with other tools.

Also, does the use case demand pages to be generated?  It's going to greatly increase your disk space consumption.  I've also run into alot of problems generating pages using ClientAutomation, that's why I use Import Agent or QuickFields Agent to handle that.

Finally, I get why you're waiting, at the beginning, for the client to launch, but curious why there's a wait if it fails? 

 

0 0
replied on September 8, 2020

Hey Rick,

Thanks for the reply.  These PDFs have often been imported manually using drag and drop.  Unfortunately, that's a side of the process that I have little control over.  As for the use case, we're using this to combine a new document (tiff pages) with an old document (possibly pdf, possibly pages), but using the doc ID of the old doc.  Thus, I need to be able to convert in order to have a combined, consistent doc, but retain the old doc ID.

As for the wait if it fails, I'm really not sure as I didn't originally write the code and I'm not very knowledgeable with coding.  I can look at it and tell you basically what it does, but as for altering it in any significant way, I'm a bit lacking. :(

So all that being said, how would I add the DocumentInfo.DeleteEdoc() into my code?  

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

Sign in to reply to this post.