How to resize image stamp annotation

Product: PDF Tron SDK

Product Version: 9.0177774

Hello

I am trying to create image annotation using custom Stamp Annotation. I could able to extend the Stamp annotaion and create basic image annotaion. But the image size seems to be very big even though I am using 40px image. Below is the class file used and output of the image annotation.

class CheckMarkAnnotation(ctrl: PDFViewCtrl) : Stamper(ctrl) {
    companion object {
        var MODE = ToolManager.ToolMode.addNewMode(Annot.e_Stamp)
    }


    override fun getToolMode(): ToolModeBase {
        return MODE
    }

    override fun addStamp() {
        val resource =
            Utils.copyResourceToLocal(
                mPdfViewCtrl.context,
                R.raw.ic_checkmark_1_32,
                "CheckMark",
                "png"
            )
        createImageStamp(Uri.fromFile(resource), 0, null)
    }
}

As you can see in the screenshot, the image annotations seems very big. I have select the annotation and manually resize them.

Is there a way to define the annotation width, height when creating custom stamp annotation?

Thank you

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi,

After investigation, it appears the default behaviour is to scale the stamp to 25% of the screen width, this resulting in these images being much larger than your source. If you review the Stamper.java class, you will find this noted in the method createImageStamp()

            // calculate the max image size based off of screen width and height
            double maxImageHeightPixels = screenHeight * 0.25;
            double maxImageWidthPixels = screenWidth * 0.25;

You can customize this scaling to match your desired outcome (for example *0.1 for 10% of the screen width)

Could you give this a try? Thanks
Andrew

Hi Ama

Thanks for your help. I couldn’t find any method, variable names on stamp object to set the scaling factor. Can you point me the doc or example code?

Hi,

You will have to override the Stamper’s createImageStamp method to tailor fit your needs, for example if you wish to set it to 40x40, you would add this to your CheckMarkAnnotation class:

@Override
public boolean createImageStamp(Uri uri, int imageRotation, String filePath) {
     ...
            double stampWidth = 40;
            double stampHeight = 40;

            com.pdftron.pdf.Stamper stamper = new com.pdftron.pdf.Stamper(com.pdftron.pdf.Stamper.e_absolute_size, stampWidth, stampHeight);
     ...

Original Stamp:

Custom Stamp Size (40x40)

Stampler class is documented here: Stamper - PDFTron API Reference | PDFTron Systems Inc.

Under the SDK source code you can reference:
package com.pdftron.pdf.tools.Stamper

Best Regards,
Andrew

Hi ama

Thanks for your suggestion. I did the same to control the stamp size but instead of overriding createImageStamp() method, I used addImageStamp() method.

Regards
Ravi