How to add page count of PDF to the file name?

I need help with an applescript that can look at a pdf, determine the page count in file and then add that value to the end of the file name in front of the .pdf
ex.
original name "map with pages4c.pdf"
renamed "map with pages4c_48.pdf"
Any help would be appreciated or suggestions on how this could be done.
Thanks,
John

Hello
That's quite simple.
Just replace this chunk of code -
tell application "Finder"
set n to f's name
set f's name to (n's text 1 thru -5) & "_" & p & ".pdf"
end tell
with -
if 10 > p then set p to "0" & p
tell application "Finder"
set n to f's name
set f's name to (n's text 1 thru -5) & "_" & p & ".pdf"
end tell
By the way, if there are 10000 files in directory tree, I'm afraid Finder is too slow to get files list. In order to avoid Apple Events timeout error, at least, replace this line -
tell o to run
with -
with timeout of 3600 seconds
tell o to run
end timeout
Or try the following script, which employs find(1) instead of Finder to get files list.
All the best,
Hiroto
--SCRIPT3
on run
--main((choose folder with multiple selections allowed) as list)
main((choose folder) as list)
end run
on open aa
main(aa)
end open
on main(aa)
(* list aa : list of folder aliases *)
script o
property ff : {}
-- confirmation for safety
set AppleScript's text item delimiters to {ASCII character 0}
set aa to (aa as Unicode text)'s text items
set AppleScript's text item delimiters to {""}
set aa to (choose from list aa default items aa ¬
with prompt ("You're renaming pdf files in following folder tree(s).") ¬
with multiple selections allowed)
if aa = false then error number -128
-- process each folder
set k to 0
repeat with a in aa
set a to a as alias
-- get pdf files' POSIX path list (= ff)
set ff to {}
set sh to "find " & quoted form of POSIX path of a & " -type f -name \"*.pdf\" -print"
try
set t to (do shell script sh)
on error
set t to ""
end try
set px to count t's paragraphs
set p0 to 1
repeat -- in order to avoid stack overflow in getting large number of paragraphs at once
set p1 to p0 + 3500
if p1 ≥ px then set p1 to -1
set ff to my ff & t's paragraphs p0 thru p1
if p1 = -1 then exit repeat
set p0 to p1 + 1
end repeat
if ff = {""} then set ff to {}
-- process each pdf file
repeat with f in my ff
set f to f as POSIX file as alias
tell application "Adobe Acrobat 7.0 Professional"
--open f
open f with invisible
tell document 1
set p to count pages
close
end tell
end tell
if 10 > p then set p to "0" & p
tell application "Finder"
set n to f's name
set f's name to (n's text 1 thru -5) & "_" & p & ".pdf"
end tell
set k to k + 1
end repeat
end repeat
-- decent notice
tell application (path to frontmost application as string)
display dialog ("Total of " & k & " pdf file(s) renamed successfully.") ¬
with icon 1 giving up after 5
end tell
end script
with timeout of 3600 seconds -- just in case
tell o to run
end timeout
end main
--END OF SCRIPT3
Message was edited by: Hiroto (fixed typos)

