下面的代码用Adobe pdf 打印出错,不能打印,有那位做过打印的高手给我指点指点,
另外用制图控件的PrintPageLayout这个方法打印也出错(参数设置没有问题的)
IActiveViewPtr pActiveView=m_ctrLayout.GetActiveView();
IPageLayoutPtr pPageLayout = pActiveView;
if(pPageLayout == NULL) return ;
IPagePtr pPage;
pPageLayout->get_Page(;pPage);
ASSERT(pPage != NULL);
// Optionally override the current PageToPrinterMapping, options for example:
// To tile the page layout over many pages if its bigger than the printer page
pPage->put_PageToPrinterMapping(esriPageMappingTile);
// Get ArcMaps current Printer object
IPageLayout2Ptr pPageLayout2 = pPageLayout;
IPrinterPtr pPrinter;
pPageLayout2->get_Printer(;pPrinter);
pPrinter->putref_Paper(m_ipPaper);
ASSERT(pPrinter != NULL);
// Find out how many printer pages the output will cover, nPageCount is calculated by PrinterPageCount.
// If nPageCount greater than 1 then we're going to tile the pagelayout onto multiple pages
// This will only be the case if pPage.PageToPrinterMapping = esriPageMappingTile
short nPageCount;
pPage->PrinterPageCount(pPrinter, 0, ;nPageCount);
for(short nCurrentPage = 0 ; nCurrentPage < nPageCount ; nCurrentPage++)
{
// Get dots per inch from printer
short printerDPI;
pPrinter->get_Resolution(;printerDPI);
// Get device bounds - this is in printer device coordinates (number of dots across page to a page)
// Note there is often a margin around the edge that is unprintable
IEnvelopePtr pDeviceBounds(CLSID_Envelope);
pPage->GetDeviceBounds(pPrinter, nCurrentPage, 0, printerDPI, pDeviceBounds);
//Get values (as doubles) out of the envelope and put them into a rectangle (as Longs)
double xMin, xMax, yMin, yMax;
pDeviceBounds->get_XMin(;xMin);
pDeviceBounds->get_YMin(;yMin);
pDeviceBounds->get_XMax(;xMax);
pDeviceBounds->get_YMax(;yMax);
RECT rectDeviceBounds;
rectDeviceBounds.left = (LONG)xMin;
rectDeviceBounds.top = (LONG)yMin;
rectDeviceBounds.right = (LONG)xMax;
rectDeviceBounds.bottom = (LONG)yMax;
// Compute the area of the page layout to send to the printer,
// this is in page layout units (inches or cm)
IEnvelopePtr pVisBounds(CLSID_Envelope);
pPage->GetPageBounds(pPrinter, nCurrentPage, 0, pVisBounds);
//Build envelope in device coordinates - this must be the whole paper
double paperWidthInch, paperHeightInch;
pPrinter->QueryPaperSize(;paperWidthInch, ;paperHeightInch);
IEnvelopePtr pDeviceFrame(CLSID_Envelope);
pDeviceFrame->PutCoords(0.0, 0.0, paperWidthInch * printerDPI, paperHeightInch * printerDPI);
OLE_HANDLE hDC;
// StartPrinting takes a device frame (whole page) and returns a handle to a device context (hDC)
pPrinter->StartPrinting(pDeviceFrame, NULL, ;hDC);
// This draws the visible bounds (pVisBounds) area of the
// active view to the printer
pActiveView->Output(hDC, long(printerDPI), ;rectDeviceBounds, pVisBounds, NULL);
pPrinter->FinishPrinting();
}
