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

TOPIC:

Center aligning small pages 7 years 2 weeks ago #12220

  • cornelius
  • cornelius's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
Good day,

Is there a way to center align pages that are smaller. Currently they are left aligned.
Is there maybe a way to fit it rather (all pages to have the same width but different heights)?

Thank you,
Cornelius

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

Last edit: by cornelius.

Center aligning small pages 7 years 1 week ago #12277

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

this is the standard behaviour of the demo project, but you can customize the vLayout method of the view mode in use to set the correct page rect.
Now, the page position is based on the biggest page size.
For example, for vertical view mode, the vLayout is:
-(void)vLayout
{
    if( m_w <= 0 || m_h <= 0 || !m_pages ) return;
    PDF_SIZE sz = [m_doc getPagesMaxSize];
    m_scale_min = (m_w - m_page_gap) / sz.cx;
    m_scale_max = m_scale_min * g_zoom_level;
    if( m_scale < m_scale_min ) m_scale = m_scale_min;
    if( m_scale > m_scale_max ) m_scale = m_scale_max;
    int cur = 0;
    int end = m_pages_cnt;
    int left = m_page_gap_half;
    int top = m_page_gap_half;
    while( cur < end )
    {
        PDFVPage *vpage = m_pages[cur];
        [vpage SetRect:left:top:m_scale];
        top += [vpage GetHeight] + m_page_gap;
        cur++;
    }
    m_docw = sz.cx * m_scale;
    m_doch = top - m_page_gap_half;
}

To center the page you can do something like:
-(void)vLayout
{
    if( m_w <= 0 || m_h <= 0 || !m_pages ) return;
    PDF_SIZE sz = [m_doc getPagesMaxSize];
    m_scale_min = (m_w - m_page_gap) / sz.cx;
    m_scale_max = m_scale_min * g_zoom_level;
    if( m_scale < m_scale_min ) m_scale = m_scale_min;
    if( m_scale > m_scale_max ) m_scale = m_scale_max;
    int cur = 0;
    int end = m_pages_cnt;
    int left = m_page_gap_half;
    int top = m_page_gap_half;
    while( cur < end )
    {
        PDFVPage *vpage = m_pages[cur];
        
        left = (m_w - [vpage GetWidth]) / 2; // Set a custom left value
        
        [vpage SetRect:left:top:m_scale];
        top += [vpage GetHeight] + m_page_gap;
        cur++;
    }
    m_docw = sz.cx * m_scale;
    m_doch = top - m_page_gap_half;
}

You can find vLayout method in PDFV class (pay attention to modify the vLayout method of the correct implementation, in this case PDFVVert)
The following user(s) said Thank You: cornelius

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

Center aligning small pages 7 years 1 week ago #12278

  • cornelius
  • cornelius's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
You are awesome. Will give it a try. Thank you

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

Center aligning small pages 6 years 8 months ago #12710

  • razvar
  • razvar's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 15
  • Thank you received: 0
Hi emanuele,

This works great but unfortunately after you zoom in/zoom out (double tap) page left position is reseted and you will see only half of the page. Any way to overcome this? Do I need to set the left position somewhere else as well? After the zoom out or something like that? Also, after adjusting the left position to "left = (m_w - [vpage GetWidth]) / 2" in vLayout the change is done after you try to move the page, so it doesn't set the left position right away...

Thank you

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

Center aligning small pages 6 years 8 months ago #12720

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

you can try changing the code in while block, in this way:
while( cur < end )
    {
        PDFVPage *vpage = m_pages[cur];
        
        // Init page pos and size
        [vpage SetRect:left:top:m_scale];
        
         // Set a custom left value
        left = (m_w - [vpage GetWidth]) / 2;
        
        // Re-Set the page position using the custom left
        [vpage SetRect:left:top:m_scale];
        
        top += [vpage GetHeight] + m_page_gap;
        cur++;
    }

And need to edit also vGoto method in PDFView class, changing
if (g_def_view > 1)
        [m_view vSetPos:&pos :gapX :gapY];
    else
        [m_view vSetPos:&pos :0 :0];

to
if (g_def_view > 1)
        [m_view vSetPos:&pos :gapX :gapY];
    else
        [m_view vSetPos:&pos :gapX :0]; // Add the necessary gap to center the page
The following user(s) said Thank You: razvar

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

Center aligning small pages 6 years 8 months ago #12722

  • razvar
  • razvar's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 15
  • Thank you received: 0
Hi,

Thanks a lot for that. It works great but after I zoom in and scrolling to left/right while zoomed the edge of the page will go bellow 0 (ie minus the gapX) and it will not display all as it will scroll back to under zero... I've tried adding the gapX in scrollViewDidScroll (PDFView) but that didn't work. Any suggestions?

Thanks again.

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

  • Page:
  • 1
  • 2
Powered by Kunena Forum