Skip to main content
February 29, 2016
Question

watermark opacity does not work

  • February 29, 2016
  • 2 replies
  • 629 views

Hi,

We are using the Adobe InDesign CC Server 2014, and calling its functionality via scripts. One feature, what we have to use is adding watermark to every page and generate PDFs with watermark.

Watermark must be in the middle of the every page and displaywed with 50% opcaity.

We trying to achive it with the attached code below.

Sadly opacity setting is ignored. What we are doing badly?

Positioning to the middle is not really working either.

myDocument.watermarkPreferences.watermarkHorizontalPosition = WatermarkHorizontalPositionEnum.WATERMARK_H_CENTER;

This kind of setting not seems to be working, so we used the

myDocument.watermarkPreferences.watermarkHorizontalOffset = 20;

which is working, but not really what we needed.

Regards

Balázs

createPDF:function(bmpSource, bmpDestination, postfix, profile, watermark, multipageFile) {

   var wt = 'DRAFT';
   var pfdFiles = [];
  
   // pdf export preference
   var pageCount = myDocument.pages.length;
   var pageRange = app.pdfExportPreferences.pageRange;
   var myPDFExportPreset = null;
   if( profile != null && profile.length ) {
   myPDFExportPreset = app.pdfExportPresets.item(profile);
   }
   else {
   if( app.scriptArgs.isDefined("bmpProfile") ) {
   bmp_log.debug("loading profile: " + app.scriptArgs.getValue("bmpProfile"));
   myPDFExportPreset = app.pdfExportPresets.item( app.scriptArgs.getValue("bmpProfile") );
   }
   }
   bmp_log.debug("createPDF using profile: " + myPDFExportPreset.name);
  
   if( 'true' == watermark ) {
   bmp_log.debug("initializing watermark preferences...");
  
   myDocument.watermarkPreferences.watermarkVisibility = true;
   myDocument.watermarkPreferences.watermarkDoPrint = true;
   myDocument.watermarkPreferences.watermarkDrawInBack = false;
   myDocument.watermarkPreferences.watermarkText = wt;
   myDocument.watermarkPreferences.watermarkFontFamily = "Arial";
   myDocument.watermarkPreferences.watermarkFontStyle = "Bold";
  
   hM = myDocument.viewPreferences.horizontalMeasurementUnits;
   vM = myDocument.viewPreferences.verticalMeasurementUnits;
   myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
   myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
  
   var x2 = Math.pow(parseInt(myDocument.documentPreferences.pageWidth),2);
   var y2 = Math.pow(myDocument.documentPreferences.pageHeight,2);
   var z = Math.sqrt(x2 + y2);
  
   myDocument.viewPreferences.horizontalMeasurementUnits = hM;
   myDocument.viewPreferences.verticalMeasurementUnits = vM;
  
   myDocument.watermarkPreferences.watermarkFontPointSize = Math.ceil(z/(wt.length+2));
   myDocument.watermarkPreferences.watermarkFontColor = UIColors.red;
   myDocument.watermarkPreferences.watermarkOpacity = 50;
   myDocument.watermarkPreferences.watermarkRotation = -45;
   myDocument.watermarkPreferences.watermarkHorizontalPosition = WatermarkHorizontalPositionEnum.WATERMARK_H_CENTER;
   myDocument.watermarkPreferences.watermarkHorizontalOffset = 20;
   myDocument.watermarkPreferences.watermarkVerticalPosition = WatermarkVerticalPositionEnum.WATERMARK_V_CENTER;
   myDocument.watermarkPreferences.watermarkVerticalOffset = 20;
   }

   if( 'false' == multipageFile ) {
  
   bmp_log.debug("creating pdf for each pages...");
  
   for(var i = 1; i <= pageCount; i ++) {
   app.pdfExportPreferences.pageRange = i.toString();
  
   // pdf
   var myFileName = bmpSource.substr(0, bmpSource.lastIndexOf('.')) || bmpSource;
   myFileName = myFileName.split('/').pop();
   var myPDF = new File( bmpDestination + "/" + myFileName + "_page" + i + ('true' == watermark ? '_watermark' : '') + postfix + ".pdf" );
  
   bmp_log.debug("exporting PDF...");
   if(!myPDF.parent.exists && !myPDF.parent.create()) {
   bmp_log.error("Not exported.  Unable to create the folder:  " + myPDF.parent.fullName);
   } else {
   if( bmp_util.removeFileIfExists(myPDF) ) {
   myDocument.exportFile(ExportFormat.PDF_TYPE, myPDF, myPDFExportPreset, true);
   pfdFiles.push( { name:bmp_util.toBase64StringFromUTF8Array(bmp_util.toUTF8Array(myPDF.fsName)) } );
   bmp_log.info("PDF exported to:  " + myPDF.fullName);
   }  
   }
   }
   }
   else {

   bmp_log.debug("creating only one pdf for all pages...");
  
   app.pdfExportPreferences.pageRange = "1" + (pageCount > 1 ? "-" + pageCount : "");
  
   var myFileName = bmpSource.substr(0, bmpSource.lastIndexOf('.')) || bmpSource;
   myFileName = myFileName.split('/').pop();
   var myPDF = new File( bmpDestination + "/" + myFileName + ('true' == watermark ? '_watermark' : '') + postfix + ".pdf" );

   bmp_log.debug("exporting PDF...");
   if(!myPDF.parent.exists && !myPDF.parent.create()) {
   bmp_log.error("Not exported.  Unable to create the folder:  " + myPDF.parent.fullName);
   } else {
   if( bmp_util.removeFileIfExists(myPDF) ) {
   myDocument.exportFile(ExportFormat.PDF_TYPE, myPDF, myPDFExportPreset, true);
   pfdFiles.push( { name:bmp_util.toBase64StringFromUTF8Array(bmp_util.toUTF8Array(myPDF.fsName)) } );
   bmp_log.info("PDF exported to:  " + myPDF.fullName);
   }  
   }
   }
  
   if( 'true' == watermark ) {
   myDocument.watermarkPreferences.watermarkVisibility = false;
   myDocument.watermarkPreferences.watermarkDoPrint = false;
   }
  
   app.pdfExportPreferences.pageRange = pageRange;
   return pfdFiles;

    },

This topic has been closed for replies.

2 replies

March 4, 2016

I have a bad feeling....

So when I wrote my first question I tried to make a watermark on a document with one page and opacity never worked.

Now I tested it with an another 4 pages document, and got a big supprise. On the first page, the watermark opcaity used, but on remaining pages still not.

I gave the script code in my first question. Can anybody help me to figure our what happening? What kind of settings has to be done in the script in order to display watermark with opacity in every page independently from page number, etc.

PLS HELP

PAGE 1

PAGE 2 and more

Legend
February 29, 2016

Hi,

I tested watermarkOpacity = 50 on InDesign CC Server 2014 [MacOS] and it's works fine, sorry I can not help you more ...

February 29, 2016

And did you used scripting interface for the test?

Legend
February 29, 2016

No  I run an script with a web app.