Recent Posts

Pages: 1 2 3 [4] 5 6 ... 10
31
Ideas/Suggestions / Re: Rasterizing PDFs?
« Last post by RTT on October 21, 2017, 07:18:21 PM »
The next script rasterizes all the document pages into image files, using the extract images tool command line interface, and then convert all these image files to a PDF with the same name as the original and a "_rasterized.pdf" suffix.

Code: [Select]
var RenderDPIs = 120;

//RunAsync = true: Rendered pages image files are converted to PDF as created.
//RunAsync = false: Wait until all the PDF pages have being rendered, before converting all back to PDF
var RunAsync = true;

//================================================================================
var fso = new ActiveXObject("Scripting.FileSystemObject");
var objShell = new ActiveXObject("Wscript.Shell");

var st_exe = fso.GetParentFolderName(pdfe.FullName) + '\\pdfshelltools.exe';
var cmd = '"' + st_exe + '" ExtractImages -s "OutputPath=' + fso.GetSpecialFolder(2 /*TemporaryFolder*/ ) + '\\\\" ExtractType=0 ImageType=3 RenderDPIs=' + RenderDPIs + ' NamePrefix=';

function ExtractImages_GetImageFilePrefix(filename, WaitOnReturn) {
    var NamePrefix = fso.GetTempName();
    objShell.Run(cmd + NamePrefix + ' "' + filename + '"', 0, WaitOnReturn);
    return fso.GetSpecialFolder(2 /*TemporaryFolder*/ ) + '\\' + NamePrefix;
}

var Merger = pdfe.CreateDocumentMerger();
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    try {
        var File = pdfe.SelectedFiles(i),
            Filename = File.Filename,
            Pages = File.Pages;
        var Path = Filename.substr(0, Filename.lastIndexOf('\\') + 1),
            Name = Filename.substring(Path.length, Filename.lastIndexOf('.'));

        pdfe.echo(' > rasterizing ' + Filename);
        pdfe.echo(' ');
        var ImageFilesPrefix = ExtractImages_GetImageFilePrefix(Filename, !RunAsync);

        for (var PageIndex = 0; PageIndex < Pages.Count; PageIndex++) {
            var imgfilename = ImageFilesPrefix + pad(PageIndex, 4) + '.png';
            var OKtoMerge = false;
            if (RunAsync) {
                pdfe.echo(' Page ' + (PageIndex + 1) + '/' + Pages.Count, 0, 2);

                //wait until page rendered image file has been created
                while (!fso.FileExists(imgfilename)) {
                    pdfe.sleep(1000);
                }
                //wait until image file not in use.
                while (true) {
                    try {
                        var ots = fso.opentextfile(imgfilename, 8, false);
                        ots.close();
                        break;
                    } catch (e) {
                        pdfe.sleep(1000);
                    }
                }

                OKtoMerge = true;
            } else {
                OKtoMerge = fso.FileExists(imgfilename);
            }

            if (OKtoMerge) {
                Merger.MergeDocument(imgfilename);
                fso.DeleteFile(imgfilename);
            } else {
                pdfe.echo('     Page ' + (PageIndex + 1) + ' failed to render', 0xFF0000, 2);
                pdfe.echo(' ');
            }
        }

        var NewFilename = Path + Name + '_rasterized.pdf';
        if (Merger.EndAndSaveTo(NewFilename)) {
            pdfe.echo('     Saved to: ' + NewFilename + ' [OK]', 0, 2)
        } else {
            pdfe.echo('     Saving to: ' + NewFilename + ' [Failed]', 0xFF0000, 2);
        }
    } catch (e) {
        pdfe.echo(e.message, 0xFF0000);
    }
}
pdfe.echo('Done');

function pad(num, size) {
    var s = "000000000" + num;
    return s.substr(s.length - size);
}

