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)
}
}
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)
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);
...
Thanks for your suggestion. I did the same to control the stamp size but instead of overriding createImageStamp() method, I used addImageStamp() method.