Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Adobe X1 SDK. And I am trying to add a watermark to a pdf. There is an example in c# that comes with the SDK, here watermark is inserted on the top of the first page, I need to insert the watermark on mouse click, that is wherever i click the mouse i want this watermark to be inerted on the pdf document.


Here is the original Adobe sample code

C#
private void addWatermarkButton_Click(object sender, EventArgs e)
{
            String filter = "PDF Files (*.pdf)|*.PDF|" +
              "All files (*.*)|*.*";
            String filename = chooseFile(filter);
            if (filename != null && g_AVDoc.IsValid())
            {
                CAcroPDDoc pdDoc = (CAcroPDDoc)g_AVDoc.GetPDDoc();
                 //Acquire the Acrobat JavaScript Object interface from the PDDoc object
                Object jsObj= pdDoc.GetJSObject();

               /* Add a watermark from a file. 
                * See the readme for a discussion on InvokeMember.
                function prototype:
                  addWatermarkFromFile(cDIPath, nSourcePage, nStart, nEnd, bOnTop, bOnScreen, bOnPrint, nHorizAlign, nVertAlign, nHorizValue, nVertValue, bPercentage, nScale, bFixedPrint, nRotation, nOpacity)
               */
                object[] addFileWatermarkParam = { filename, 0, 0, 0, true, true, true, 0, 3, 10, -10, false, 0.4, false, 0, 0.7 };

                Type T = jsObj.GetType();
                T.InvokeMember(
                        "addWatermarkFromFile",
                        BindingFlags.InvokeMethod |
                        BindingFlags.Public |
                        BindingFlags.Instance,
                        null, jsObj, addFileWatermarkParam);

                //get current time and make a string from it
                System.DateTime currentTime = System.DateTime.Now;

                /* make a color object */
                Object colorObj = T.InvokeMember(
                        "color",
                        BindingFlags.GetProperty |
                        BindingFlags.Public |
                        BindingFlags.Instance,
                        null, jsObj, null);
                Type colorType = colorObj.GetType();
                Object blueColorObj = colorType.InvokeMember(
                        "blue",
                        BindingFlags.GetProperty |
                        BindingFlags.Public |
                        BindingFlags.Instance,
                        null, colorObj, null);

                /* Add a text watermark.
                ' function prototype:
                '   addWatermarkFromText(cText, nTextAlign, cFont, nFontSize, color, nStart, nEnd, bOnTop, bOnScreen, bOnPrint, nHorizAlign, nVertAlign, nHorizValue, nVertValue, bPercentage, nScale, bFixedPrint, nRotation, nOpacity)
                */
                 object[] addTextWatermarkParam = { currentTime.ToShortTimeString(), 1, "Helvetica", 100, blueColorObj, 0, 0, true, true, true, 0, 3, 20, -45, false, 1.0, false, 0, 0.7 };
                T.InvokeMember(
                        "addWatermarkFromText",
                        BindingFlags.InvokeMethod |
                        BindingFlags.Public |
                        BindingFlags.Instance,
                        null, jsObj, addTextWatermarkParam);              
            }
}
Posted
Updated 30-Oct-14 22:48pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900