iosswiftpdftronpdfnet

PDFNet Resize annot Swift


Have anyone worked using PDFNet where the annot needs to be resized? For simplicity, currently i set the text of the annot using

annot.setContents(text)
annot.refreshAppearance()
pdfView.update()

However, if the text is too long where it exceeds the annot's width, it cant be resized and the text will be trimmed as the annot's width isnt wide enough. I checked the documentation and it seems there is a resize function, however the parameter it is taking isn't clear. Anyone with knowledge on this, thanks in advance


Solution

  • How are you creating the (free-text) annotations? If you are using a PTToolManager and creating the annotations with PTFreeTextCreate tool class, then you can enable auto-resize for free-text annotations with toolManager.isAutoResizeFreeTextEnabled = true

    Using the PTDocumentController class for viewing and annotating documents is highly recommended if possible, otherwise a PTPDFViewCtrl and PTToolManager should be used.

    The PTAnnot.resize() function is used to set the PDF page rect of the annotation, preserving (ie. scaling) the annotation's appearance to fill its new rect.

    Auto-resizing a free-text annotation without a PTToolManager would require calculating (yourself) the size of the text. The PTToolManager API approach is recommended.