Advertisement
Piuuf

Untitled

May 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. #target illustrator
  2.  
  3.  
  4. try {
  5.  
  6. if (app.documents.length > 0 ) {
  7.  
  8.  
  9. var destFolder = null;
  10. destFolder = Folder.selectDialog( 'Sélectionner le dossier d\'export pour la preview.', '~' );
  11.  
  12. if (destFolder != null) {
  13. var options, i, sourceDoc, targetFile;
  14.  
  15.  
  16. options = this.getOptions();
  17.  
  18.  
  19. for ( i = 0; i < app.documents.length; i++ ) {
  20. sourceDoc = app.documents[i];
  21.  
  22.  
  23. targetFile = this.getTargetFile(' [preview]' + sourceDoc.name,'.pdf', destFolder);
  24.  
  25.  
  26. sourceDoc.saveAs( targetFile, options );
  27. }
  28. alert( 'Previews enregistrés au format PDF' );
  29. }
  30. }
  31. else{
  32. throw new Error('Aucun document ouvert.');
  33. }
  34. }
  35. catch(e) {
  36. alert( e.message, "Alerte de script", true);
  37. }
  38.  
  39.  
  40. function getOptions()
  41. {
  42.  
  43. var options = new PDFSaveOptions();
  44.  
  45. options.acrobatLayers = true;
  46. options.colorBars = true;
  47. options.colorCompression = CompressionQuality.JPEGLOW;
  48. options.compressArt = true;
  49. options.embedICCProfile = true;
  50. options.enablePlainText = true;
  51. options.generateThumbnails = false;
  52. options.optimization = true;
  53. options.pageInformation = false;
  54. options.compatibility = PDFCompatibility.ACROBAT7;
  55.  
  56. return options;
  57. }
  58.  
  59.  
  60. function getTargetFile(docName, ext, destFolder) {
  61. var newName = "";
  62.  
  63.  
  64. if (docName.indexOf('.') < 0) {
  65. newName = docName + ext;
  66. } else {
  67. var dot = docName.lastIndexOf('.');
  68. newName += docName.substring(0, dot);
  69. newName += ext;
  70. }
  71.  
  72.  
  73. var myFile = new File( destFolder + '/' + newName );
  74.  
  75.  
  76. if (myFile.open("w")) {
  77. myFile.close();
  78. }
  79. else {
  80. throw new Error('Accès refusé');
  81. }
  82. return myFile;
  83. }
  84.  
  85. printPostScript();
  86.  
  87. function printPostScript() {
  88.  
  89. app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;
  90.  
  91. var docPath, docs, inFolder, opts, psPath;
  92.  
  93. jobOpts = new PrintJobOptions();
  94.  
  95. opts = new PrintOptions();
  96.  
  97. opts.printPreset = 'PostScript';
  98.  
  99. opts.jobOptions = jobOpts;
  100. var sepOpts = new PrintColorSeparationOptions();
  101. opts.colorSeparationOptions = sepOpts;
  102. var fontOpts = new PrintFontOptions();
  103. opts.fontOptions = fontOpts;
  104. fontOpts.downloadFonts = PrintFontDownloadMode.DOWNLOADNONE;
  105. fontOpts.fontSubstitution = FontSubstitutionPolicy.SUBSTITUTEDEVICE;
  106. opts.customPaperSupport = true;
  107. sepOpts.convertSpotColors = true;
  108. sepOpts.overPrintBlack = true;
  109. sepOpts.colorSeparationMode = PrintColorSeparationMode.HOSTBASEDSEPARATION;
  110. var psOpts = new PrintPostScriptOptions();
  111. opts.postScriptOptions = psOpts;
  112. psOpts.postScriptLevel = PrinterPostScriptLevelEnum.PSLEVEL3;
  113. if ( app.documents.length > 0 ) {
  114.  
  115. docs = app.documents;
  116.  
  117. } else {
  118.  
  119. inFolder = Folder.selectDialog( 'Select Source Folder...' );
  120.  
  121. if ( inFolder != null ) {
  122.  
  123. docs = inFolder.getFiles( '*.ai' );
  124.  
  125. };
  126.  
  127. };
  128.  
  129.  
  130. for ( i = docs.length-1; i >= 0; i-- ) {
  131.  
  132. if ( docs[i] instanceof File ) {
  133.  
  134. app.open( docs[i] );
  135.  
  136. } else {
  137.  
  138. app.activeDocument = docs[i];
  139.  
  140. };
  141.  
  142. docPath = decodeURI( app.activeDocument.fullName );
  143.  
  144. psPath = docPath.replace( /.ai$/, '.ps' );
  145.  
  146. jobOpts.file = File( psPath );
  147.  
  148. app.activeDocument.print( opts);
  149.  
  150. app.activeDocument.close( SaveOptions.DONOTSAVECHANGES );
  151.  
  152. };
  153.  
  154. app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;
  155.  
  156. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement