- Posts: 13
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about iOS development and PDF
Center aligning small pages
IP: 192.168.0.71
8 years 11 months ago - 8 years 11 months ago #12220
by cornelius
Center aligning small pages was created by cornelius
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
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
Last edit: 8 years 11 months ago by cornelius.
IP: 192.168.0.71
8 years 11 months ago #12277
by emanuele
Replied by emanuele on topic Center aligning small pages
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:
To center the page you can do something like:
You can find vLayout method in PDFV class (pay attention to modify the vLayout method of the correct implementation, in this case PDFVVert)
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:
Code:
-(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:
Code:
-(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)
IP: 192.168.0.71
8 years 11 months ago #12278
by cornelius
Replied by cornelius on topic Center aligning small pages
You are awesome. Will give it a try. Thank you
IP: 192.168.0.71
8 years 7 months ago #12710
by razvar
Replied by razvar on topic Center aligning small pages
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
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
IP: 192.168.0.71
8 years 7 months ago #12720
by emanuele
Replied by emanuele on topic Center aligning small pages
Hi,
you can try changing the code in while block, in this way:
And need to edit also vGoto method in PDFView class, changing
to
you can try changing the code in while block, in this way:
Code:
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
Code:
if (g_def_view > 1)
[m_view vSetPos:&pos :gapX :gapY];
else
[m_view vSetPos:&pos :0 :0];
to
Code:
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
IP: 192.168.0.71
8 years 7 months ago #12722
by razvar
Replied by razvar on topic Center aligning small pages
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.
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.
Time to create page: 0.371 seconds