Draw Bitmap (Image) to docPrint Using Windows API
docPrint and docPrint Pro are virtual printer
software that saves any document you print as 20+ formats. Below are some
examples that can help you to accomplish your task with docPrint Printer.
Download Evaluation Version of docPrint
SDK
Purchase docPrint SDK
#include <Winspool.h> void DrawBMPToDocPrint( HANDLE& prnHandle, char* sPrnName, DEVMODE* dm, HBITMAP hBmp ) { SetOutputFileName(szOutputFileName); HDC hDC = 0, tmpDC = 0; DOCINFO di = { sizeof(DOCINFO), "BMP Printing" }; HBITMAP oldBmp = 0; BITMAP info = { 0 }; hDC = CreateDC( 0, sPrnName, 0, dm ); if( !hDC ) { ClosePrinter( prnHandle ); free( dm ); return; } if( StartDoc( hDC, &di ) == SP_ERROR ) { DeleteDC( hDC ); ClosePrinter( prnHandle ); free( dm ); return; } StartPage( hDC ); tmpDC = CreateCompatibleDC( hDC ); oldBmp = (HBITMAP)SelectObject( tmpDC, hBmp ); GetObject( hBmp, sizeof( info ), &info ); BitBlt( hDC, 0, 0, info.bmWidth, info.bmHeight, tmpDC, 0, 0, SRCCOPY ); SelectObject( tmpDC, oldBmp ); DeleteDC( tmpDC ); EndPage( hDC ); EndDoc( hDC ); DeleteDC( hDC ); } void CDemo_converter_comDlg::OnButtonBmp() { SetOutputFileName(szOutputFileName); CString sPrnName = szPrinterName; HANDLE prnHandle = 0; PRINTER_DEFAULTS pd = { 0, 0, PRINTER_ACCESS_USE }; DEVMODE* dm = 0; long len = 0; HBITMAP hBmp = 0; static char BASED_CODE szFilter[] = "Windows Bitmap (*.bmp)|*.bmp||"; CFileDialog dlg( 1, 0, 0, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, szFilter, 0 ); if( dlg.DoModal() != IDOK ) return; hBmp = (HBITMAP) LoadImage( 0, dlg.m_ofn.lpstrFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION ); if( !hBmp ) return; if( !OpenPrinter( (char*)(LPCTSTR)sPrnName, &prnHandle, &pd ) ) { DeleteObject( hBmp ); return; } len = DocumentProperties( 0, prnHandle, (char*)(LPCTSTR)sPrnName, 0, 0, 0 ); if( len <= 0 ) { DeleteObject( hBmp ); ClosePrinter( prnHandle ); return; } dm = (DEVMODE*)malloc( len ); DocumentProperties( 0, prnHandle, (char*)(LPCTSTR)sPrnName, dm, 0, DM_OUT_BUFFER ); DrawBMPToDocPrint( prnHandle, (char*)(LPCTSTR)sPrnName, dm, hBmp ); DeleteObject( hBmp ); ClosePrinter( prnHandle ); free( dm ); } |
Copyright
© 2000-2006 by VeryPDF, Inc.
Send comments about this site to the webmaster.