PDF-ShellTools > Ideas/Suggestions

UPDATE to Rotate Pages Command

<< < (2/2)

nightslayer23:

--- Quote from: RTT 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: ---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");

--- End code ---

--- End quote ---

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:

--- Quote from: nightslayer23 on August 21, 2019, 02:48:21 AM ---The new function doesn't work. it rotates all pages.

--- End quote ---
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.

--- End quote ---
Did you removed the page rotation angle check, as explained in the commented line?

--- Code: ---...
//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;
                }
...

--- End code ---
You need to replace the above code by just:

--- Code: ---                    var w = Page.Width;
                    var h = Page.Height;

--- End code ---

nightslayer23:
Attached file is landscape.. but if I use the "Rotate Pages" function.. type the portrait in the pages section.. it rotates them all.

RTT:
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:

--- Quote from: RTT 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.

--- End quote ---

no worries  ;D

Navigation

[0] Message Index

[*] Previous page

Go to full version