Home  docPrint  docPrint-Pro  Support  ScreenShots

Draw EMF (Metafile) 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 DrawEMFToDocPrint( HANDLE& prnHandle, char* sPrnName, 
		DEVMODE* dm, HENHMETAFILE hMeta )
{
	HDC hDC;
	DOCINFO di = { sizeof(DOCINFO), "Metafile Printing" };
	RECT rcOut = { 0 };
	ENHMETAHEADER hdr = { 0 };

	SetOutputFileName(szOutputFileName);
	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 );

	GetEnhMetaFileHeader( hMeta, sizeof( hdr ), &hdr );
	rcOut.right = hdr.rclBounds.right;
	rcOut.bottom = hdr.rclBounds.bottom;

	PlayEnhMetaFile( hDC, hMeta, &rcOut ); 

	EndPage( hDC );
	EndDoc( hDC );

	DeleteDC( hDC );
}

void CDemo_converter_comDlg::OnButtonEmf() 
{
	SetOutputFileName(szOutputFileName);
	CString sPrnName = szPrinterName;
	HANDLE prnHandle = 0;
	PRINTER_DEFAULTS pd = { 0, 0, PRINTER_ACCESS_USE };
	DEVMODE* dm = 0;
	long len = 0;
	HENHMETAFILE hMeta = 0;

	static char BASED_CODE szFilter[] = "Enhanced Metafile 
		(*.emf)|*.emf||";

	CFileDialog dlg( 1, 0, 0, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST 
		| OFN_PATHMUSTEXIST, szFilter, 0 );
	if( dlg.DoModal() != IDOK )
		return;

	hMeta = GetEnhMetaFile( dlg.m_ofn.lpstrFile ); 
	if( !hMeta )
		return;
	if( !OpenPrinter( (char*)(LPCTSTR)sPrnName, &prnHandle, &pd ) )
	{
		DeleteEnhMetaFile( hMeta );
		return;
	}

	len = DocumentProperties( 0, prnHandle, 
		(char*)(LPCTSTR)sPrnName, 0, 0, 0 );
	if( len <= 0 )
	{
		DeleteEnhMetaFile( hMeta );
		ClosePrinter( prnHandle );
		return;
	}
	dm = (DEVMODE*)malloc( len );

	DocumentProperties( 0, prnHandle, (char*)(LPCTSTR)sPrnName, 
		dm, 0, DM_OUT_BUFFER );

	DrawEMFToDocPrint( prnHandle, (char*)(LPCTSTR)sPrnName, 
		dm, hMeta );

	DeleteEnhMetaFile( hMeta );

	ClosePrinter( prnHandle );
	free( dm ); 
}

Copyright © 2000-2006 by VeryPDF, Inc.
Send comments about this site to the webmaster.