I have a document called 'mydocument'
I have a multiple pages in the document.
Each page has one "title" styled with a pargraph style sheet called title.
I need to export each page as individual .jpg with a custom file name
mydocument-01-title.jpg
with the 01 being the page number
Seemed like a simple request... but turns out it is a bit of a challenge.
This scipt below I found on another thread is kinda working
it gives me a
title1.jpg
But I can't figure out how to....
1. add "mydocument" name
2. have a leading 0 on 1 digit numbers
Can someone please guide me, I would be for ever grateful.
if (app.documents.length != 0) { var myDoc = app.activeDocument; MakeJPEGfile();}else{ alert("Please open a document and try again."); }
function MakeJPEGfile() { for(var myCounter = 0; myCounter < myDoc.pages.length; myCounter++) { if (myDoc.pages.item(myCounter).appliedSection.name != "") { myDoc.pages.item(myCounter).appliedSection.name = ""; } var myPageName = myDoc.pages.item(myCounter).name; var myJpegPrefix = ""; var isStyleExist = true; //Checking the existing of the paragraph style (filename) try{ myDoc.paragraphStyles.item("title"); } catch (myError) { isStyleExist = false; } if (isStyleExist) myJpegPrefix = getParagraphContent(myDoc.paragraphStyles.item("title"), myDoc.pages.item(myCounter)) + myPageName; app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high; // low medium high maximum app.jpegExportPreferences.exportResolution = 72; app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange; app.jpegExportPreferences.pageString = myPageName; var myFilePath = "~/-client/JOYS - Just Organize Your Stuff/-Art/-art-book-kindle/" + myJpegPrefix + ".jpg"; var myFile = new File(myFilePath); myDoc.exportFile(ExportFormat.jpg, myFile, false); }} // The new function, but needs to add checking the file name rules.
function getParagraphContent (paragraphStyle, currentPage){ var paragraphContent = null; for (var c = 0; c < currentPage.textFrames.length; c++) { for (var i = 0; i < currentPage.textFrames.item(c).paragraphs.length; i++) { if (currentPage.textFrames.item(c).paragraphs.item(i).appliedParagraphStyle == paragraphStyle) { paragraphContent = currentPage.textFrames.item(c).paragraphs.item(i).contents; // Remove spaces and returns at the end: paragraphContent = paragraphContent.replace(/\s+$/, ''); // Replace remaining spaces with hyphen: paragraphContent = paragraphContent.replace(/\s+/g, '-'); // Make lowercase: paragraphContent = paragraphContent.toLowerCase(); return paragraphContent; } } } return paragraphContent;}