Customization of PTSelectionRectContainerView for selected images

As you know, pdftron PTAnnotEditTool works by determine minX, maxX, minY and maxY and make it rectangle according to these points as below.

I want to customize it by creating my own borderView surrounding rotated image and put PTResizeWidgetViews manually into right point as below.

Everything is okay now but PTResizeWidgetViews act according to PTSelectionRectContainerView’s corner points and it does not work as I want. Screen recording exists below.

Is there any way to customize act of PTResizeWidgetView for rotated images? If it is not, can you help me about how to customize selection rect container view in another way if it is possible?
Thank you already!

Hi @bilgehan,

Thank you for getting in touch with us about this.

To rotate and resize image annotations, you can follow the sample code to create PTImage annotations, which doesn’t require placing PTResizeWidgetView manually.

For your case, you may also want to use these lines of code:

PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptrelative_scale a: 0.05 b: 0.05];
Other configuration you want to add
[s SetRotation: yourRotationDegree];
[s SetAsAnnotation:YES];
[s SetAsBackground: NO];

[s StampImage: doc src_img: img dest_pages: ps]; // Stamp the image here

PTPage* page = [doc GetPage:yourCurrentAnnotationPageNumber];
int numAnnots = [page GetNumAnnots];
PTAnnot* annot = [page GetAnnot:numAnnots - 1];
PTObj* obj = [annot GetSDFObj];
[obj PutString:PTImageStampAnnotationIdentifier value:@""];
[obj PutNumber:PTImageStampAnnotationRotationDegreeIdentifier value:yourRotationDegree];

To customize the selection rect container view and its borderView, you could subclass the PTAnnotEditTool, override the method - (**BOOL**)selectAnnotation:(PTAnnot *)annotation onPageNumber:(**unsigned** **int**)pageNumber, and implement your customization there.

For example:

- (BOOL)selectAnnotation:(PTAnnot *)annotation onPageNumber:(unsigned int)pageNumber
    // Let's say you are using the image stamp
    if ([self.currentAnnotation extendedAnnotType] == PTExtendedAnnotTypeImageStamp) {
        // Customization to the border view like:
        self.selectionRectContainerView.borderView.backgroundColor = UIColor.redColor;
        self.selectionRectContainerView.borderView.layer.borderWidth = 10;
    return [super selectAnnotation:annotation onPageNumber:pageNumber];

Please let me know if this works for you.

Thank your for your response. I already did your methods but I need specific customization as I mentioned. I do not want to use default rectangle but want to use surrounding border even if image rotated like second picture of mine. Furthermore, if I customize border view like that, widget views does not work according to the points I want to put in.

Hi @bilgehan,

Thank you for providing more information. Are you using CALayer or UIImage to draw the border?

If you are using an imageView, you could add it as a subview of the borderView in the selectAnnotation method and use auto layout to make sure they have the same frame.

If you are using CALayer, one way to solve the problem is to create a new class (e.g. MyView) inherited from UIView. In MyView’s init method, add the border as a sublayer. In MyView’s layoutSubviews method, set the border sublayer’s path and frame to be the same as the view. There are some code snippets that might help. Then you could create a MyView object and add it as a subview of the borderView in the selectAnnotation method and use auto layout to make sure they have the same frame.

Please let me know it this helps.