How to determine number of pages in a document?

Hi, how can I determine the number of pages in a document set?

The ‘classic’ metadata, either in workflow or design, seems to no longer give this information (though there is a ‘page total’ function in design, so the information is there somewhere!).

Basically I’m looking for the equivalent of the ‘MyMeta.Job.Group(x).Document(y).Count’ in workflow or the ability to add a metadata field in design.

Is this still possible?

Thanks

Barry

1 Like

Hi Barry,

You can add the number of pages in a document to the page By using the additional content options n the output settings.

To do this select additional content and then add a new text field in the text options. You can then add the document number the document pages (number of pages in this document) and the docuemnt page number in a suitable position and font on your page. You can also include logic so the text is only added on certain pages for example only on the first or last page.

If you need this information to be brought into your workflow as a field for more advanced processing, I’d advise you to contact you local support Team who will be happy to help you build on this to achieve what you need.

Hope this helps

ALex Banahene

Thank you for your advice Alex.

Putting the actual page total on the design itself is easy enough (using the {##} field-function) but passing that Document page total value through to the workflow, or indeed a system metadata field/job info, seems to be an issue.

Metadata in the Connect workflow no longer works as it did. By that I mean that while the correct number of datapages in a document is shown in the system metadata, a value of 1 is always returned if the value is selected and passed through to a custom metadata field.

I’m guessing that this is a work-in-progress still but I hope that this is rectified in the very near future.

Thanks again :slight_smile:

Barry

Was this ever resolved? How, in Workflow, does one retrieve the number of Pages per Document? I tried “Retrieve items” after the Create Output step but all the “Pages in Document” values are set to “1”.

Barry,

I got this script from pre-sales, I think Phil wrote it. It retrieves the contentSet, loops through it, adding Page Count to the Document node.

Important notes:

  • The ‘Execute Data Mapping’ Action should have the “Output records in Metadata” option set. This exposes the Connect database records as external (legacy) Metadata.
  • You’ll run the script AFTER the ‘Create Print Content’ Action, as there is no content nor contentID until after this runs.
  • Do NOT check the “Update Records from Metadata” in the ‘Create Print Content’ Action. For some reason this causes the script to return blank values for the page counts.
  • Whatever field name you use in the script (I use ‘_vger_fld_pndPAGECOUNT’), should be in the Data Map (which in my case is a field named ‘pndPAGECOUNT’; Connect adds the “vger_fld” prefix). This isn’t strictly necessary. If you only need the Page Count inside of Workflow, you can bypass this. For my needs, I have other external Metadata Fields I add in a separate branch that I need for the Separation functionality within Connect’s Output Preset. In other words, I need to push my external (legacy) / Workflow Metadata back into Connect so the job and output presets can use it as INTERNAL Metadata.
  • If you do need to push the legacy Metadata back into Connect content, use the ‘Update Data Records’ Action after the script executes.
  • I added a “totalPages” local variable because I also needed a total page count, since “Pages in Group” is also defunct in Connect.

Note to OL R&D:

This split between internal/Connect Metadata and external/Workflow Metadata is maddening. I think if a script is required in order to get something as basic as “how many pages are in each document”, that is indicative of a missing standard plugin.

The ‘Create Print Content’ Action needs another option to “Update Metadata with Connect Content” or something as an option, and that option, when checked, should update the legacy Metadata Properties, such as “Pages in Document”.

It seems the “Retrieve items” Action should generate updated, correct Metadata, making the script obsolete, but I couldn’t get it to work. The Help Pages do not explain the Name value or how it relates to the ‘Set Property’ Action, and when I finally got it to run, the Metadata does not have accurate page count information.

Thomas Greer

var xhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
var metaFile = new ActiveXObject(“MetadataLib.MetaFile”);
metaFile.LoadFromFile (Watch.GetMetadataFilename());
var metaJob = metaFile.Job();
var metaGroup = metaJob.Group(0);
var totalPages = 0;

var contentsetid = Watch.ExpandString(“GetMeta(_vger_contentset_id[0], 10, Job.Group[0])”);

var url = “http://localhost:9340/rest/serverengine/entity/contentsets/” + contentsetid + “/pages?detail=true”;
xhttp.open(‘GET’,url,false);
xhttp.setRequestHeader(‘Content-Type’, ‘application/json’);
xhttp.onreadystatechange = handlerGetDataRecord;
xhttp.send();

Watch.SetVariable(“totalPages”, totalPages);

function handlerGetDataRecord()
{
if (xhttp.readyState == 4) {
if (xhttp.status == 200) {
var contentsetPageDetails = JSON.parse(xhttp.responseText);
var contentsetPageDetailMap = {};
for (var idx=0; idx < contentsetPageDetails.length; idx++) {
contentsetPageDetailMap[‘’+contentsetPageDetails[idx].id] = contentsetPageDetails[idx].pages[0].count;
}
for (var idx=0; idx < metaGroup.Count; idx++) {
var contentItemId = metaGroup.Item(idx).FieldByName(‘_vger_contentitem_id’);
metaGroup.Item(idx).Fields.Add(‘_vger_fld_pndPAGECOUNT’, contentsetPageDetailMap[contentItemId]);
totalPages += contentsetPageDetailMap[contentItemId];
}
metaFile.SaveToFile (Watch.GetMetadataFilename());
}
}
}

2 Likes

Hi!
I’ve been trying to get the script above work, but it fails to run with the following error:

W3602 : Error 0 on line 14, column 1: msxml3.dll: Access denied.

Is there a known way to fix this?

Regards,
Roland

You likely have Connect Security turned on.

Thanks, I got it working.

Is there a way to write metadata to a page with the _metaGroup.Item(idx).Fields.Add(‘vger_fld_pndPAGECOUNT’, function?
I’m thinking of something like _metaGroup.Item(idx).Fields(XY).Add(’_vger_fld_pndPAGECOUNT’, (where XY is the page number in the current document)

Thanks,
Roland_

I just ran into the same issue.

Did you find a solution to this?

Hi

Ha there been a solution to this as I have the same problem.

Regards

James

Hi @jbeal84,

Which issue are you currently facing? Are you not able to execute the by Thomas shared script because of the following–by Roland shared–error message, for example?

W3602 : Error 0 on line 14, column 1: msxml3.dll: Access denied.

Please note that you can solve this by adding the username and password of the PlanetPress Connect Server to the following line of JavaScript code:

xhttp.open("GET", url, false);

The above line of JavaScript code needs in this case be changed to something like:

xhttp.open("GET", url, false, "username", "password");

Hi,

Sorry I mean around a easier way of getting the count rather than the above work around

James

Hi @jbeal84,

I’ve done my best to make the solution of adding the record field “pageCount” to the metadata as compact as possible but I assume that you still need use a couple of lines of JavaScript code to add the page count to the metadata.

var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
var contentSetId = Watch.ExpandString("GetMeta(_vger_contentset_id[0], 10, Job.Group[0])");
var url = ("http://localhost:9340/rest/serverengine/entity/contentsets/" + contentSetId + "/pages?detail=true");

/* IMPORTANT: "username" and "password" needs to be changed to
 * the applied credentials of the Connect Server. */
xmlHttp.open("GET", url, false, "username", "password"); 

xmlHttp.onreadystatechange = function () {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var job = JSON.parse(xmlHttp.responseText);
			var contentSet = {};
			
			for (var i = 0; i < job.length; i++) {
				var contentItemId = job[i].id;
				var pageCount = job[i].pages[0].count;
				
				contentSet[contentItemId] = pageCount;
			}
			
			var metaFile = new ActiveXObject("MetadataLib.MetaFile");
			
			metaFile.LoadFromFile(Watch.GetMetadataFilename());
			
			var metaJob = metaFile.Job();
			var metaGroup = metaJob.Group(0);
			
			for (var i = 0; i < metaGroup.Count; i++) {
				var contentItemId = metaGroup.Item(i).FieldByName("_vger_contentitem_id");
				
				metaFile.Job().Group(0).Item(i).Fields.Add("_vger_fld_pageCount", contentSet[contentItemId]);
			}
			
			metaFile.SaveToFile(Watch.GetMetadataFilename());
		}
	}
};

xmlHttp.send();

P.S. Please note that the above JavaScript code is based on the JavaScript code shared by Thomas Greer so the same requirements are still applied. The main difference is that the above JavaScript code does not take the total page count into account.

1 Like

What is the status of the Feature Request to make Workflow Metadata accurate? Connect Document Sets should be analogous to Metadata Groups, etc.

We are looking at providing a Workflow plugin that does this (and other things as well). We have a proof of concept that seems to work, but I can’t give you any more detail on when it will be made available.

I’ll bump it up in our list of priorities.

2 Likes

@Phil did this get put into the new versions?

Not in the 2022.1 version that just came out, but it is scheduled for 2022.2 later this year. It may become available earlier as a separate download, but don’t hold me to that.