Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF
  • Page:
  • 1
  • 2

TOPIC:

Adding image after moving UIImageView 7 years 10 months ago #10790

  • Shades
  • Shades's Avatar Topic Author
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 37
  • Thank you received: 0
Hi,
I didn't understand,what I mean is getting the inverse from PDF_RECT to CGRECT ?
Also,after adding the bitmap image is not getting in the right position after doing that :
struct PDFV_POS pos;
    [m_view vGetPos:&pos :frame.origin.x * m_scale :frame.origin.y* m_scale];
    _rect.left = pos.x;
    _rect.right = pos.x+frame.size.width;
    _rect.top = pos.y;
    _rect.bottom = pos.y+frame.size.height;
   NSString *tp = NSTemporaryDirectory();
    tp = [tp stringByAppendingPathComponent:@"cache.dat"];
    [m_doc setCache:tp];
    PDFPage *page = [m_doc page:p];
   CGImageRef ref = [UIImage imageWithData:data].CGImage;
      [page addAnnotBitmap:ref :YES :&_rect];
    [m_view vRenderSync:p];
    [self refresh];
    [m_doc save];

Any suggestions please ?

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

Last edit: by Shades.

From PDF_RECT to CGRect 7 years 10 months ago #10793

  • Shades
  • Shades's Avatar Topic Author
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 37
  • Thank you received: 0
Hi,
After adding the bitmap,I am trying to send it's coordinates to the server.That's why I think I need to convert the PDF_RECT to CGRECT.
I have done something like That:
struct PDFV_POS pos;
    [m_view vGetPos:&pos :signatureFrame.origin.x * m_scale :signatureFrame.origin.y* m_scale];
    _rect.left = pos.x;
    _rect.right = pos.x+signatureFrame.size.width;
    _rect.top = pos.y;
    _rect.bottom = pos.y+signatureFrame.size.height;
  CGRect rect1 = CGRectMake(self.contentOffset.x + (_rect.left)/m_scale,
                              self.contentOffset.y + (_rect.top)/m_scale,
                              (_rect.right - _rect.left)/m_scale,
                              (_rect.bottom - _rect.top)/m_scale);

But it seems I have done something wrong.Any suggestion please ?

Thank you

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

Adding image after moving UIImageView 7 years 10 months ago #10794

  • emanuele
  • emanuele's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 580
  • Thank you received: 67
Hi,

here is a checked slice of code that will help you.
to convert CGRect to PDF_RECT:
CGRect frame = CGRectMake(point.x, point.y, 100, 100);
    
    struct PDFV_POS pos1;
    struct PDFV_POS pos2;
    
    [m_view vGetPos:&pos1 :frame.origin.x * m_scale :frame.origin.y * m_scale];
    [m_view vGetPos:&pos2 :(frame.origin.x + frame.size.width) * m_scale :(frame.origin.y + frame.size.height) * m_scale];
    
    PDF_RECT rect;
    
    rect.left = pos1.x;
    rect.right = pos2.x;
    rect.top = pos2.y;
    rect.bottom = pos1.y;

to convert PDF_RECT to CGRect (this PDF_RECT if got from an annotation):
[m_annot getRect:&m_annot_rect];
            
m_annot_rect.left = [vpage GetX] - self.contentOffset.x * m_scale + [vpage ToDIBX:m_annot_rect.left];
m_annot_rect.right = [vpage GetX] - self.contentOffset.x * m_scale + [vpage ToDIBX:m_annot_rect.right];
float tmp = m_annot_rect.top;
m_annot_rect.top = [vpage GetY] - self.contentOffset.y * m_scale + [vpage ToDIBY:m_annot_rect.bottom];
m_annot_rect.bottom = [vpage GetY] - self.contentOffset.y * m_scale + [vpage ToDIBY:tmp];
            
int dx = m_tx - m_px;
int dy = m_ty - m_py;
CGRect rect1 = CGRectMake((m_annot_rect.left+dx)/m_scale,
                                      (m_annot_rect.top+dy)/m_scale,
                                      (m_annot_rect.right - m_annot_rect.left)/m_scale,
                                      (m_annot_rect.bottom - m_annot_rect.top)/m_scale);

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

Adding image after moving UIImageView 7 years 10 months ago #10795

  • Shades
  • Shades's Avatar Topic Author
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 37
  • Thank you received: 0
Thank you for your answer.
The first code works great.Thank you.
But still confused with the second one.If we suppose we have an UIImageView instead of an annotation,how could we get the right coordinates.My point is to send right coordinates to the server,so I need to get the position ( x,y) according to the pdf.
Now I have the PDF_RECT of the pdf but still not able to post them to the server.

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

Adding image after moving UIImageView 7 years 9 months ago #10797

  • emanuele
  • emanuele's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 580
  • Thank you received: 67
if you have a PDF_RECT you can convert it into CGRect with the second part of code, but if you have CGRect and you need only x,y according to pdf, you can simply use vGetPos method
struct PDFV_POS pos1;
[m_view vGetPos:&pos1 :rect.origin.x * m_scale :rect.origin.y * m_scale];
If you have PDF_RECT and you need only x,y you can use m_annot_rect.left, m_annot_rect.top, that represent x,y according to pdf.

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

Adding image after moving UIImageView 7 years 9 months ago #10801

  • Shades
  • Shades's Avatar Topic Author
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 37
  • Thank you received: 0
Hi,
Thank you!
Following that method,I don't get the right position in the server .I am confused.The image is moving to the top of the view.

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

  • Page:
  • 1
  • 2
Powered by Kunena Forum