Copy link to clipboard
Copied
Hi All
I’m trying to find out how to export two PDF's at once from Indesign CC. I'm aiming to get 1 PDFx-1a PDF (High res with crop and bleed) and 1 smallest File Size (Cropped, no marks)? Could you point me in the right direction or if anyone has a working script I could use that would be amazing. My brain is going to fall out my ears.
Many thanks
Rahul
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you however I've tried this but the coding is incorrect. Could you resupply it on here? I keep getting an error with it.
Want to test this today 20th April if possible. Many thanks.
Copy link to clipboard
Copied
Why not share the error? It may help us help you.
Copy link to clipboard
Copied
Got an error with it - I don't know anything about scripts, so any help or reconfiguration would be amazing!
// BS"D
// All rights reserved (c) 2015 by Id-Extras.com
// Free to use and modify but do not delete this copyright attribution.
// This script will export 2 pdfs of the current document
// Choose the PDF presets by altering their names below
// The second PDF gets a suffix added to its name.
// Modify the line below beginning name2 = to change the suffix.
// For more InDesign scripts: www.Id-Extras.com
d = app.activeDocument;
// Here you can choose the PDF preset
preset1 = app.pdfExportPresets.itemByName("200dpi");
preset2 = app.pdfExportPresets.itemByName("300dpi");
if (!(preset1.isValid && preset2.isValid)){
alert("One of the presets does not exist. Please check spelling carefully.");
exit();
}
if (d.saved){
thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";
thePath = String(new File(thePath).saveDlg());
}
else{
thePath = String((new File).saveDlg());
}
thePath = thePath.replace(/\.pdf$/, "");
name1 = thePath.replace(/AW$/, "LR")+".pdf";
name2 = thePath.replace(/AW$/, "HR") +".pdf";
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
Copy link to clipboard
Copied
Looks as if you're treating this as an AppleScript. But it's JavaScript.
Copy link to clipboard
Copied
Hi Peter thanks for this. If it does work - I know its a silly question but how do I make this work with indesign? I know nothing about scripts - apple or java. Does this script work?
Copy link to clipboard
Copied
Copy the script to InDesign's script folder, then run it from InDesign's Scripts panel. See here for details:
https://indesignsecrets.com/how-to-install-scripts-in-indesign.php
P.
Copy link to clipboard
Copied
Peter - great work - however can you tell me what im doing wrong. I'm almost there but not sure about the characters for the indesign pdf presets.
d = app.activeDocument;
// Here you can choose the PDF preset
preset1 = app.pdfExportPresets.[HighQualityPrint]("300dpi");
preset2 = app.pdfExportPresets.[Smallest File Size]("100dpi");
if (!(preset1.isValid && preset2.isValid)){
alert("One of the presets does not exist. Please check spelling carefully.");
exit();
}
if (d.saved){
thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";
thePath = String(new File(thePath).saveDlg());
}
else{
thePath = String((new File).saveDlg());
}
thePath = thePath.replace(/\.pdf$/, "");
name1 = thePath.replace(/AW$/, "LR")+".pdf";
name2 = thePath.replace(/AW$/, "HR") +".pdf";
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
Cheers for your help so far, greatly appreciated.
Copy link to clipboard
Copied
You'll have to specify PDF presets that exist on your disk. This one:
preset1 = app.pdfExportPresets.[HighQualityPrint]("300dpi");
should be this:
preset1 = app.pdfExportPresets.item ('[High Quality Print]');
and for preset2 you should use a similar format.
(mind the spaces). The ones in Ariel's script are specific for his system (sorry, Ariel, I seem to have hijacked this thread. . .)
P.
Copy link to clipboard
Copied
Okay - so the script worked! Yay! however its only creating one pdf - not two and its not renaming _LR _HR. I dont have a clue why it's working completley. Ive created two presets myself Print 1 and Lowres as test presets. Only one is working. See Code. I'm happy to wait on this, but just really need it by the end of next week. So close I can feel it!
d = app.activeDocument;
// Here you can choose the PDF preset
preset1 = app.pdfExportPresets.item ('Print1');
preset2 = app.pdfExportPresets.item ('Lowres');
if (!(preset1.isValid && preset2.isValid)){
alert("One of the presets does not exist. Please check spelling carefully.");
exit();
}
if (d.saved){
thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";
thePath = String(new File(thePath).saveDlg());
}
else{
thePath = String((new File).saveDlg());
}
thePath = thePath.replace(/\.pdf$/, "");
name1 = thePath.replace(/AW$/, "LR")+".pdf";
name2 = thePath.replace(/AW$/, "HR") +".pdf";
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
Copy link to clipboard
Copied
Okay - so the script worked! Yay! however its only creating one pdf - not two and its not renaming _LR _HR. I dont have a clue why it's working completly. Ive created two presets myself Print 1 and Lowres as test presets. Only one is working. See Code. I'm happy to wait on this, but just really need it by the end of this week. So close I can feel it!
d = app.activeDocument;
// Here you can choose the PDF preset
preset1 = app.pdfExportPresets.item ('Print1');
preset2 = app.pdfExportPresets.item ('Lowres');
if (!(preset1.isValid && preset2.isValid)){
alert("One of the presets does not exist. Please check spelling carefully.");
exit();
}
if (d.saved){
thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";
thePath = String(new File(thePath).saveDlg());
}
else{
thePath = String((new File).saveDlg());
}
thePath = thePath.replace(/\.pdf$/, "");
name1 = thePath.replace(/AW$/, "LR")+".pdf";
name2 = thePath.replace(/AW$/, "HR") +".pdf";
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
Copy link to clipboard
Copied
Looks as if the script expects the names of the InDesign files to end in AW. Try this:
name1 = thePath + "LR.pdf";
name2 = thePath + "HR.pdf";
Copy link to clipboard
Copied
Fantastic - Thanks very much for your help! Greatly appreciated!
Rahul
Copy link to clipboard
Copied
Thanks for the help, Peter!
The script that rahul1976 is posting here has been modified (possibly by me for someone else). The original version on the website that I linked to initially should work fine as is (see my initial post above).
Ariel
Copy link to clipboard
Copied
Hello
Im looking for a way to iprove this script a little - that it will
- save pdfs in current indd document location
- add active layer name to output name - filename_layername_LR
anyone could help me with it ?
Copy link to clipboard
Copied
Hello
Im looking for a way to iprove this script a little - that it will
- save pdfs in current indd document location
- add active layer name to output name - filename_layername_LR
anyone could help me with it ?
d = app.activeDocument;
preset1 = app.pdfExportPresets.itemByName("[PDF/X-1a:2001]");
preset2 = app.pdfExportPresets.itemByName("[Smallest File Size]");
if (!(preset1.isValid && preset2.isValid))
{
alert("One of the presets does not exist. Please check spelling carefully.");
exit();
}
thePath = d.filePath + "/" + d.name.replace(".indd", "") + "_" + d.activeLayer.name;
name1 = thePath + "_HR.pdf";
name2 = thePath + "_LR.pdf";
//export PDFs as Background Tasks
d.asynchronousExportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1); //Hi-Res PDF
d.asynchronousExportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2); //Lo-Res PDF
Copy link to clipboard
Copied
Thank you very much. it is working, you've made my day
Copy link to clipboard
Copied
Thank you so much, this is a lifesaver for me. Is there a way to save the files into separate folders on your HD?
Copy link to clipboard
Copied
This is freaking fantastic!! I adjusted the code (below) to save out 3 PDFs at once and it works. YAY! What a time saver.
// BS"D
// All rights reserved (c) 2015 by Id-Extras.com
// Free to use and modify but do not delete this copyright attribution.
// This script will export 3 pdfs of the current document
// Choose the PDF presets by altering their names below
// The second PDF gets a suffix added to its name.
// Modify the line below beginning name2 = to change the suffix.
// For more InDesign scripts: www.Id-Extras.com
d = app.activeDocument;
// Here you can choose the PDF preset
preset1 = app.pdfExportPresets.itemByName("PRINT");
preset2 = app.pdfExportPresets.itemByName("PRESS");
preset3 = app.pdfExportPresets.itemByName("[Smallest File Size]");
if (!(preset1.isValid && preset2.isValid)){
alert("One of the presets does not exist. Please check spelling carefully.");
exit();
}
if (d.saved){
thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";
thePath = String(new File(thePath).saveDlg());
}
else{
thePath = String((new File).saveDlg());
}
thePath = thePath.replace(/\.pdf$/, "");
name1 = thePath+"_PRINT.pdf";
// Here you can set the suffix at the end of the name
name2 = thePath+"_PRESS.pdf";
name3 = thePath+"_DIGITAL.pdf";
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
d.exportFile(ExportFormat.PDF_TYPE, new File(name3), false, preset3);
Copy link to clipboard
Copied
hi,
Can the output pdf not override another pdf with the same name?
I have two files, when the name is stripped with regex, ends up with the same file name. When I export the pdfs:
with...
doc.asynchronousExportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
i get: Cannot save to the file because it is in use by one of more background tasks/
---because the first pdf is being generated by indesign.---
if i do,
doc.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
It just overwrites the first file with the second file.
Can it check for the existence of a file name and append a number? instead of replacing the first pdf.
i think a file name check has to be created at the name2
name2 = thePath+ ".pdf";
or is there an easier way? instead of new File(name2)...
any pointer would be appreciated.
Copy link to clipboard
Copied
Here is an example that will export the current document as Test.pdf on the desktop. If the file(s) already exists it will add an counter: Test_1.pdf, Test_2.pdf, ...
var myPDFpreset = app.pdfExportPresets[0];
var doc = app.activeDocument;
var saveFolder = "~/desktop/";
var name = "Test";
var versionCounter = 1;
var pdf_fullname = new File (saveFolder + name + ".pdf");
while (pdf_fullname.exists)
{
pdf_fullname = File (saveFolder + name + "_" + versionCounter + ".pdf");
versionCounter++;
}
doc.asynchronousExportFile(ExportFormat.PDF_TYPE, pdf_fullname, false, myPDFpreset);
Copy link to clipboard
Copied
thank you!
i can adapt this to my needs.
Copy link to clipboard
Copied
fyi:
when I omit the while part in my sample script it will overwrite the existing file without any problems when using the asynchronousExportFile function. I don't know why it doesn't work in your own script.
Copy link to clipboard
Copied
My same-named pdfs are created almost simultaneously, almost within the same second—as they are batched.
it works now with the ExportFile, the only downside is that it locks up InDesign. Which I can live with.
If i can insert a pause or a event listener, then maybe I can use asynchronousExportFile.
I might also be able to use asynchronousExportFile if the same named pdfs are not in the queue in a sequential order Like when these same named pdfs are part of a larger group, I think indesign prints them randomly.
Or print one set first, then the other set.
An even listener might be the more elegant approach, i need to look into it.