So i am working on adding a watermark to a pdf in ms Access using VBA.
I recently got the PDFXCoreAPI dll's and the company i work at hasn't bought the license yet. That is probably the reason why the watermark itself isn't showing and only the demo stamps are there so ill skip that for now.
When i have a IPXC_WatermarkParams object and try to change the scale i get a compile error no matter what value entered I am fairly new to VBA and working with PDFXChange core API so i am not sure if it is a VBA or a PDFXChange thing. Looking at the documentation and other posts i am pretty certain this is the correct syntax so i don't know what's happening.
Here is some sample code below, same thing happens in Access and Excel so test where you prefer.
Code: Select all
Public Sub testWatermarkImage()
Dim objIPXC As PDFXCoreAPI.IPXC_Inst
Dim objIAUX As PDFXCoreAPI.IAUX_Inst
Dim objIAFS As PDFXCoreAPI.IAFS_Inst
Dim objDocMain As IPXC_Document
Dim rect As PXC_Rect
Dim bitset As IBitSet
Dim wp As IPXC_WatermarkParams
Dim resultPath As IAFS_Name
Set objIPXC = New PDFXCoreAPI.PXC_Inst
Set objIAUX = objIPXC.GetExtension("AUX")
Set objIAFS = objIPXC.GetExtension("AFS")
'I don't have a license key (yet)
objIPXC.init ""
Debug.Print objIPXC.APIVersion ' Prints: 33751040
Set objDocMain = objIPXC.NewDocument()
' Define A4 size
rect.Left = 0
rect.bottom = 0
rect.Right = 595
rect.Top = 842
' Add a blank page
objDocMain.Pages.AddEmptyPages 0, 1, rect
' Create watermark parameters
Set wp = objIPXC.CreateWatermarkParams()
wp.WatermarkType = 1 ' Image
wp.ImageFile = "C:\temp\myImage.png"
wp.Opacity = 1
wp.Rotation = 0
wp.HAlign = 2 ' Center
wp.VAlign = 2 ' Middle
wp.HOffset = 0
wp.VOffset = 0
wp.Start = 0
'wp.Scale = 76 ' Gives: "compile error: Expected: ("
' Apply watermark to all pages
Set bitset = objIAUX.CreateBitSet(objDocMain.Pages.Count)
objDocMain.PlaceWatermark bitset, wp
' Save the document
objDocMain.WriteToFile ("C:\temp\testWatermark.pdf")
End Sub