Similar Messages

  • How do I add pages to a PDF in the iPad version of Acrobat reader

    How do I add pages to a PDF in the iPad version of Acrobat reader

    You don't.
    Adobe Reader is a reader application. You can't use it to do editing.
    If you have Adobe Acrobat on Mac or Windows, you can add pages.

  • How to get Page Count of pdf in Document library in EventHandler

    Hi,
    How to get Page Count of pdf in Document library once uploaded has been done and i would like to update the page count value in document library column of the corresponding file.
    I should achieve it in Event handler.
    Which even should i use, either ItemAdded or "ItemUpdated "?
    Thanks & Regards
    Poomani Sankaran.

    Hello,
    If you are looking for file download or view count then event handler will not work. You need to enable the analytic report to your site. Once you enable it then you can see the report within a browser or you can also create custom webpart to show count
    of specific file.
    http://blogs.msdn.com/b/ecm/archive/2010/05/03/web-analytics-in-sharepoint-2010-insights-into-reports-and-metrics.aspx
    http://sharepoint.stackexchange.com/questions/34611/count-of-files-under-a-folder-in-a-document-library
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Windows Vista home addition want let Icloud execute. I went into the DEP program but I can not find the Apple exe file to add as ok. What is the file name?

    Windows Vista home additon want let Iclud execute. I went into the DEP program but I can not find the Apple exe file to add as ok. What is the file name?

    Hey,
    if you know the name(s) of the root folder(s) you want to access (eg. by making a note on the Windows side) then you can make them appear by just doing Shift-Command-G in Finder ("Go to Folder…"), and entering the full path to the required folders.  You can then navigate all the contents as normal.
    HTH,
    S.

  • When I save a PDF report the file name is xdo instead of "report name.pdf"

    Hi,
    I started a new project with BI Publisher integrated with OBIEE, I builded a set of reports that are working properly (these are the first reports on this OBIEE/BIP server)
    Accessing Oracle BI Cataloge I can run the reports and change the output format to pdf.
    when I press the right mouse button and select "save as" a dialog box appears.
    On the "File name" field, the default name that BIP writes is "xdo" I would like it to be the "name of the report.pdf".
    It seems that if I create a new report the file name is correct but if I change the name of the report then BIP always selects XDO as the default file name.
    Is there any place where I can configure the default name.

    Thanks for the quick reply.  I figured out how to get the desired results by using tagging.  For anyone who may reference this post in the future, I went to "Customize" in the top right corner of Adobe, then selected "Create new tool set...", looked under "accessiblity and found the "tag" option.  Hit ok, tag is added to the toolbar.  Then I highlighted the dataset in the PDF that was relevant to the output format, then clicked "tag", saved as spreadsheet.  Sorry I can't provide more details on how tagging works or if there's a more elegant solution available, but I'm sure one's out there.

  • Should the web page address be included in the file name in the meta data dialog box?

    In the page properties > meta data > below is a field with the label file name: (the the area to type in the field), after the field, it is labeled .html.
    I have 2 questions here.
    1. If I type in http//:www (my page url), do I include .html at the end? I didn't know if this is automatically added because it is off to the side of the field?
    2. If I type in the entire URL address: http//:www (etc, etc).html,    after closing the page properties dialog box, I make it a habit to double check my work. What happens is the http//:www.xxx changes to (htttpwww.xxx). It drops the //: on the URL.
    So would it be better to just type in www.xxx (without the http//:www.xxx)
    and do you type in the .html at the end?
    I am assuming this will help with SEO page ranking or at least makes it easier for the search engines to crawl your site??
    I hope this makes sense.
    Advise would be very helpful.
    Ben

    You are absolutely correct with the URL Ben. Taking your above example, you just need to type in "Services" in the file name and the webpage will be exported as services.html and the URl will be  www.xyz.com/services.html.
    All the webpages (be it parent page or child page) gets physically saved at the root directory of your website on the server (where your website resides).
    This name is just the name of the file using which it is physically stored and called from the server. It does not help search Engines to crawl deeper inside the website.
    As I explained, "name which you wants the .html file to be stored with" here means the name of the physical file which is getting saved on the server.
    Most users leave the file name same as Page name. If you have it different from page name then this will be the workflow :
    Page Name : About
    File Name : test
    domain : www.mysite.com
    Now if you are  using a Menu Widget, it will list "About" in the Menu. And when end user will click on "About" then it will call the file named "test.html" from the server location (where all the files of your website are stored).
    And it will open a page with address "www.mysite.com/test.html"
    Hope I am able to explain the concept of File Name here. Please let us know if you have further queries on this.
    Regards,
    Sachin

  • How to create Dynamic field so it appears the file name

    Hi,
    I was wondering if anyone knows how to create a dynamic text field so it automatically appears the file name created of the document.
    thanks alot !!!
    Jack
    [email protected]

    Hi, Seems we can't upload examples anymore, but here is a screen shot of what I meant.
    Hope it helps

  • How to add pages in Dreamweaver without opening new file??

    Hey there everyone
    I just wanted to know if and how i could add pages in Dreamweaver rather than having all different files.
    Thanks

    I want to have a main page which is used for every page but only slights differences are made i.e. there will b a box in the middle which will change as pages change. and thats all, i don't want anything else 2 change.

  • How can I save the web page by using the Page Title as the file name ?

    When i use Internet Explorer ,I can save the web page by using Page Title as the file name(as default no need to adjust anything). But when i use Firefox ,It can not use the Page Title to save as the file name. How can I do that like in Internet Explorer?

    See:
    *File Title: https://addons.mozilla.org/firefox/addon/834
    *Title Save: https://addons.mozilla.org/firefox/addon/712

  • How can I insert the file name automatically on all pages?

    I would like that on all pages of my keynote presentations the file name is inserted automatically in a footer as eg in EXCEL and Word.

    Oh yeah! Very similar to that one is Print Window. I use it all the time.
    http://www.printwindowapp.com
    It costs $20 if you want all the extra features the free version doesn't have. But I've always used the free version. Nothing in the paid version I need.

  • How to add page event on the every pdf  footer

    How to add page event on the every pdf footer

    there is an option available in third party tool which you are using for create PDF using java. so read API documentation. if you can also extend/customize any feature using java

  • ? how to add page numbers in pages 5.2, starting with 2.  Pages '09 had an option to not show folio on page one.  Also any how to do left and right folios for a Tabloid?  Many trhanks

    ? how to add page numbers in pages 5.2, starting with page 2.  Pages '09 had an option to not show folio on page one.  Also any idea how to do left and right folios for a Tabloid?  Many thanks  . . .

    Hello jacquemac,
    Your first question:
    There might be a better way of achieving what you wish to do, but following these steps could help you out.
    You might want to blend in Thumbnails and Invisibles either with (cmd+shift+i and cmd+alt+p) or over the View section in the Menubar.
    1. go for Documents (right end of the Toolbar) -> Section
    2. place your cursor at the very top of your second page and click "Create new Section->Starting with this page" in the side bar on your right.
    (what you are actually doing next is setting the pagenumbers for each section you created. You can see your sections in the Thumbnail view.)
    3. click on your first page (the first and only page of your first section) and mark the checkbox "Hide on first page of section"
    4. click on your second page (the first page of your second section) and  "Insert page number" -> start at 1
    Your second question:
    Im not quite sure i understand what exactly you want to do here. One page, two columns, each column with another page number? As far as i know this is not possible.
    greetings jl

  • How to add page numbers in Numbers?

    How to add page numbers in Numbers?
    Is there a simple way like in Excel? Thanks.

    In Numbers '09, use Insert > Page Number
    Place the page number in a page header, and it will appear on each age when in Print View and when the file is prnted.
    May have changed in Numbers 3 (current version).
    Regards,
    Barry

  • How to change the file name of pdf file in html page?

    Hi,
    Actually my requirement is to upload 50 PDF files containing javascript in each file into flex page with the help of one html page.
    i did the the javascript part by using batch processing.
    now i want to call those pdf files one after another without changing the file name in html page
    the code written in html page is
    <html>
        <body>
            <object id="PDFObj"
                    data="http:\\localhost\pdf\20090807 - Batch 630.pdf"
                    type="application/pdf"
                    width="100%"
                    height="100%">
            </object>
            </body>
    </html>
    So every time i have to change that file name to acess another file.
    Is there is any other way to sort this problem????
    Plz anyone help me to sort out this problem with some code or some example.

    I once had a similar task for creating a webpage that I only use on my computer--a webpage that accesses PDF's and SWF's font previews from a list of fonts as "a href's".  What you must do is utilize the power of the command line, whether on a Mac on a PC or on Linux, Linux being the most powerful (although Mac IS Unix).  You must utilize variables, variable replacement, and then a command to print out the results of a "for" or "while" loop to a text file which will be your HTML file with each individual link automatically built into the HTML code.  You will have a list of 50 links.  If you are simply looking for a GOOGLE type functionality where you click on "Next" and "Previous" you will have to dig deeper into variable replacement--this I don't know how to do yet but there are books for command-line shell interpreters.  One shell interpreter is called "bash" (born-again shell) and there is a book on the market which gives a detailed example of how to replace variables in a shell script.  Again, I don't know how it works.  I will try to learn this at a later time when I am more seasoned with the basics of shell scripting.

  • How to delete pages in a pdf file with mac OSX Mavericks?

    Indeed i don't have Pages options in my tools window... Is that normal for the mac version? Please it's urgent...

    Sorry, it was my fault. When I searched on the Internet, I was reading the Acrobat help pages, without knowing it, because in my research I wrote "how to delete pages in a pdf file with Adobe reader", i was just automatically redirected toward Acrobat help but i didn't notice.
    So no incorrect information exist in the Reader Help pages.

Maybe you are looking for