| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 142148 | 2016-05-05 00:18:00 | Help needed with VBA and PDFs | Tony (4941) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 1420129 | 2016-05-06 06:21:00 | You can always create your own function (helper), that can fill in some defaults and do what you want and be as easy as addText(). I am sure you will learn how you can do that. | Kame (312) | ||
| 1420130 | 2016-05-07 00:04:00 | OK, I ' m stuck again. I ' m trying to add a watermark, using the code below. The API reference says it should work. What am I missing? Also the reference says I ought to be able to add a newline by using \n (or \r depending where you read), but I can ' t get that to work either. --> Sub test2() Dim FileNm, gApp, avDoc, pdDoc, jso, res Dim str1, str2 As Object Dim rect(3) As Integer FileNm = "C:\Users\Tony\Desktop\access\Email development\SubsTemplateForm.pdf" ' File location Set gApp = CreateObject("AcroExch.app") Set avDoc = CreateObject("AcroExch.AVDoc") If avDoc.Open(FileNm, "") Then Set pdDoc = avDoc.GetPDDoc() Debug.Print pdDoc.GetFileName Set jso = pdDoc.GetJSObject ' Define form field area rect(0) = 165 ' x lower left rect(1) = 668 ' y lower left rect(2) = 225 ' x upper right rect(3) = 686 ' y upper right ' add a form field Set Field = jso.addField("myFormField", "text", 0, rect) Field.Value = "Testing" ' add a watermark ' ********* This works jso.addWatermarkFromText ("Testing text") ' ********* Below gives a syntax error - if I add ANYTHING after "Confidential" ' ********* The Acrobat API reference says this is the syntax jso.addWatermarkFromText("testing text", 0, font.Helv, 24, color.red); If MsgBox("Save doc?", vbYesNo) = vbYes Then pdDoc.Save PDSaveIncremental, "C:\Users\Tony\Desktop\access\Email development\test document(2).pdf" ' Save changes to the PDF document End If pdDoc.Close End If ' Close the PDF; the True parameter prevents the Save As dialog from showing avDoc.Close (True) ' Some cleaning Set gApp = Nothing Set avDoc = Nothing Set pdDoc = Nothing Set jso = Nothing End Sub --> |
Tony (4941) | ||
| 1420131 | 2016-05-07 02:14:00 | Are semi-colons required? You added one in the second attempt. Anyways, if you do use more than 1 parameter, it seems from the API that you must fill in all parameters, which is ridiculous, but that's how I am reading it. So, give everything a parameter, this is where a helper function would come in handy. |
Kame (312) | ||
| 1420132 | 2016-05-07 02:32:00 | My bad with the semi colon. it was a cut and paste from the api document. Removing it makes no difference. I found if you remove the brackets from the second example it will compile, but stops with "Invalid qualifier" on "color.red" when it is executed. If I remove that parameter it stops with "object required". I can see the use of the helper function, but I still have to get the basic syntax etc correct before I can build one, right? |
Tony (4941) | ||
| 1420133 | 2016-05-07 03:44:00 | maybe color.red is not set. Try jso.color.red or create it. color.red = new Array("RGB", 1, 0, 0) |
Kame (312) | ||
| 1420134 | 2016-05-07 03:58:00 | My bad again. Color.red actually doesn't compile, with the "invalid qualifier" message. It seems OK with "font.helv" though. WTF?? Part of my problem I am sure is not understanding some basic concepts, but I haven't found anywhere that can give me those. For instance the API documentation says: The color object is a convenience static object that defines the basic colors. Use this object to set a property or call a method that requires a color array. but I don't know how to expose that. |
Tony (4941) | ||
| 1 2 | |||||