Not entirely sure if this is what you are asking for. Let me know if not.
In the first line of the script you may change the RenderDPIs variable, if you need higher resolution.
32
Ideas/Suggestions / Rasterizing PDFs?
« Last post by nightslayer23 on October 20, 2017, 06:38:48 AM »
Got any thoughts on a way to rasterize PDF documents?
Would look to highlight a group of files and right click, select rasterize.
Would be for very heavily layered files that take too long to load / print.
33
Ideas/Suggestions / Re: Split multi-page & multi-page.size PDF into respective sizes
« Last post by Braud on October 13, 2017, 02:59:22 PM »
This works like a charm. Thank you RTT!
34
Bug reports / Re: Report paper sizes in use : NOT WORKING
« Last post by RTT on October 04, 2017, 11:53:03 PM »
There is indeed a nasty bug in the code! The attached script should have it fixed. I've included code to check the total number of pages reported with the total number of pages processed, that outputs an error messages if a discrepancy exist (to alert for any other flaw the algorithm may have). Try it against a big number of PDFs, and let me know if any error message shows up.
35
Bug reports / Report paper sizes in use : NOT WORKING
« Last post by nightslayer23 on October 04, 2017, 04:15:05 AM »
Usually I trust this tool to a T but now it seems I maybe can't...

I tried a bunch of 41 pdfs and got a dramatically under par assessment of how many pages there is.

I have attached the example as both "split by pdf sizes" and the combined file. Same results!

link to files: (SIC)
36
Bug reports / Re: Scripts manager crashes with stack overflow when new/edit selected
« Last post by RTT on October 04, 2017, 02:10:30 AM »
Re-arranged the position of the screens (from side to side to top/bottom).  Hit "apply". 

Bingo!  There's the editor.  On the second screen.
Great!
Don't the Windows key+arrow_left/arrow_right work to move windows across screens oriented top/bottom? Never tested.
Quote
At the moment I'm blaming my display driver. later this week (or early next) I'll see if I can reproduce the problem.
Let me know if I need to fix something.
Quote
Observation: if I fire up the editor from the manager, I have only one RTT app on the task bar.  If I do it via CTRL-click, then I end up with two instances.
Two buttons in the taskbar, but only one scripts editor window, or two windows also?
37
I'm leaning towards your suggestion that the display is popping up somewhere off screen.
Bingo!

Rebooted. No joy.
Borrowed a screen from my client, fired up in "duplicate mode".  No Joy.
Changed to Extended Desktop.  No Joy.
Re-arranged the position of the screens (from side to side to top/bottom).  Hit "apply". 

Bingo!  There's the editor.  On the second screen.
 :o
At the moment I'm blaming my display driver. later this week (or early next) I'll see if I can reproduce the problem.

Observation: if I fire up the editor from the manager, I have only one RTT app on the task bar.  If I do it via CTRL-click, then I end up with two instances.

(As you suspect, I'm not allowed to play with HKEYs.)
38
Bug reports / Re: Scripts manager crashes with stack overflow when new/edit selected
« Last post by RTT on October 03, 2017, 01:47:53 AM »
You can reset/set the position by deleting/editing the values under the HKEY_CURRENT_USER\Software\PDFShellTools\MyScripts registry key, but you probably don't have permission to run the regedit tool on your system? But you can use the linked above WinSpy++ tool to manually set the window position.

But if indeed the problem is the window being off-screen, it's strange the Windows Key+arrow-up, arrow-left or arrow-right shortcuts are not working!
39
Instead of opening the scripts editor from the manager, try ...
Interesting - I get a RTT icon on the taskbar and task manager shows a task (as does ALT-TAB ) called PDF-ShellTools- My Scripts but I can't switch to it.

I can close it from the task bar, in which case I get a "save changes?" message if I've ALT-TAB'd to the not-there window.

I'm leaning towards your suggestion that the display is popping up somewhere off screen. 
40
Bug reports / Re: Scripts manager crashes with stack overflow when new/edit selected
« Last post by RTT on October 03, 2017, 01:12:59 AM »
Instead of opening the scripts editor from the manager, try open it directly to see if anything changes. To do this, hold down the CTRL key, while clicking a script menu item from the shell context PDF-ShellTools>My Scripts sub menu. This will open the clicked script directly in the editor, from where you can edit, run or create new ones (if the editor indeed shows up this way).
Pages: 1 2 3 [4] 5 6 ... 10