PDF-ShellTools > Ideas/Suggestions

Comments Flattener

(1/3) > >>

nightslayer23:
Could you translate a custom script for flattening all annotations, highlights and comments?

We've found these often drop off at the print level.

We have a current java script that does it perfect, but you have to do it file - by - file.

Be great if there was a way to do this as a batch.

the program that the script belongs in is: https://www.uvsar.com/projects/acrobat/flattener/

RTT:
No internal code to do this, but here is a script to automate Acrobat Professional to do it.

--- Code: ---var objShell = new ActiveXObject("shell.application");
var objFolder;
objFolder = objShell.BrowseForFolder(0, "Select the destination folder", 0x10, 0x11);

if (objFolder != null) {
    var DestFolder = objFolder.self.path;
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var app = pdfe.CreateObject("AcroExch.App");
    var baseDoc = pdfe.CreateObject("AcroExch.PDDoc");
    var ProgressBar = pdfe.ProgressBar;
    ProgressBar.max = pdfe.SelectedFiles.Count;

    for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
        try {
            FullPathFilename = pdfe.SelectedFiles(i).Filename;
            var Filename = FullPathFilename.substr(FullPathFilename.lastIndexOf('\\') + 1);
            var DestFullPathFilename = fso.BuildPath(DestFolder, Filename);

            if (FullPathFilename == DestFullPathFilename) {
                DestFullPathFilename = FullPathFilename.substr(0, FullPathFilename.lastIndexOf('.') - 1) + '_flattened.pdf';
            }

            pdfe.echo('Flattening: ' + FullPathFilename);
            ProgressBar.position = i + 1;

            baseDoc.Open(FullPathFilename);

            try {
                var JSObject = baseDoc.getJSObject();
                JSObject.addScript("flatten", "function flatten(){this.flattenPages();}flatten();");
                JSObject.removeScript("flatten");
                baseDoc.Save(1, DestFullPathFilename);
                pdfe.echo(" [OK]", 0, 1);
            } catch (err) {
                pdfe.echo(err, 0xFF0000);
                pdfe.echo("");
            }
            baseDoc.close();
        } catch (err) {
            pdfe.echo(err, 0xFF0000);
            pdfe.echo("");
        }
    }
    app.Exit();
    pdfe.echo('\nDone');
}

--- End code ---

nightslayer23:
so this script is to be installed into acrobat correct?

this isn't a script we could add to the PDF Shell Tools context menu?

never-mind! I see it works from the context menu! fantastic..

what do I need to take out of this script so it is a save over original file ? I'd like to add the script to a super script that I have that checks size & orientation but flattens comments at the same time (which I've already put together). same with a version that checks size, orientation & coverage, would need it to flatten prior to checking for coverage.

RTT:

--- Quote from: nightslayer23 on September 16, 2019, 12:06:11 AM ---so this script is to be installed into acrobat correct?

--- End quote ---
No. This is a PDF-ShellTools script, to run from the PDF-ShellTools scripts interface, so could be added to the PDF-ShellTools context menu. It just needs Acrobat Professional to be installed, as it uses it to do the work.

nightslayer23:
yes I worked out how to use it just after I posted.

please see my last post for other enquiry

Navigation

[0] Message Index

[#] Next page

Go to full version