Copy link to clipboard
Copied
Hi Team,
I have 700+ pages in PDF, I want to replace multiple page numbers via script.
Random pages need to replace.
For example, old pdf page numbers 54, 109, 154, and 209 replace with the same page numbers with new pdf.
In the manual process, I click on replace pages and do the process.
Can we do this in the script in Acrobat DC?
I found one script but that script is not working
var doc = app.openDoc({
cPath: "/C/Users/username/directory/oldpdf.pdf"
});
doc.replacePages({
nPage: 2,
cPath: "/C/Users/username/directory/newpdf.pdf",
nStart: 0,
nEnd: -1
});
Thanks in Advanced.
Copy link to clipboard
Copied
Try the following code:
var pagesToReplace = [54, 109, 154, 209];
var newFilePath = "/C/Users/username/directory/newpdf.pdf"; // change to actual file path, keeping the same syntax!
for (var i=0; i<pagesToReplace.length; i++) {
this.replacePages({nPage: pagesToReplace[i]-1, cPath: newFilePath, nStart: pagesToReplace[i]-1})
}
You can run it from the JS Console or even from a Custom Command. If it doesn't work specify exactly what happened, including the full text of any error message you got. Just saying "it doesn't work" is not very helpful to us.
Copy link to clipboard
Copied
Try the following code:
var pagesToReplace = [54, 109, 154, 209];
var newFilePath = "/C/Users/username/directory/newpdf.pdf"; // change to actual file path, keeping the same syntax!
for (var i=0; i<pagesToReplace.length; i++) {
this.replacePages({nPage: pagesToReplace[i]-1, cPath: newFilePath, nStart: pagesToReplace[i]-1})
}
You can run it from the JS Console or even from a Custom Command. If it doesn't work specify exactly what happened, including the full text of any error message you got. Just saying "it doesn't work" is not very helpful to us.
Copy link to clipboard
Copied
Thanks, @try67 code is perfect I just need to do some changes in my process.
Actually, it is giving an Access Denied error but after modifying the pdf it is working perfectly fine.
Copy link to clipboard
Copied
Hi @try67,
var pagesToReplace = [54, 109, 154, 209];
Can we add the above page numbers directly from excel or a text file?
When we have 300+ pages that need to do in color that time we need to type all page numbers manually.
That will be time-consuming and also might be a typo mistake.
It will be great if we get the page number directly from excel or a text file
Copy link to clipboard
Copied
Yes, it's possible, but converting the list from Excel to a string is not too difficult. You just need a capable plain text editor (I recommend Notepad++), and then you could copy the column from Excel in to it and do a simple RegExp search & replace command to replace the line-breaks ("\r\n") with commas.
Copy link to clipboard
Copied
@try67, thanks for the quick reply and advice!!
Yes, I 100% agree with you better if we convert excel data into strings by Notepad++ or excel formula.
In fact, I'm planning to use CONCATENATE excel formula because I always get data in excel sheets.
So in the same sheet, we can convert multiple-row data into a single cell and copy and paste it into our code.
Copy link to clipboard
Copied
this i great