Copier le lien dans le Presse-papiers
Copié
I have Adobe Acrobat Pro Adobe Continuous Release version 2023.006.20360 and Adobe Creative Cloud. I'm trying in either platform to create an Action Wizard that will take a PDF and edit the bookmarks to promote them all to Primary in order to split the PDF into multiple PDFs. The PDF itself is about 160+ pages and has 60+ bookmarks but the bookmarks are grouped into a hierarchy so I have to get the bookmarks updated to primary in order to split.
I have 2 issues here, I can't seem to find in my version a way to add an update bookmarks into the wizard, nor do I see a way to add split PDFs. I did find Split PDF as a custom tool but I don't see a way to add the custom tool into the action wizard.
I also tried using a javascript to update the bookmarks, but even though it says it runs successfully it doesn't change anything in the document.
Please help
Copier le lien dans le Presse-papiers
Copié
You can use a script to move the bookmarks around, but not to split the file according to them (at least not in an Action). What code did you use, and what was the result of running it from the Console on a single file?
Copier le lien dans le Presse-papiers
Copié
For just the Bookmarks I selected New Action Wizard, on right changed the default to add folder instead of file, then on left in Choose tools to add: I selected More Tools added Execute JavaScript, unchecked prompt user, then added the code:
var doc = this;
for (var i = 0; i < doc.numBookmarks; i++) {
var bookmark = doc.bookmarkRoot.children[i];
bookmark.primary = true;
}
When I run this I see it pull up each file as it finds them in the folder but none of them have the bookmarks updated when it says complete.
Copier le lien dans le Presse-papiers
Copié
Where did you get this code from?
Copier le lien dans le Presse-papiers
Copié
You need to run this code from the console, first. You will see it reports errors in it.
For starters, there's no such thing as a numBookmarks or a primary property.
Copier le lien dans le Presse-papiers
Copié
ChatGPT
Copier le lien dans le Presse-papiers
Copié
I also tried the below from Bard
var doc = app.activeDoc; var bookmarks = doc.bookmarks; for (var i = 0; i < bookmarks.length; i++) { bookmarks[i].primary = true; }
Copier le lien dans le Presse-papiers
Copié
Going off the primary doesn't exist, I tried this
var doc = app.activeDoc; var bookmarks = doc.bookmarks; for (var i = 0; i < bookmarks.length; i++) { if (bookmarks[i].parent) { bookmarks[i].parent.remove(bookmarks[i]); doc.rootBookmarks.add(bookmarks[i]); } }
Didn't work either.
Copier le lien dans le Presse-papiers
Copié
No, it wouldn't... Both codes are incorrect.
First of all, does your bookmarks tree contain multiple levels? If so, it would require using a recursive function, not a simple for-loop.
I've actually developed a (paid-for) that will allow you to do it, if you're interested. You can find it here:
https://try67.blogspot.com/2008/11/acrobat-flatten-bookmarks.html
Copier le lien dans le Presse-papiers
Copié
Yes it contains multiple levels but I only want the bottom level. It's too many bookmarks to have to manually move them every time.
Copier le lien dans le Presse-papiers
Copié
So you want to move the lowest-level bookmarks to the top, and remove all the rest?
Copier le lien dans le Presse-papiers
Copié
That is correct. Then split by bookmarks since I can't split by lower level.
Copier le lien dans le Presse-papiers
Copié
You can, actually. Another (paid-for) tool by me:
https://www.try67.com/tool/acrobat-extract-lowest-level-bookmarks
Copier le lien dans le Presse-papiers
Copié
Actually I may be going about this the wrong way. What I have is a PDF with a summary page list of invoices and then 60+ invoices with varying page counts. I'm thinking I want to split by text, using javascripts from a few other posts. But what does that do with the summary page?
Copier le lien dans le Presse-papiers
Copié
If there's a reliable way to identify where each invoice begins (or ends) based on the text, then yes, there's no need to do it via the bookmarks at all. It can be done directly.
Copier le lien dans le Presse-papiers
Copié
Hi,
Here is a script which will generate all lowest bookmarks at the first root level:
lowestLevelBookmarks=[];
function lowestLevelBookmarksAtTheRootLevel(bkm,nLevel) {
if (bkm.name!="Root" && bkm.children==null) {
bkm.execute();
lowestLevelBookmarks.push([bkm.name,this.pageNum]);
}
if (bkm.children!=null) for (var i=0; i<bkm.children.length; i++) lowestLevelBookmarksAtTheRootLevel(bkm.children[i],nLevel+1);
}
lowestLevelBookmarksAtTheRootLevel(this.bookmarkRoot,0);
bookmarkRoot.remove();
for (var i=lowestLevelBookmarks.length-1; i>=0; i--) this.bookmarkRoot.createChild(lowestLevelBookmarks[i][0],"this.pageNum="+lowestLevelBookmarks[i][1]);
About spliting the file according to bookmarks, I assume the first page is where the bookmark refers. But the last page can be either the page where the next bookmark refers or the previous one... Let me know.
@+
Copier le lien dans le Presse-papiers
Copié
Okay that seems to work within the Action Wizard. I created an action called Promote Bookmarks. Now any suggestions on splitting by bookmark within the same Wizard or will I always have to go through a separate step to choose split and choose split by bookmarks?
Copier le lien dans le Presse-papiers
Copié
Also I'm trying to save the file immediately after updating the bookmarks with a new name in a separate directory. I see where I can append to the file name, but am I missing something in the configuration window of the Action Wizard to tell it store in a different folder? Or is that another tool entirely?
Copier le lien dans le Presse-papiers
Copié
If you know the new path there is no problem to save the file with new bookmarks in an other folder.
For splitting the file I still don't know the ranges of page you want as asked previously.
@+
Copier le lien dans le Presse-papiers
Copié
No answer!!!
Well, let's imagine that we created a "New Documents" directory in the same folder as the main file for saving all new documents.
The pages extracted will be from the page number relative to the bookmark to the previous page number relative to the next bookmark.
The script is as follows:
// Only Lowest-Level Bookmarks At The Root Level
lowestLevelBookmarks=[];
function lowestLevelBookmarksAtTheRootLevel(bkm,nLevel) {
if (bkm.name!="Root" && bkm.children==null) {
bkm.execute();
lowestLevelBookmarks.push([bkm.name,this.pageNum]);
}
if (bkm.children!=null) for (var i=0; i<bkm.children.length; i++) lowestLevelBookmarksAtTheRootLevel(bkm.children[i],nLevel+1);
}
lowestLevelBookmarksAtTheRootLevel(this.bookmarkRoot,0);
bookmarkRoot.remove();
for (var i=lowestLevelBookmarks.length-1; i>=0; i--) this.bookmarkRoot.createChild(lowestLevelBookmarks[i][0],"this.pageNum="+lowestLevelBookmarks[i][1]);
// Main File Saving
var newPath=this.path.replace(this.documentFileName,"New Documents/");
this.saveAs(newPath+this.documentFileName.replace(/.pdf$/i," \(Only Lowest Bookmarks\).pdf"));
// Files Extracting
for (var i=0; i<lowestLevelBookmarks.length; i++) {
var statingPage=lowestLevelBookmarks[i][1];
if (i<lowestLevelBookmarks.length-1) var endingPage=lowestLevelBookmarks[i+1][1];
else var endingPage=this.numPages-1;
if (endingPage>statingPage && endingPage!=this.numPages-1) endingPage--;
this.extractPages({
nStart: statingPage,
nEnd: endingPage,
cPath: newPath+lowestLevelBookmarks[i][0].replace(/\s+/g," ").replace(/\s+$/,"")+".pdf"
})
}
@+
Copier le lien dans le Presse-papiers
Copié
The page ranges will vary, which is why I was trying to split by bookmarks. There is a case of potentially splitting by invoice text "No. :" as that text appears on the first page of every invoice in the PDF followed by the actual invoice number (generally 6 digits), but it doesn't appear at all on page 1 which is the summary of invoices. Ideally I'd like to split page 1 into a file appended with "Summary" and the rest of the splits by invoice with the file name appended with the invoice number (the six digits after "No. : " . I've attempted this through multiple AI's but the javascript never runs so was going back to the Split PDF tool by bookmark.
Copier le lien dans le Presse-papiers
Copié
If the invoice number is always located at the same place or always after the "No." text, we can use an other script.
Is it the case?
@+
Copier le lien dans le Presse-papiers
Copié
Yes the invoice number always looks like the attached and always on "Pg 1/X" but that isn't page 1 of the PDF until after the split.
Copier le lien dans le Presse-papiers
Copié
...and this number is indicated on each page of the same invoice? ...or only on the first page?
Is it always a 6-digit number, or it can be from 4 to 8-digit (for example)?
@+
Copier le lien dans le Presse-papiers
Copié
Yes and no, the invoice number does appear on each page, but not in that specific format "No. : 123456" . That format is only on first page. And thus far I've only seen 6 digit invoice numbers so I'd go with that.
Trouvez plus d’idées, d’événements et de ressources dans la nouvelle communauté Adobe
Explorer maintenant