Skip to main content
Known Participant
March 18, 2022
Answered

Creating separate pages pdf using (exportAsSinglePages, singlePagesPDFSuffix).

  • March 18, 2022
  • 2 replies
  • 474 views

How to create single pages pdf for the selected range using script. Unable to find a solution through the forum except looping through pages.

 

This topic has been closed for replies.
Correct answer rob day

Hi @Singaaram , there are the exportAsSinglePages and  singlePagesPDFSuffix properties in pdfExportPreferences. This exports pages 2 and 4 to a chosen folder using the PDF/X-4 preset

 

 

var f = Folder.selectDialog("Select a folder for the PDF pages"); 
var doc = app.documents.item(0);
var n = doc.name.replace(/\.[^\.]+$/, '')
var thePath = f + "/" +  n + ".pdf";
var preset=app.pdfExportPresets.itemByName("[PDF/X-4:2008]");


//the exportAsSinglePages property set to true exports single pages. The singlePagesSuffix set to _the page number
app.pdfExportPreferences.properties = {pageRange:"2,4", exportAsSinglePages:true, singlePagesPDFSuffix:"_^P"}
doc.exportFile(ExportFormat.pdfType, File(thePath));

 

 

2 replies

rob day
rob dayCorrect answer
Braniac
March 18, 2022

Hi @Singaaram , there are the exportAsSinglePages and  singlePagesPDFSuffix properties in pdfExportPreferences. This exports pages 2 and 4 to a chosen folder using the PDF/X-4 preset

 

 

var f = Folder.selectDialog("Select a folder for the PDF pages"); 
var doc = app.documents.item(0);
var n = doc.name.replace(/\.[^\.]+$/, '')
var thePath = f + "/" +  n + ".pdf";
var preset=app.pdfExportPresets.itemByName("[PDF/X-4:2008]");


//the exportAsSinglePages property set to true exports single pages. The singlePagesSuffix set to _the page number
app.pdfExportPreferences.properties = {pageRange:"2,4", exportAsSinglePages:true, singlePagesPDFSuffix:"_^P"}
doc.exportFile(ExportFormat.pdfType, File(thePath));

 

 

SingaaramAuthor
Known Participant
March 18, 2022

Hi @rob day, Thank you so much.

That works perfectly.🤟🏼🤩 

Derek Cross
Braniac
March 18, 2022

Presumably, you are aware of the "Create Separate PDF Files" facility in the Export Adobe PDF dialogue box?

 

SingaaramAuthor
Known Participant
March 18, 2022

Hi Derek,

 

Thanks. Yes I am aware of that. But in a scripting I don't know how to integrate this in pdf creation.

I have this code only. But this did not worked for ranges. So I had to make alternate solution. 

myPages = theDoc.pages;
for (i = 0; i < myPages.length; i += 1) {
myPage = myPages[i];
myPageName = padder(i + 1, 2);
myPageRange = myPage.name;
myFilePath = myFolder + "/" + docNameNoExt + "_Big_" + myPageName + ".pdf";
myPerPageFile = new File(myFilePath);
app.pdfExportPreferences.pageRange = myPageRange;
theDoc.exportFile(ExportFormat.pdfType, myPerPageFile, false, myPDFExportPreset);
}
function padder(n, width, leadingSymbol) {
leadingSymbol = leadingSymbol || "0";
n = n + "";
return n.length >= width ? n : new Array((width - n.length) + 1).join(leadingSymbol) + n;
}