PDF-ShellTools > Ideas/Suggestions

UPDATE to Rotate Pages Command

(1/2) > >>

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

nightslayer23:
awesome! thank you

nightslayer23:
question though... can we get it to save over the original file or save it to another location with the same filename?

RTT:

--- Quote from: nightslayer23 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?

--- End quote ---
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)) {

Navigation

[0] Message Index

[#] Next page

Go to full version