Write Images & Rename

Hi there,

I’m pretty new to Retrobatch. I have a bunch of PDFs and I would like to extract the first page of each file, scale the page to a specific size and save the new image as a GIF file.

Here is my workflow:

All is working fine except the file name of the generated GIF.

I want:

packaging.pdf -> packaging.gif
approvals.pdf -> approvals.gif

I have:

packaging.pdf -> packaging page 1.gif
approvals.pdf -> approvals page 1.gif

How can I get rid of the PDF page number?

TIA


Cary

This is a little tricky, but possible. First, add a JavaScript node before the write images node. Then delete all the boilerplate code and paste the following in:

function processAsset(document, jsnode, asset) {
    var s = asset.outputFileName().replace(" page 1.", ".")
    asset.setOutputFileName(s);
    
    return true;
}

That little snippet of code removes the page 1 bit, and then sets the output file name to the new string.

1 Like

Thank you very much for your help @ccgus! This is just perfect! :+1:

Would something like this allow me to rename/substitute text? For instance, instead of _orig at the end of the filename, I’d like to replace that bit of text with “_optimized”. Or is there already a rename node? Thanks!

There isn’t a rename node - but you can use the above JS node snippet to do the renaming. Change the second line to:

var s = asset.outputFileName().replace("_orig", "_optimized")

Perfect, perfect, perfect! Thanks so much @ccgus !