print/print preview paging.

Hi,

I’m writing a program which reads a plain text file and converts the input 
to a formatted label print, ie. format, group and paginate the data, and then 
print (display) the label print.

The application framework is CDocument/CFrameWnd/ CScrollView. I tried two 
ways to do the job.

First way, in CScrollView::OnDraw, it reads each input line and formats it, 
and TextOut in CScrollView. It doesn’t know how many lines and pages needed.

The second way is - in CDocument::OnOpenDocument it reads input lines and 
stores each line in CStringArray. In 
CScrollView::OnDraw it TextOut each array element. It set pages with  
SetMaxPage in CScrollView::OnPreparePrinting.

In both case, no MapMode change in this stage, nor font change. The output 
on CScrollView is ok. But when click Print Preview, it only displays one page 
– the first page, the next page is blank.

What’s wrong?

Thanks,

ybc
0
ybc (16)
7/19/2006 4:37:02 AM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
736 Views

Similar Articles

[PageSpeed] 12

If the pages is not set with SetMaxPage in CScrollView::OnPreparePrinting, 
it only displays one page – the first page, the next page is blank.

If the pages is set with SetMaxPage in CScrollView::OnPreparePrinting, all 
the pages are identical - as the first page.
 
ybc
0
ybc (16)
7/19/2006 7:48:01 AM
At a guess (and without seeing your code that's all it's going to be),
you're outputting all your strings in OnDraw(). What you need to do is
find out which page you're on (see below) and only output the correct
strings. The StringArray approach is therefore best, especially if you
wish to hop backwards and forwards in Print Preview.

To get the current page, in my .h I declare
	UINT	uiCurPage;
and in OnPrint() do
	uiCurPage=pInfo->m_nCurPage;
Then in OnDraw() I can use uiCurPage to start from the right point in
the array.

HTH

Paul.

0
paul.ganney1 (118)
7/19/2006 9:01:02 AM
I TRACE pInfo->m_nCurPage, it's 1 and 2, ie. only 2 pages. But 
pInfo->SetMaxPage is set to 13 
(pDoc->m_stringArray.GetUpperBound()/LinesPerPage + 1)

BOOL CArclabsView::OnPreparePrinting(CPrintInfo* pInfo)
{
	CArclabsDoc* pDoc = GetDocument();
	pInfo->SetMaxPage(pDoc->m_stringArray.GetUpperBound()/CArclabsDoc::nLinesPerPage + 1);   
	return DoPreparePrinting(pInfo);
}

"Paul S. Ganney" wrote:

> At a guess (and without seeing your code that's all it's going to be),
> you're outputting all your strings in OnDraw(). What you need to do is
> find out which page you're on (see below) and only output the correct
> strings. The StringArray approach is therefore best, especially if you
> wish to hop backwards and forwards in Print Preview.
> 
> To get the current page, in my .h I declare
> 	UINT	uiCurPage;
> and in OnPrint() do
> 	uiCurPage=pInfo->m_nCurPage;
> Then in OnDraw() I can use uiCurPage to start from the right point in
> the array.
> 
> HTH
> 
> Paul.
> 
> 
0
ybc (16)
7/19/2006 11:23:02 PM
I TRACE the pInfo->m_nCurPage. When I click 'Next Page' in Print Preview, 
pInfo->m_nCurPage is 1,2,3,...13. It's correct. But it only display the first 
page. The code is as the following:

void CArclabsView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
	CSize sizeTotal (4000, 100000);
	CSize sizePage (sizeTotal.cx/2, sizeTotal.cy/10);
	CSize sizeLine (sizeTotal.cx/2, sizeTotal.cy/100);
	SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
}
void CArclabsView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	int i, nStart, nEnd, nPage;
	CArclabsDoc* pDoc = GetDocument();
	nPage = pInfo->m_nCurPage ;
	nStart = (nPage -1) * CArclabsDoc::nLinesPerPage;
	nEnd = nStart + CArclabsDoc::nLinesPerPage;
	for (i = nStart; i < nEnd; i++)
	{
		if (i > pDoc->m_stringArray.GetUpperBound ())
			break;
TRACE("%s\n",pDoc->m_stringArray[i]);
		pDC->TextOut (20, i * 100, pDoc->m_stringArray[i]);
	}
	//CScrollView::OnPrint(pDC, pInfo);
}

The output of TRACE for the string array is correct, but no output in Print 
Preview.

0
ybc (16)
7/19/2006 11:56:01 PM
If your strings are correct (which it seems that they are) then it's
probably printing off-page. Try setting your mapping mode in OnPrint()
(you shouldn't need to, but then again your code looks fine). Another
thing to try is doing 2 TextOuts, e.g.

pDC->TextOut (20, i, pDoc->m_stringArray[i]);
pDC->TextOut (20, -i, pDoc->m_stringArray[i]);

Paul.

0
paul.ganney1 (118)
7/20/2006 9:00:52 AM
Reply:

Similar Artilces: