Need to add annotation in swift as per our define position. - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF
  • Page:
  • 1
  • 2

TOPIC: Need to add annotation in swift as per our define position.

Need to add annotation in swift as per our define position. 1 month 5 days ago #14289

  • apdeveloper
  • apdeveloper's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 25
  • Thank you received: 0
Hi Team,
I have to add annotation from swift project like (x, y, height, width) at some particular position programmatically and that annotation is going to work as our currently working annotation.


Can you please help me out as soon as possible.

Please Log in or Create an account to join the conversation.

Need to add annotation in swift as per our define position. 1 month 4 days ago #14290

  • emanuele
  • emanuele's Avatar
  • Online
  • Moderator
  • Moderator
  • Posts: 543
  • Karma: 21
  • Thank you received: 65
Hi,

you could take a look at addEditText method of PDFView class (Obj-C part).
You could use the same logic and add your annotations (this method is based on screen coordinates).

Please Log in or Create an account to join the conversation.

Need to add annotation in swift as per our define position. 1 month 2 hours ago #14294

  • apdeveloper
  • apdeveloper's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 25
  • Thank you received: 0
Hi Team,
Do you have any idea how to pass annotation position from swift project and show in radaee pdf do you have any dummy how to do that.

Please Log in or Create an account to join the conversation.

Need to add annotation in swift as per our define position. 3 weeks 6 days ago #14295

  • apdeveloper
  • apdeveloper's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 25
  • Thank you received: 0
Hi Team,
I have added this code but unable to see any annotation

// get the vpage to calculate the annot size based on current scale value
PDFVPage *vpage = [m_view vGetPage:0];
PDFPage *page = [vpage GetPage];

// customize this part to modify the rect size and position
int x = 50;
int y = 100;
int width = 500;
int height = 100;

// convert the coordinate system from screen to pdf
struct PDFV_POS pos1;
struct PDFV_POS pos2;

[m_view vGetPos:&pos1 :(x - self.contentOffset.x) * m_scale :(y - self.contentOffset.y) * m_scale];
[m_view vGetPos:&pos2 :(x - self.contentOffset.x + width) * m_scale :(y - self.contentOffset.y + height) * m_scale];

PDF_RECT rect;

rect.left = pos1.x;
rect.right = pos2.x;
rect.top = pos2.y;
rect.bottom = pos1.y;

// add the annotation
[page addAnnotRect:&rect: g_rect_Width * m_scale / [m_view vGetScaleMin:0]: g_rect_color: 0];

// refresh the page
[m_view vRenderSync:0];
[self refresh];

Please Log in or Create an account to join the conversation.

Need to add annotation in swift as per our define position. 3 weeks 6 days ago #14296

  • apdeveloper
  • apdeveloper's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 25
  • Thank you received: 0
Hi team,
Can you just reply little fast what i am doing wrong after i have added the above code in PDFview.m file in objc and calling this function using the delegate from swift project but unable to see the annotation.

Please Log in or Create an account to join the conversation.

Need to add annotation in swift as per our define position. 3 weeks 6 days ago #14297

  • emanuele
  • emanuele's Avatar
  • Online
  • Moderator
  • Moderator
  • Posts: 543
  • Karma: 21
  • Thank you received: 65
Hi,
to add a new method, starting from PDFView class, you should add the method in:
- PDFView class: add and implement the new method.
- RDPDFViewController: add new method the calls the PDFView class' method.
- RadaeePDFPlugin: add new method the calls the RDPDFViewController class' method.

Then build the lib project and replace the RadaeePDFPlugin.h into your project, run the make command to create the new lib and replace the old one into your project.
Please be sure to use your method when the pdf file is opened, as it's using vpage instance.
If you want to add annotation using the PDF coordinate system you should use something like:
// get the page from doc
    PDFPage *page = [m_doc page:0];
    [page objsStart];
    
    // customize this part to modify the rect size and position
    int x = 50; // left
    int y = 200; // top
    int width = 200;
    int height = 100;
    
    // create rect in pdf coordinate system
    PDF_RECT rect;
    
    rect.left = x;
    rect.right = x + width;
    rect.top = y;
    rect.bottom = y + height;
    
    // add the annotation
    [page addAnnotRect:&rect: g_rect_Width * m_scale / [m_view vGetScaleMin:0]: g_rect_color: 0];
    
    // refresh the page
    [m_view vRenderSync:0];
    [self refresh];
If you want to add the annotation when the pdf file is closed (only PDF coordinate system) you should also:
- open it with a PDFDoc instance (Ex. [m_doc open:*pdfPath* :*password*];)
- remove [self refresh] at the end of the method
- add [m_doc save]; at the end of the method
The following user(s) said Thank You: apdeveloper

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum