Author Topic: UPDATE to Rotate Pages Command  (Read 10132 times)

0 Members and 1 Guest are viewing this topic.

nightslayer23

  • Newbie
  • *
  • Posts: 98
UPDATE to Rotate Pages Command
« on: August 03, 2017, 03:14:45 AM »
Can we get an update for the Rotate Pages Batch Command to incorporate the parameter of Landscape or Portrait pages?

At the moment it can only rotate by page numbers, if it could rotate "portrait pages only" or something it'd be awesome!

RTT

  • Administrator
  • *****
  • Posts: 918
Re: UPDATE to Rotate Pages Command
« Reply #1 on: August 04, 2017, 01:28:48 AM »
In the next version, 3.2, it will be possible to use the words "landscape" and "portrait" as page selectors, in any of the tools that have the possibility to define the list of affected pages. I have it already implemented, as depicted in the attached screenshot.

Even so, you can do it already with a script.
Here's one that rotates all the portrait pages by 90 degrees:
Code: [Select]
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    try {
        var Pages = pdfe.SelectedFiles(i).Pages;
        var RotatedPagesCount = 0;
        for (var PageIndex = 0; PageIndex < Pages.Count; PageIndex++) {
            var Page = Pages(PageIndex);
            if (Page) {
                //Note: this rotation angle check should be removed for versions>3.1.x           
                if (Page.Rotation == 90 || Page.Rotation == 270) {
                    var w = Page.Height;
                    var h = Page.Width;
                } else {
                    var w = Page.Width;
                    var h = Page.Height;
                }

                if (h > w) {
                    Page.Rotation = Page.Rotation + 90;
                    RotatedPagesCount++;
                }
            }
        }
        if (RotatedPagesCount) {
            if (Pages.CommitChanges(pdfe.SelectedFiles(i).Filename + '(rot).pdf')) {
                pdfe.echo(pdfe.SelectedFiles(i).Filename + ' (rotated ' + RotatedPagesCount + ' pages)');
            } else {
                pdfe.echo(pdfe.SelectedFiles(i).Filename + ' (failed to commit changes)', 0xFF0000);
            }
        } else {
            pdfe.echo(pdfe.SelectedFiles(i).Filename + ' (nothing to rotate)');
        }
    } catch (e) {
        pdfe.echo(pdfe.SelectedFiles(i).Filename + ' :' + e.message, 0xFF0000);
    }
}
pdfe.echo("Done");

nightslayer23

  • Newbie
  • *
  • Posts: 98
Re: UPDATE to Rotate Pages Command
« Reply #2 on: August 04, 2017, 05:04:30 AM »
awesome! thank you

nightslayer23

  • Newbie
  • *
  • Posts: 98
Re: UPDATE to Rotate Pages Command
« Reply #3 on: August 04, 2017, 05:58:15 AM »
question though... can we get it to save over the original file or save it to another location with the same filename?

RTT

  • Administrator
  • *****
  • Posts: 918
