17 Replies Latest reply on Aug 17, 2017 7:13 AM by Sebastian Soyke

    PDF Watermark based on state (Add-in)

    Sebastian Soyke

      Hi All,

       

      I was wondering if anyone did manage to create a macro, EPDM Add-in, or java script for a PDF file, which would create dynamic watermark based on a file state or maybe a Variable value?

      To be clear, I am nor looking for solutions for SolidWorks documents but PDFs.

       

      For example, I do have a massive amount of documents which have to be approved externally, and they are all PDFs. Each of the documents has multiple level approval. For documents which are not in the approved state, I would like to display a WATERMARK, i.e. "Submitted to the customer for approval."

      Hiding on approved documents is not an option, as the input in them is from all departments and draft copies are preview in a shopfloor. I just want to eliminate the possibility of using a wrong document on the shop floor.

       

      Please let me know if there is any solution to my problem,

        • Re: PDF Watermark based on state (Add-in)
          Craig Schultz

          I set up a variable that gets changed or disappears depending on which state the model is in.  Then in the drawing I have a text block associated with the variable.  I think there's a way to put it on the watermark layer so it's transparent or behind the model.  (Don't quote me on that though...)

           

          Capture.PNG

          cap2.PNG

          • Re: PDF Watermark based on state (Add-in)
            Craig Schultz

            If you're converting office docs to PDFs you should be able map a variable to do the same thing.  Actual PDFs, I don't think so.

            • Re: PDF Watermark based on state (Add-in)
              Christian Chu

              Sebastian,

              Please see the below image - does the water mark looks ok to you

              if so, you don't need a macro/addin or anything - just create a CusProp and link the text in the SW dwg

              Then when you saveAs PDF, it's shown

              You can go back the SW dwg and adjust the text so it can look good on the PDF too

               

               

               

               

                • Re: PDF Watermark based on state (Add-in)
                  Jeff Hamilton

                  What you have described to create a watermark based upon a custom property driven by a workflow state does work, because I have done it. However it is shown on the Solidworks drawing itself and then transferred to pdf when the pdf is printed, either automatically or manually. I'm not sure why (or if) you would want it shown on the pdf only and not the drawing, because then it would not be a true representation of the drawing: thus, a snapshot in time.

                  You can also specify the watermark to generate something other than the exact text of the workflow state, such as "preliminary"  on all states up to the point of release.

                  It's a very simple way to do it without writing code and will also show up on the preview in PDM.

                • Re: PDF Watermark based on state (Add-in)
                  Amos Avery

                  Hi Sebastian,

                  The PDF format is a locked-down file that's intended to be a snap-shot in time of a document created by some other tool (Word, SolidWorks, etc.).  For this reason, it does not support Custom Properties.  We have researched this very question in detail and have found that there is no way to automate such a feature with PDM.  The only way I know to change what you see on a PDF file is to use Acrobat Professional to add the watermark (edit text, add text or add comment).  You might be able to use Acrobat Professional to make a Form from your PDF with a Watermark Field that will save with it.  However, the form field isn't updated automatically with PDM and it isn't read only so others could change it.

                   

                  We use Workflow States to limit access to specific people before the document is approved.  We teach Users to pay attention to States.  For the shop floor, we use a temporary XML file with the same name that they can see (while hiding access to the actual file) and we automate its creation.  This works to let them know the file does exist but the real version is not available (our ECN process relies on this).

                   

                  Unfortunately there is no easy way to let everyone access a file and not let everyone do whatever they want with it (only common sense and training can help). -Amos

                    • Re: PDF Watermark based on state (Add-in)
                      Sebastian Soyke

                      Hi Amos Avery .

                      All points taken, however people tend to do work in their way, and I try to eliminate the human error to a minimum.

                       

                      I did do some research in the JS API reference file and did found a necessary code for adding watermark from a text. Small modification and I now reference the custom property in the PDF. I concluded that the custom property updates accordingly based on the change in the EPDM variable, therefore, is dynamic and not static as I thought initially. Please see the code. This watermark will not be visible in the document but only when printing, to see in a document "bOnScreen: true,".

                      For the watermark, I used an EPDM Variable called "Watermark", but any can be used for reference. All available are listed in the additional metadata / Advanced / pdfx

                       

                       

                      var docwtrmrk = this.info.Watermark; // this.info.<Any EPDM Variable can be used as ref.>

                      var cMyText = docwtrmrk +  " Printed on: " + util.printd("dd.mm.yyyy @ HH:MM", new Date);

                       

                       

                      this.addWatermarkFromText({

                      cText: cMyText,

                      nTextAlign:app.constants.align.center,

                      cFont: "Helvetica-Bold",

                      nScale: 1,

                      aColor: color.red,

                      nRotation: 45,

                      nOpacity: 0.5,

                      bOnScreen: false,

                      });

                       

                       

                      The problem is that there is no way to remove the watermark, and I did look everywhere for a solution. Whenever the document is running the script (on print in my occasion), it adds an additional layer of the watermark, therefore there are multiple instances. My question is if anyone knows how to deal with this problem.

                      For example, when the document is going to be approved it will still show the watermark "not approved", hence this script does not help and could cause a lot of issues.

                       

                      I attached a copy of PDF which has the script. The watermark is printed but not visible in the page.

                    • Re: PDF Watermark based on state (Add-in)
                      Lee CS Young

                      My Office to PDF add-in has the ability to add a watermark (image, text, variable value) to a PDF.

                        • Re: PDF Watermark based on state (Add-in)
                          Sebastian Soyke

                          Dear Lee CS Young and Tim Webb

                           

                          I managed to create a script which adds the Watermark to the PDF document based on the value of the EPDM Variable.

                          The PDF I am working on is constantly changing. In this occasion, I am not working on native files but PDFs only. the PDFs are being edited and state of documents is changed in the PDFs. I will not be able to use your add-in at all.

                            • Re: PDF Watermark based on state (Add-in)
                              Tim Webb

                              Hi Sebastian,

                               

                              Does anybody, besides you, know you are developing this? I would recommend revealing the programming you've done to your IT department and asking them for their input.

                               

                              I have been following this thread and I do see what you are doing and have understood what you are doing since the first day I read your post, however I would not recommend your approach due to the elevated risk in two key areas:

                              1. Using the embedded JS API makes it "possible" but is this feasible? This is a significant security risk from IT's perspective.
                              2. Who will support the custom scripting if you leave the company? Is this a sustainable approach for your company?

                               

                              My two cents,

                              Tim CEPA

                              Believe in The Q!

                                • Re: PDF Watermark based on state (Add-in)
                                  Sebastian Soyke

                                  Hi Tim,

                                   

                                  Unfortunately, I won't get any support from our IT. And adding the script is the only thing I can think about, besides from removing permission to see unapproved documents, which is not possible, this is a nature of our work. The most obvious thing is to have regular training and explain to people how to use EPDM. However, this does not work at the moment, and I am forced to look for other options.

                                   

                                  At this moment the whole idea is not going to work in the way I wanted. There is no option to remove a watermark from the PDF. I did manage to Add Watermark and made the additional script to prompt the user to remove it afterwards. The water mark will not be added unless you press to print the document and the state is "not approved". I also changed the settings in EPDM so non approved documents can't be checked out by shop floor, hence, wrongly saved with the watermark.

                                   

                                  All of this steps are done to ensure that there is no wrong paperwork in the shop floor. I know it looks like too much, but when mistakes cost thousands of pounds, then, the extra action is required.

                                    • Re: PDF Watermark based on state (Add-in)
                                      Tim Webb

                                      Hi Sebastian, I get it.

                                      I just wanted to offer some insight as a PDM consultant who has encountered this scenario before.

                                       

                                      I know you've considered this but I wonder if you could simply change the value of the PDF custom property to an empty string to "remove" the watermark?

                                        • Re: PDF Watermark based on state (Add-in)
                                          Sebastian Soyke

                                          Hi, Tim.

                                          Unfortunately changing the custom property to an empty string will not remove the Watermark in the PDF if it was created. I checked the JS_API_References and OCG object, can't be deleted by a script. They did not think about it for some reason. One would think if something can be added it should have an option to be removed.

                                          My Approach is as follow:

                                          1)I hanged workflow to set Watermark variable to "No" for Approved, and "Yes" for not approved docs.

                                          2) The project documents (PDFs), which are required to be submitted to the customer have the unique workflow, and if not approved, only groups engineering and document control can check them out.

                                          3) The Template which we use for documents submittals, now have the following script:

                                           

                                          // Add Watermark ON PRINT Var. Watermark "YES"
                                          var docwtrmrk = this.info.Watermark; // get Watermark variable value 
                                          var docRev = this.info.Revision; // Get Revision variable Value 
                                          var cMyText = "NOT APPROVED!!! FOR REFERENCE ONLY" + "\n Printed on: " +  util.printd("dd.mm.yyyy @ HH:MM", new Date) + "\n REVISION NO.: " + docRev;
                                          
                                          
                                          if (docwtrmrk == "Yes") {
                                          // Yes, adds watermark
                                          this.addWatermarkFromText({
                                          cText: cMyText,
                                          nTextAlign:app.constants.align.center,
                                          cFont: "Helvetica-Bold",
                                          nScale: 1,
                                          aColor: color.red,
                                          nRotation: 45,
                                          nOpacity: 0.5,
                                          bOnScreen: true,
                                          });
                                          app.alert("You are about to print NOT APPROVED Docuement \n Double check with engineering and Document controler  \n USE FOR REF. ONLY", 1);
                                          }
                                          else {} // Dont add watermark
                                          

                                           

                                          Whenever someone would like to print it out, and the watermark variable is set to "yes" then the script will add watermark. If a variable is "no" then, nothing happens.

                                          Software does not remove the watermark, but as I changed the settings and shop floor is not able to edit the document, no harm is done.

                                            • Re: PDF Watermark based on state (Add-in)
                                              Tim Webb

                                              Sebastian, I like it but would recommend changing the text to give it some teeth!

                                               

                                              I recommend my clients use a little more powerful language on the face of their prints that puts the ownership ultimately back onto the shoulders of the one who views, uses, or otherwise employs the print in manufacturing, ordering, or otherwise using it once it has been printed.

                                               

                                              "IT SHALL BE THE RESPONSIBILITY OF THE END USER OF THIS HARDCOPY TO VERIFY THIS PRINT MATCHES THE LATEST REVISION IN DOCUMENT CONTROL AND DESTROY THIS PRINT IF THEY DO NOT MATCH."

                                               

                                              If a print gets to the floor in ANY way shape or form, this takes the ownership off your shoulders and turns the spotlight right onto them where it belongs. Many of my ISO clients use this strategy and train their shop floor that it IS their responsibility to trust but verify.

                                               

                                              It's similar to building office keys that say "DO NOT DUPLICATE" - If any key maker copies that key, they are ultimately the one responsible for that key.

                                              key.jpg

                                              It's old fashioned but an earlier generation knew what they were doing and we can use that in the digital age.

                                               

                                              Hope this helps,

                                              Tim CEPA

                                              Believe in The Q!

                                      • Re: PDF Watermark based on state (Add-in)
                                        Lee CS Young

                                        With my add-in, the PDF is the native file. It may not work in your scenario but I felt it was worth pointing out.

                                    • Re: PDF Watermark based on state (Add-in)
                                      Tim Webb

                                      Sebastian,

                                      I second the recommendation for Lee Young's Office add-in to avoid trying to recreate the wheel. Give it a go.

                                       

                                      Best,

                                      Tim

                                      Believe in The Q!