VBA WatermarkParams .Scale  SOLVED

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Stefan - PDF-XChange

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
User avatar
OfficeWorker
User
Posts: 2
Joined: Mon Aug 04, 2025 12:51 pm

VBA WatermarkParams .Scale

Post by OfficeWorker »

Hello there,

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
image.png
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

You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11731
Joined: Wed Jan 03, 2018 6:52 pm

Re: VBA WatermarkParams .Scale

Post by Daniel - PDF-XChange »

Hello, OfficeWorker

I am very sorry for the delay, it seems that this post was missed, and I only just spotted it now.
I have raised this topic to the Dev team today to see what they think could be the cause. It looks like to me that the error is from VBA itself, but we shall see what the experts have to say.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3593
Joined: Thu Jul 08, 2004 10:36 pm

Re: VBA WatermarkParams .Scale  SOLVED

Post by Ivan - Tracker Software »

It is not our issue, but a VBA-specific issue. For some reason, in the wp.Scale, VBA treats this Scale as a call to its method Scale, instead of the object's property. Do not ask me why.
A workaround for this is to use With:

Code: Select all

With wp
    .Scale = 76
End With
P.S. The Opacity property has a range from 0 to 100. Setting it to 1 will make your watermark almost invisible.
PDF-XChange Co Ltd. (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
User avatar
OfficeWorker
User
Posts: 2
Joined: Mon Aug 04, 2025 12:51 pm

Re: VBA WatermarkParams .Scale

Post by OfficeWorker »

Thanks for the reply, better late then never :lol:

The with solution works lovely, thanks! The company bought the license by now and I was close to pushing the update through, I did find out about the opacity and the only thing not working at this point was the scale, which i can work on today :) .

Once again VBA proving to me why im not a fan of it.
Ivan - Tracker Software wrote: Mon Sep 15, 2025 7:50 pm For some reason, in the wp.Scale, VBA treats this Scale as a call to its method Scale, instead of the object's property.
Do you know why it happens? :wink:
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11731
Joined: Wed Jan 03, 2018 6:52 pm

Re: VBA WatermarkParams .Scale

Post by Daniel - PDF-XChange »

Hello, OfficeWorker

I'm going to take the safe route here say say that... he probably doesn't know the answer to that question, given what immediate followed the section you quoted:
Ivan wrote: Do not ask me why.
I am sorry to say, that you will need to reach out elsewhere, likely to Microsoft and ask why these VBA actions are acting up, as it is beyond our expertise.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com