OL Learn

Rotating PDF pages prior to Datamapping

What’s the best method to rotate pages prior to datamapping? I have edit: portrait pages which I need to rotate 90 degrees in order to datamap them properly. Is this a possible preprocessor step? Or something best one with a script in workflow?

I attempted to use the auto-rotate feature with the Digital Action plugin, but it turns the PDF into an image file which is non-text searchable and therefore not useful to me.

Thank you in advance,

Kyle

Hi Kyle,

There are posts on here that shows rotating PDF’s in a script in Workflow. Would be interesting if it can be done in the mapper and if not implemented by OL.

Link

I also have this one. I can’t find the post here but it was supplied to a member by either Phil or Rod. (I think)

'VBScript: Auto find landscape pages and make them portrait.

dim myPDF, myRotatedPDF, myRect
dim x, pageHeight, pageWidth, tempright, myRotatedPDFName

myRotatedPDFName = Watch.GetOriginalFileName
Set myPDF = Watch.GetPDFEditObject
myPDF.open Watch.GetJobFileName,false
Set myRotatedPDF = Watch.GetPDFEditObject
myRotatedPDF.create “E:\OLForums\156122\tempPDF\” & myRotatedPDFName

Set myRect = CreateObject(“AlambicEdit.PdfRect”)

for x = 0 to myPDF.Pages.Count-1
Set myRect = myPDF.Pages(x).size
pageWidth = myRect.Right
pageHeight = myRect.Top
if (pageWidth < pageHeight) then
myRect.Bottom = 0
myRect.Left = 0
myRect.Top = 842 'height in points for A4
myRect.Right = 595 ’ width in 595 points for A4
myRotatedPDF.Pages.insert x, myRect
myRotatedPDF.Pages(x).merge2 myPDF.Pages(x),0,0,0,1
else
tempright = myRect.Right
myRect.Right = myRect.Top
myRect.Top = tempright
myRotatedPDF.Pages.insert x, myRect
myRotatedPDF.Pages(x).merge2 myPDF.Pages(x),0,myRect.Top,90,1
end if
next
myRotatedPDF.save false

EDIT: So the idea is to use the script to rotate some PDF’s so you can map them. Then going forward the script will rotate future PDF’s before the All In One or Execute Data Mapping plugins.

EDIT2: Tip: Searching forums using their supplied search function is not always useful. So what I do is type a question in google followed by site:learn.objectiflune.com to get better search results.

I hope that helps.

Regards,

S

Sharne,

Thank you very much. I initially tried the VBScript, but quickly realized it was for rotating landscape TO portrait (I realize the error in my request). I actually needed the opposite, and I wasn’t quite sure which numbers to change in order to make that work.

Instead, I followed the provided link and used that javascript code and it’s working! Thank you very much.

For anyone who finds this in the future,

  1. Create a workflow process which takes your PDF (mine is from a folder capture source)

  2. Run Script Plugin with the below code set as language “javascript”:

var pdf = Watch.GetPDFEditObject();
var test
pdf.Open(Watch.GetJobFileName(),false);
for (i=0; i < pdf.Pages().Count(); i++)
{
Test = pdf.Pages(i).Orientation;
if (Test == 90)
{
pdf.Pages(i).Orientation = 0
}
}
pdf.Save(false)

The above code will take a PORTRAIT page and rotate to be LANDSCAPE.

  1. Output your file (send to folder, rename as .pdf).

Thanks again for all the help!

1 Like

Hi Kyle,

Glad the info I had helped.

Regards,

Kyle, your JavaScript code works fine as long as the page’s orientation is actually set to 90 (which means it is a rotated landscape page on which you want to eliminate the rotation element). In many PDF files, a landscape page and a portrait page both have the Rotation angle set at 0 and the only difference between both is the width-to-height ratio.

So for other users who may run into these kinds of PDFs: know that you can also take a look at each page’s height and width to determine whether or not you should rotate them.

Hi Phil,

I have a job where the pages alternate between portrait and landscape and have tried using the below, but its rotating all page, any ideas?

var pdf = Watch.GetPDFEditObject();

pdf.Open(Watch.GetJobFileName(),false);

for (i=0; i < pdf.Pages().Count(); i++){
var Odd = i
Odd = Odd%2;
if (Odd=1)
{
pdf.Pages(i).Orientation = 270;
}
else
{
pdf.Pages(i).Orientation =0;
}
}
pdf.Save(true);

This works for me:

var pdf = Watch.GetPDFEditObject();
pdf.Open(Watch.GetJobFileName(),false);
for (i=0; i < pdf.Pages().Count(); i++){
  pdf.Pages(i).Orientation = (i%2) ? 270 : 0;
}
pdf.Save(true);