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

Question

Question

Count Page Size in Workflow

asked on August 17, 2020

Hi,

Is it possible, with WF and SDK, to count the number of pages, in a selection of documents,  which are of a certain size (A3, A4, A0, etc)? 

Cheers,

Anthony

0 0

Replies

replied on February 23, 2021

Yes, it's possible.

This script loops through all pages of the document, checking it's width and height, then it compares those values to the expected width and height for each different page size, and increments a counter for each page size for each page found.

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;

    /// <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()
        {
            //Set-up Size Variables
            int USLetterPage = 0;       // 8.5" w x 11.0" h
            int USLegalPage = 0;        // 8.5" w x 14.0" h
            int A0Page = 0;             //33.1" w x 46.8" h
            int A1Page = 0;             //23.4" w x 33.1" h
            int A2Page = 0;             //16.5" w x 23.4" h
            int A3Page = 0;             //11.7" w x 16.5" h
            int A4Page = 0;             // 8.3" w x 11.7" h
            int A5Page = 0;             // 5.8" w x  8.3" h
            int A6Page = 0;             // 4.1" w x  5.8" h
            int A7Page = 0;             // 2.9" w x  4.1" h
            int A8Page = 0;             // 2.0" w x  2.9" h
            int A9Page = 0;             // 1.5" w x  2.0" h
            int A10Page = 0;            // 1.0" w x  1.5" h
            int OtherSizePage = 0;          // All Other Sizes

            //Get a reference to the entry...
            DocumentInfo di = Document.GetDocumentInfo(this.BoundEntryId, this.RASession);

            //loop through each page of the document
            for (int i = 1; i <= di.PageCount; i++)
            {
                //Get a reference to the current page and it's size
                PageInfo pi = di.GetPageInfo(i);
                decimal widthInches  = Math.Round(Decimal.Divide(pi.ImageWidth, pi.ImageXResolution), 1);
                decimal heightInches = Math.Round(Decimal.Divide(pi.ImageHeight, pi.ImageYResolution), 1);

                //increment each page counter based on the current page's size
                if      ((widthInches == (decimal) 8.5 && heightInches == (decimal)11.0) || (heightInches == (decimal) 8.5 && widthInches == (decimal)11.0)) USLetterPage++;     // 8.5" w x 11.0" h
                else if ((widthInches == (decimal) 8.5 && heightInches == (decimal)14.0) || (heightInches == (decimal) 8.5 && widthInches == (decimal)14.0)) USLegalPage++;      // 8.5" w x 14.0" h
                else if ((widthInches == (decimal)33.1 && heightInches == (decimal)46.8) || (heightInches == (decimal)33.1 && widthInches == (decimal)46.8)) A0Page++;           //33.1" w x 46.8" h
                else if ((widthInches == (decimal)23.4 && heightInches == (decimal)33.1) || (heightInches == (decimal)23.4 && widthInches == (decimal)33.1)) A1Page++;           //23.4" w x 33.1" h
                else if ((widthInches == (decimal)16.5 && heightInches == (decimal)23.4) || (heightInches == (decimal)16.5 && widthInches == (decimal)23.4)) A2Page++;           //16.5" w x 23.4" h
                else if ((widthInches == (decimal)11.7 && heightInches == (decimal)16.5) || (heightInches == (decimal)11.7 && widthInches == (decimal)16.5)) A3Page++;           //11.7" w x 16.5" h
                else if ((widthInches == (decimal) 8.3 && heightInches == (decimal)11.7) || (heightInches == (decimal) 8.3 && widthInches == (decimal)11.7)) A4Page++;           // 8.3" w x 11.7" h
                else if ((widthInches == (decimal) 5.8 && heightInches == (decimal) 8.3) || (heightInches == (decimal) 5.8 && widthInches == (decimal) 8.3)) A5Page++;           // 5.8" w x  8.3" h
                else if ((widthInches == (decimal) 4.1 && heightInches == (decimal) 5.8) || (heightInches == (decimal) 4.1 && widthInches == (decimal) 5.8)) A6Page++;           // 4.1" w x  5.8" h
                else if ((widthInches == (decimal) 2.9 && heightInches == (decimal) 4.1) || (heightInches == (decimal) 2.9 && widthInches == (decimal) 4.1)) A7Page++;           // 2.9" w x  4.1" h
                else if ((widthInches == (decimal) 2.0 && heightInches == (decimal) 2.9) || (heightInches == (decimal) 2.0 && widthInches == (decimal) 2.9)) A8Page++;           // 2.0" w x  2.9" h
                else if ((widthInches == (decimal) 1.5 && heightInches == (decimal) 2.0) || (heightInches == (decimal) 1.5 && widthInches == (decimal) 2.0)) A9Page++;           // 1.5" w x  2.0" h
                else if ((widthInches == (decimal) 1.0 && heightInches == (decimal) 1.5) || (heightInches == (decimal) 1.0 && widthInches == (decimal) 1.5)) A10Page++;          // 1.0" w x  1.5" h
                else OtherSizePage++;                                                                                                                                                // All Other Sizes
            }

            //Push total page size counts out as token values
            SetToken("USLetterPage", USLetterPage);
            SetToken("USLegalPage", USLegalPage);
            SetToken("A0Page", A0Page);
            SetToken("A1Page", A1Page);
            SetToken("A2Page", A2Page);
            SetToken("A3Page", A3Page);
            SetToken("A4Page", A4Page);
            SetToken("A5Page", A5Page);
            SetToken("A6Page", A6Page);
            SetToken("A7Page", A7Page);
            SetToken("A8Page", A8Page);
            SetToken("A9Page", A9Page);
            SetToken("A10Page", A10Page);
            SetToken("OtherSizePage", OtherSizePage);
        }
    }
}

 

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

Sign in to reply to this post.