Add a UIView to a PDF page
This guide demonstrates how to make a `UIView` appear as if it is stuck to a page.
It is convenient for the user to make a UIView that is "stuck" to a page record its desired page location. To do this, you could add an extension/category to a UIView, or use a derived class, as shown below:
public class FloatingView : UIView
{
public FloatingView() : base()
{
}
public int PageNumber { get; set; }
public pdftron.PDF.Rect PdfPageRect { get; set; }
}class FloatingView: UIView {
// the page on which the UIView appears
var pageNumber: Int32 = 0
// the location, expressed in PDF coordinates, at which the view appears
var pdfPageRect: PTPDFRect?
}@interface FloatingView : UIView
// the page on which the UIView appears
@property (assign, nonatomic) int pageNumber;
// the location, expressed in PDF coordinates, at which the view appears
@property (strong, nonatomic) PTPDFRect* pdfPageRect;
@end
@implementation FloatingView
@end
In this example, we will add a red square to a location near the bottom left hand corner of the first page:
Without the last line in the code snippet above, the new view would not appear in the correct location. The following method will position it, and any others that have been added:
Whenever the PDF page shifts within the PTPDFViewCtrl, which may happen when changing the page presentation mode, zooming, and such, the views need to be re-positioned (positionFloatingViews needs to run again). To do this, implement the PTPDFViewCtrl delegate methods pdfScrollViewDidEndZooming: and onLayoutChanged, and in them, call positionFloatingViews:
Last updated
Was this helpful?