Implemented: DrawNonCurrentPage
Implemented: DrawNonCurrentPage
Probably the #1 most-wanted feature for us is the ability to do DrawCurrentPage, but for pages besides the current page. That is, render an arbitrary page in a document to an HDC.
Here is a sample C++ code:
Code: Select all
/////////////////////////////////////////////////////////////////////////////
void CSample1::CreatePageBitmap( int pageNumber)
/////////////////////////////////////////////////////////////////////////////
{
// m_pdf is the IPDFCreactiveX interface pointer
//delete an existing bitmap
if ( m_hBitmap != NULL )
{
DeleteObject( m_hBitmap );
m_hBitmap = NULL;
}
//prepare memory dc that will be used to create the bitmap for this thumb
HDC hScreenDC = GetDC( NULL );
HDC hMemDC = CreateCompatibleDC( hScreenDC );
m_hBitmap = CreateCompatibleBitmap( hScreenDC, m_size.cx, m_size.cy );
//select the new bitmap into the memory dc
HBITMAP hOldBitmap = (HBITMAP) SelectObject( hMemDC, m_hBitmap );
//draw a grey border white filled rectangle to mark the bitmap's frame
HPEN hPen = CreatePen( PS_SOLID, 1, RGB(127,127,127) ); //light gray pen
HPEN hOldPen = (HPEN) SelectObject( hMemDC, hPen );
Rectangle( hMemDC, 0, 0, m_size.cx, m_size.cy );
SelectObject( hMemDC, hOldPen );
DeleteObject( hPen );
//copy the bitmap from a source dc to our memory dc, taking into account the border
if ( m_pdf )
{
int saveDC;
int oldMap;
SIZE oldWindow, oldView;
saveDC = SaveDC( hMemDC );
// set scale and origin
oldMap = SetMapMode( hMemDC, MM_ISOTROPIC );
// set scaling factor
SetWindowExtEx( hMemDC, 2000, 2000, &oldWindow );
SetViewportExtEx( hMemDC, acThumbnailCtrl::m_thumbSizeFactor, acThumbnailCtrl::m_thumbSizeFactor, &oldView );
// switch to current page before drawing it
long savePage = m_pdf->GetCurrentPage();
BOOL saveRefresh = m_pdf->GetAutoRefresh();
m_pdf->PutAutoRefresh( FALSE );
m_pdf->PutCurrentPage( (long) pageNumber + 1/*pageNumber is zero-based*/ );
m_pdf->DrawCurrentPage( (long) hMemDC, 0 );
m_pdf->PutCurrentPage( savePage );
m_pdf->PutAutoRefresh( saveRefresh );
// reset previous scaling
SetViewportExtEx( hMemDC, oldView.cx, oldView.cy, NULL );
SetWindowExtEx( hMemDC, oldWindow.cx, oldWindow.cy, NULL );
SetMapMode( hMemDC, oldMap );
RestoreDC( hMemDC, saveDC );
}
else
{
BitBlt( hMemDC, 2, 2, m_size.cx - 4, m_size.cy - 4, hScreenDC, 0, 0, SRCCOPY );
}
//deselect the bimtap out of the mem dc and delete the mem dc
SelectObject( hMemDC, hOldBitmap );
DeleteDC( hMemDC );
//release the source dc
ReleaseDC( NULL, hScreenDC );
}