AlambicEdit Rotate pages 180 when Odd

I need to rotate all the odd pages of a Letter sized PDF files.
I’m using the merge2 method, but I can’t seem to get the merged page to display other than a blank page. I’m thinking that it has something to do with the PdfRect.

I’m starting with this forum post. So understand that on the even pages that the InsertFrom2 method should be used.

Workflow Script to rotate landscape pages in PDF

No matter what I’ve done I can’t seem to get 180 rotation to work.

Something like this should work (I converted to JavaScript the code you referred to):

var objFSO = new ActiveXObject("Scripting.FileSystemObject");
var objFile = objFSO.GetFile(Watch.GetJobFilename());
var tempFileName = Watch.GetJobFilename()+".tmp";

var myPDF = Watch.GetPDFEditObject();
myPDF.open(Watch.GetJobFileName(),false);

var myRotatedPDF = Watch.GetPDFEditObject();
myRotatedPDF.create(tempFileName);

var myRect = new ActiveXObject("AlambicEdit.PdfRect");
var myRect = myPDF.Pages(i).size();

for(var i=0;i<myPDF.Pages().Count();i++){
  if(i%2==0){
    var pw=myPDF.Pages(i).MediaSize().right;
    var ph=myPDF.Pages(i).MediaSize().top;
    myRotatedPDF.Pages().insert(i, myRect);
    myRotatedPDF.Pages(i).merge2(myPDF.Pages(i),pw,ph,180,1);
  }else{
    myRotatedPDF.Pages().InsertFrom2(myPDF.Pages(),i,1,i);
  }
}

CollectGarbage();
myPDF.Close();
myRotatedPDF.save(true);
myRotatedPDF.Close();

objFSO.DeleteFile(Watch.GetJobFileName());
objFSO.MoveFile(tempFileName, Watch.GetJobFileName());
1 Like

Much appreciated! This appears to work, I just need to add in some additional actions, but I believe that I have that covered.

Wondering what I was doing wrong that the rotated page was blank?

No worries on switching to jscript as I’m slowly converting all the vbs because of it being deprecated. I had plans to convert this one after I figured out what the missing commands were. I only went back to VBS because I was failing with my jscript.

On the javascript front within workflow are their any plans on moving from jscript to actual javascript or to add more features in the enhanced jscript?

The script that you based yourself on was for 90 degree rotation through the following command (converted to JS):

myRotatedPDF.Pages(x).merge2(myPDF.Pages(x),0,myRect.Top,90,1);

For 180 degree rotation, you not only need to change the number of degrees but also the origin of the rotation:

myRotatedPDF.Pages(i).merge2(myPDF.Pages(i),pw,ph,180,1);

So your page was being rotated, but outside the visible area.

As for JS within Workflow, we have decided against updating it to a more current version because of the technical limitations of the aging Workflow development environment. The sheer amount of work and the risks associated with it are just not worth it.

However, our Automate product, which is currently available in Tech Preview mode, uses Node-RED technology and therefore offers the very latest version of JavaScript. While it is not yet a full-blown alternative to Workflow, it can already handle the vast majority of tasks that Workflow can.

You can follow its evolution (and try it out for yourself) by visiting the Automate category in these forums and reading its initial post.