Re: UPDATE to Rotate Pages Command
« Reply #4 on: August 07, 2017, 04:05:16 PM »
question though... can we get it to save over the original file or save it to another location with the same filename?
The relevant line is:
if (Pages.CommitChanges(pdfe.SelectedFiles(i).Filename + '(rot).pdf')) {

To save over, replace it by:
if (Pages.CommitChanges() {

To save to another location, replace it by:
var Filename=pdfe.SelectedFiles(i).Filename;
if (Pages.CommitChanges('c:\\your\\other\path\\'+Filename.substr(Filename.lastIndexOf('\\') + 1)) {

nightslayer23

  • Newbie
  • *
  • Posts: 98
Re: UPDATE to Rotate Pages Command
« Reply #5 on: August 21, 2019, 02:48:21 AM »
In the next version, 3.2, it will be possible to use the words "landscape" and "portrait" as page selectors, in any of the tools that have the possibility to define the list of affected pages. I have it already implemented, as depicted in the attached screenshot.

Even so, you can do it already with a script.
Here's one that rotates all the portrait pages by 90 degrees:
Code: [Select]
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    try {
        var Pages = pdfe.SelectedFiles(i).Pages;
        var RotatedPagesCount = 0;
        for (var PageIndex = 0; PageIndex < Pages.Count; PageIndex++) {
            var Page = Pages(PageIndex);
            if (Page) {
                //Note: this rotation angle check should be removed for versions>3.1.x           
                if (Page.Rotation == 90 || Page.Rotation == 270) {
                    var w = Page.Height;
                    var h = Page.Width;
                } else {
                    var w = Page.Width;
                    var h = Page.Height;
                }

                if (h > w) {
                    Page.Rotation = Page.Rotation + 90;
                    RotatedPagesCount++;
                }
            }
        }
        if (RotatedPagesCount) {
            if (Pages.CommitChanges(pdfe.SelectedFiles(i).Filename + '(rot).pdf')) {
                pdfe.echo(pdfe.SelectedFiles(i).Filename + ' (rotated ' + RotatedPagesCount + ' pages)');
            } else {
                pdfe.echo(pdfe.SelectedFiles(i).Filename + ' (failed to commit changes)', 0xFF0000);
            }
        } else {
            pdfe.echo(pdfe.SelectedFiles(i).Filename + ' (nothing to rotate)');
        }
    } catch (e) {
        pdfe.echo(pdfe.SelectedFiles(i).Filename + ' :' + e.message, 0xFF0000);
    }
}
pdfe.echo("Done");

The new function doesn't work. it rotates all pages.

and the old script rotates pages correctly, but it doesn't truly make them landscape. if you did that function again, it would rotate the same pages again as it doesn't identify them as now true landscape pages.

RTT

  • Administrator
  • *****
  • Posts: 918
Re: UPDATE to Rotate Pages Command
« Reply #6 on: August 22, 2019, 12:39:06 AM »
The new function doesn't work. it rotates all pages.
By new function do you mean the functionality 'portrait' and 'landscape' page selector words, when used with the rotate pages tool? Please share a PDF where this occurs, so I can try it here. You can attach it to a forum reply, or send it to shelltools at rttsoftware.com.

Quote
and the old script rotates pages correctly, but it doesn't truly make them landscape. if you did that function again, it would rotate the same pages again as it doesn't identify them as now true landscape pages.
Did you removed the page rotation angle check, as explained in the commented line?
Code: [Select]
...
//Note: this rotation angle check should be removed for versions>3.1.x           
                if (Page.Rotation == 90 || Page.Rotation == 270) {
                    var w = Page.Height;
                    var h = Page.Width;
                } else {
                    var w = Page.Width;
                    var h = Page.Height;
                }
...
You need to replace the above code by just:
Code: [Select]
                    var w = Page.Width;
                    var h = Page.Height;

nightslayer23

  • Newbie
  • *
  • Posts: 98
Re: UPDATE to Rotate Pages Command
« Reply #7 on: August 22, 2019, 03:24:38 AM »
Attached file is landscape.. but if I use the "Rotate Pages" function.. type the portrait in the pages section.. it rotates them all.

RTT

  • Administrator
  • *****
  • Posts: 918
Re: UPDATE to Rotate Pages Command
« Reply #8 on: August 23, 2019, 01:32:59 AM »
Bug found and fixed. It happens whenever the rotate pages select expression doesn't triggers any page needing rotation. With your sample file all the pages have landscape orientation, so no pages to rotate if the pages expression is "portrait". Fixed code will be in the next public release.
Thanks for reporting the issue.

nightslayer23

  • Newbie
  • *
  • Posts: 98
Re: UPDATE to Rotate Pages Command
« Reply #9 on: August 23, 2019, 05:21:41 AM »
Bug found and fixed. It happens whenever the rotate pages select expression doesn't triggers any page needing rotation. With your sample file all the pages have landscape orientation, so no pages to rotate if the pages expression is "portrait". Fixed code will be in the next public release.
Thanks for reporting the issue.

no worries  ;D