[JS][CS4]PDF Export With RegExp Doesn't Include First Zero-Please Help

This is a script we put together with the help of Jongware, Shonkyin and Kaysan a while back...
Here's the link to the original thread:
http://forums.adobe.com/thread/481958?tstart=0
( function() {
if(app.documents.length != 0){
var myFolder = app.activeDocument.filePath;
if(myFolder != null){
var myPageName, myFilePath, myFile;
var myDocument = app.activeDocument;
     //var myBaseName = myDocumentName + "_" ;
          //1.  Update modified links, find and alert operator of missing links.
          var linksLog = updateLinks(myDocument, "");
     if (linksLog != "") {
          alert("Missing Links\n" + linksLog + "\nPlease resolve and try again.");
          return;
     function updateLinks(doc, log) {
          var myLinks = doc.links;
          for (var j = myLinks.length - 1; j >= 0; j--) {
               switch (myLinks[j].status) {
                    case LinkStatus.normal :; case LinkStatus.linkEmbedded : break; // nothing to do
                    case LinkStatus.linkOutOfDate : myLinks[j].update(); break; // update
                    case LinkStatus.linkMissing :
                         log = log + "Link '" + myLinks[j].name + "' is missing\n";
                    break
               } // end switch
          } // end for
          return log
     } // end updateLinks
var my_suffix = decodeURI(app.activeDocument.name).replace(/^(\d+).*/, '$1');
//my_suffix = Number(my_suffix);
if (typeof (my_suffix) != 'number')
my_suffix = Number(my_suffix);
for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){
    if (myDocument.pages.item(myCounter).appliedSection.name != ""){
        myDocument.pages.item(myCounter).appliedSection.name = "";
myPageName = myDocument.pages.item(myCounter).name;
app.pdfExportPreferences.pageRange = myPageName;
myFilePath = myFolder + "/" + "MyTest_" + (my_suffix + myCounter) + ".pdf";
myFile = new File(myFilePath);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
myDocument.exportFile(ExportFormat.pdfType, myFile, false, "[Press Quality]");
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
    else{
        alert("No documents are open. Please open a document and try again.");
        exit();
alert("Finished exporting");
The problem is, I never considered pages 0 through 99. The script works perfect for 138-140 TEST 10_WORKER.indd. It creates PDFs named:
MyTest_138.pdf
MyTest_139.pd
MyTest_140.pdf
If the document name is 098-100 TEST 10_WORKER.indd, It creates PDFs named:
MyTest_98.pdf -  should be MyTest_098.pdf 
MyTest_99.pdf -  should be MyTest_099.pdf 
MyTest_100.pdf - This is perferct
And of course, the double 0s, 008-010 TEST 10_WORKER.indd
MyTest_8.pdf -  should be MyTest_008.pdf 
MyTest_9.pdf -  should be MyTest_009.pdf 
MyTest_10.pdf -  should be MyTest_010.pdf 
Why doesn't it use the first 0(s) in the name? 0 is a digit and every RegEx tester I've checked it with includes the zero.
Any assistance with getting this script to use the leading zero if there is one would be greatly appreciated.
Also, if there is a way to export each PDF from a multipage document which doesn't start with a number, it would be extremely helpful.
Thanks in advance
Danny

The zeros aren't there because they never were there. Your loop starts at 0 and that could be a page number. To pad your page numbers to three-digit numbers, replace this line:
myFilePath = myFolder + "/" + "MyTest_" + (my_suffix + myCounter) + ".pdf";
with this one:
myFilePath = myFolder + "/" + "MyTest_" + (my_suffix + pad(myCounter)) + ".pdf";
and add the following function somewhere at the end of your script:
function pad (n) {
    return ("00000"+n).slice(-3);
Peter

Similar Messages

  • I cannot export to pdf from Indesign... I export and then nothing happens. Can someone please help?

    Indesign worked well for a long time.  Then recently, after I and to reset my computer to an earlier time, Indesign stopped letting me export to PDF. I get no error message.  It is just that nothing happens after I export it.  I have some major deadlines for printin and am desperate for help.  I emailed the Indesign file to someone else and they were able to export it and create a PDF. 
    I look forward to any suggestions. I would gladly pay someone if they can get it to work again.

    @ (peterfrommaine)-peter – since you use InDesign CS5.5, be aware that there is a bug (at least up to version 7.5.2) with PDF export with books that could mess up your page numbers. You are not affected, because you printed to PDF (that is the "print-PostScript-distill-to-PDF" way).
    But if you want to export to PDF, read this thread:
    http://forums.adobe.com/message/3750835#3750835
    So then I would go a different route. Use a script that exports in foreground (there are several around; if you read the thread mentioned by the other Peter, you already found that link: ExportPDF_in_Foreground_CS5.jsx) or use the more radical method Matthew Lawn suggested to prevent all background exporting (not only PDF export):
    http://forums.adobe.com/message/3689090#3689090
    And see the following implementation (very cool) by Marijan Tomba "controlBackgroundExport.jsx":
    http://forums.adobe.com/message/3690507#3690507
    Uwe

  • Hi, I am wondering why my iphone won't send pictures through messages, I have MMS on and I have tried sending it with 3G on aswell and still doesn't work. Someone please help me :)

    Hi, I am wondering why my iphone won't send pictures through messages, I have MMS on and I have tried sending it with 3G on aswell and still doesn't work. Someone please help me :)

    Hey lozza567,
    Thanks for the question. I understand that you are experiencing issues sending MMS messages. The following resource may provide a solution:
    iOS: Troubleshooting Messages
    http://support.apple.com/kb/ts2755
    Issues with sending and receiving MMS
    You will need these to send and receive MMS:
    - An iPhone 3G or later.
    - iOS 3.1 or later.
    - A cellular data connection. MMS isn't available if you are using only Wi-Fi.
    - A domestic MMS plan from your cellular provider. You may need an international messaging plan to send MMS to an international contact. Contact your carrier for more information.
    - A roaming MMS when using a cellular provider's network different from your billing cellular provider's network. Learn more about roaming and contact your carrier for more information.
    To resolve issues with sending and receiving MMS, follow these steps first
    1. Go to Settings and turn airplane mode off.
    2. Go to Settings > Messages and turn MMS Messaging on.
    3. Go to Settings > Cellular and turn Cellular Data on.
    4. Go to Settings > Cellular and turn Data Roaming on if you are roaming on a cellular provider network different from your billing provider's network.
    5. Verify that you have a cellular data connection in the status bar at the top left of your iPhone.
    6. Go to Settings and turn Wi-Fi off. Open Safari and navigate to www.apple.com to verify that you have a data connection. Turn Wi-Fi back on to continue using Wi-Fi for other features. If your cellular data connection isn't available, follow these steps.
    7. Verify that you can send and receive SMS. If you are unable to send and receive SMS, see the "Issues with sending and receiving SMS" section, above.
    8. MMS may not be available while on a call. Only 3G and faster GSM networks support simultaneous data and voice calls. Learn more about which network your phone supports.
    9. Restart your iPhone.
    10. Tap Settings > General > Reset > Reset Network Settings on your iPhone.
    11. Reseat your SIM card.
    If you are still unable to send or receive MMS, follow these steps
    1. Make sure that the contact trying to message you isn't blocked in Settings > Messages > Blocked.
    2. Go to Settings > Messages and turn on group messaging if you are sending a group message.
    3. Make sure that you are using the area code with the contact's phone number. When sending messages internationally, you also need the contact's international code.
    4. Verify a "Pay as you go" MMS plan has enough available balance. Contact your carrier if unsure of your MMS plan or available balance.
    5. If the issue occurs with a specific contact or contacts, back up or forward important messages and delete your current messaging threads with the contact. Create a new message to the contact and try again.
    6. If the issue occurs with a specific contact or contacts, delete and re-create the contact from the Contacts application. Create a new message to the newly created contact and try again.
    7. Back up and restore your iPhone as new.
    8. If your carrier has recently ported your phone number, the porting process may not be complete. Contact your carrier to confirm that the porting process is complete.
    9. Contact your carrier to verify that you are provisioned to send SMS and are in an area with cellular coverage.
    10. Contact your carrier to verify that there are no blocks or filters placed on your wireless account preventing you from sending SMS.
    11. Your carrier may require APN settings to be modified to use MMS. Learn more about when you should adjust APN settings.
    Thanks,
    Matt M.

  • I cant use the highlight, underline, or strikethrough function in a specific pdf file. The file isnt locked. I used to highlight texts from that file before the latest update. The problem occurs only with that file. Urgent need. Please help. Thanks!

    i cant use the highlight, underline, or strikethrough function in a specific pdf file. The file isnt locked. I used to highlight texts from that file before the latest update. The problem occurs only with that file. Urgent need. Please help. Thanks!

    Chester31,
    Thank you very much for sharing your file with us!  Now that we are able to reproduce the problem at our end, you may stop sharing the file on Acrobat.com.
    Do you know when this problem (for not being able to add new highlight/strikeout/underline) has started?  Did you update your iOS from 7.x to 8.0 recently?
    We will continue investigating the problem and let you know what we find.
    Thank you again for your help.

  • PHP 5 with Leopard doesn't include the GD library?

    Anyone out there have this problem; PHP with Leopard doesn't include the GD library?

    The GD library is a feature that is included with PHP that allows on-the-fly image manipulation with PHP scripts.
    It's a programming thing really; doesn't have much to do with an actual library.

  • How do I transfer my checked songs from one computer to another - tried exporting library playlist etc but no luck! Please help! I have 26,000 songs - 17,000 are selected and I can't run down the list on my new computer and re-check 17,000 songs! Thanks!

    How do I transfer my checked songs from one computer to another - tried exporting library playlist etc but no luck! Please help! I have 26,000 songs - 17,000 are selected and I can't run down the list on my new computer and re-check 17,000 songs! Thanks!

    Make a smart playlist of your whole library but only checked songs - #4 on  http://support.apple.com/kb/ht1801
    Highlight all files in that playlist, then drag to the other drive.  This isn't preserving any playlists or whatever, just copying files from one drive to another.
    You might want to delete the smart playlist this once you are done because it will probably gobble up resources with that many files.

  • After i update the 10.10.2 OS X Yosemite my iPhoto stops working. In the warning that appears when I try to open the app says that happened a mistake because of this update. I reinstalled the app but doesn't work anyway. Please, HELP!

    after i update the 10.10.2 OS X Yosemite my iPhoto stops working. In the warning that appears when I try to open the app says that happened a mistake because of this update. I reinstalled the app but doesn't work anyway. Please, HELP!

    I already tried that but it doesn't work. Appears a warning saying: "See the developer to make sure that iPhoto works with this version of OS X. You may need to reinstall the application. Be sure to install all available updates in the application and OS X."

  • Please help, i movie is not exporting or sharing movies, it will closed unexpectedly please help?

    Please help, i movie is not exporting or sharing movies, it will closed unexpectedly please help?

    Hi Videoframe
    This was emailed to Apple Support on 23 DEc 2012 at 09:50 Eastern Australia time.
    "I continued to talk to other Apple Mac users on iMovie….Interesting to have found out that their movies were made using iDVD without any known issues as yet…Looking at the results from Apple Support Forum and Youtube, problems appears to be when NOT using iDVD. I and many others can't understand how these many technical problems were overlooked by the programmers of iMovie. One would have thought iMovie problems have been iron out prior to getting rid of iDVD. By the way when I first contacted Apple Support back on 16th Nov, I was told I need to RE-INSTALL my computer…..that I did and in the process my iDVD was removed and never was re-installed.
    May I suggest you delegate a junior person or someone string together a project consisting over near 1700 images, approx. 25mins of video footage, titles and including with and without transitions then export the project.
    I am still in the dark as to what is being done about this extended non result. I am not sure if is known by the people who is in charge of this iMovie programme. it would be nice to get some sort of feedback. Not sure if I should refer this to a third party to do the testing?? I am sure Apple's competitors would love to make a mockery of this.
    There has to be a time frame for this to end, as I and many others can't simply sit here in the dark and wait for someone to come back for a solution, this could be months or years who knows.  As you can appreciate I am not the only user anxiously waiting for a solution.
    I guess I am in a way representing other worldwide users in pursuing a solution on this matter ASAP. I therefore ask you to please make this a priority if this is at all possible.
    Many thanks."
    I've been corresponding to them since Fri 16th Nov on and off without a solution.

  • HT5312 The option to reset security information tab isn't showing up for me, is there I way that I can make it show up. I have a rescue email address and it still doesn't show up. Please help!

    The option to reset my security information tab is not available for me, I have a rescue email address in place and it still doesn't show up. Please help!

    You need to ask Apple to reset your security questions; ways of doing so include clicking here and picking a method for your country, and filling out and submitting this form.
    (96335)

  • Please help block my ipod touch second generation and forget the code, try putting the code so many times that now says connect to itunes, I connect but will not let me do anything that tells me this should unlock with key and I should do for Please help!

    please helpme i block my ipod touch second generation and forget the code, try putting the code so many times that now says connect to itunes, I connect but will not let me do anything that tells me this  should unlock with key and I should do for Please help!. thanks

    Place the iPOd in recovery mode and then restore. For recovery mode:
    iPhone and iPod touch: Unable to update or restore

  • Hi, when ever I'm using 3G, on my Iphone4 sim stops working and Network is lost, this started after I updated my phone with  6.0.1(10A523)version. Please help how to solve this problem.

    Hi, when ever I'm using 3G, on my Iphone4 sim stops working and network is lost, this started after I updated my phone with  6.0.1(10A523)version. Please help how to solve this problem. Thanks.

    Photos/videos in the Camera Roll are not synced. Photos/videos in the Camera Roll are not touched with the iTunes sync process. Photos/videos in the Camera Roll can be imported by your computer which is not handled by iTunes. Most importing software includes an option to delete the photos/videos from the Camera Roll after the import process is complete. If is my understanding that some Windows import software supports importing photos from the Camera Roll, but not videos. Regardless, the import software should not delete the photos/videos from the Camera Roll unless you set the app to do so.
    Photos/videos in the Camera Roll are included with your iPhone's backup. If you synced your iPhone with iTunes before the videos on the Camera Roll went missing and you haven't synced your iPhone with iTunes since they went missing, you can try restoring the iPhone with iTunes from the iPhone's backup. Don't sync the iPhone with iTunes again and decline the prompt to update the iPhone's backup after selecting Restore.

  • Hello, I have an iPad Mini WiFi Cellular white 16Gb and I puted my sim inside it but, I cant read the text message that I recieve in the Sim. What can i do? And I can't put the sim in a cellphone coz it doesn't recognize it. Please help me! Thank you.

    Hello, I have an iPad Mini WiFi Cellular white 16Gb and I puted my sim inside it but, I cant read the text message that I recieve in the Sim. What can i do? And I can't put the sim in a cellphone coz it doesn't recognize it. Please help me! Thank you.

    iPads do not do SMS.

  • HT1212 my ipad is disabled permantly and i dont want to loose my pictures i keep going through the 5 steps and each time it says "itunes cannot connect to ipad because it is locked with a passcode" WHAT DO I DO PLEASE HELP ME. thank you. sorry about spell

    my ipad is disabled permantly and i dont want to loose my pictures i keep going through the 5 steps and each time it says "itunes cannot connect to ipad because it is locked with a passcode" WHAT DO I DO PLEASE HELP ME. thank you. sorry about spelling.

    FORCE IPAD INTO RECOVERY MODE
    1. Turn off iPad
    2. Turn on computer and launch iTunes (make sure you have the latest version of iTune)
    3. Plug USB cable into computer's USB port
    4. Hold Home button down and plug the other end of cable into docking port.
    DO NOT RELEASE BUTTON until you see picture of iTunes and plug
    5. Release Home button.
    ON COMPUTER
    6. iTunes has detected iPad in recovery mode. You must restore this iPad before it can be used with iTunes.
    7. Select "Restore iPad"...
    Note:
    1. Data will be lost if you do not have backup
    2. If you did not do step 4 properly, start all over again.

  • HT2736 I was sent an app as gift but i dont get the email with the message to redeem it. Please help. Thank you.

    I was sent an app as gift but i dont get the email with the message to redeem it. Please help. Thank you.

    Have you checked your spam folder as well as your Inbox ? If it's not in there either then you could ask the sender to try re-sending it (and to double-check the address) : http://support.apple.com/kb/HT1541

  • TS1463 What is the easiest way to restore my ipod back to factory specs. It has a red circle with a red x in the middle,please help me to fix my ipod, until now i can't use my ipod..i tried all the procedures in Restore ipod from disk mode but still not w

    What is the easiest way to restore my ipod back to factory specs. It has a red circle with a red x in the middle,please help me to fix my ipod, until now i can't use my ipod..i tried all the procedures in Restore ipod from disk mode but still not working, please help me...

    If you are unable to get the iPod into Disk Mode to try and restore it, it's a very good indication, as mentioned in the article, that the iPod's hard drive is damaged and in need of replacement either by Apple or a third party repair company.
    B-rock

Maybe you are looking for