The CreateDC and CDICreateDC methods create a printer device context using the various parameters set using CDIntf function calls. The parameters include paper size, resolution, margins, font embedding, JPEG compression.
OLE_HANDLE CreateDC()
HDC CDICreateDC(HANDLE hPrinter)
hPrinter
Handle to printer returned by any of the DriverInit function calls.
The return value is a printer device context (hDC) if the function succeeds, NULL otherwise.
Member of CDIntfEx.CDIntfEx.
// DOCX Converter Cpp.cpp : Defines the entry point for the console application.
//
#include <Windows.h>
#include <string>
#include <iostream>
#include "CdIntf.h"
#pragma comment(lib, "CDIntf.lib")
using namespace std;
enum PAPERSIZE {
Letter = 1,
Legal = 5,
A4 = 9,
A2 = 8,
CustomSize = 256
};
int main()
{
// Constants for Activation codes
#define strLicenseTo "DOCX Converter Developer Evaluation"
#define strActivationCode "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190"
#define AMYUNIPRINTERNAME "Amyuni DOCX Converter"
// Get a reference to the installed printer.
// This will fail if the printer name passed to the DriverInit method is
// not found in the printer’s folder
HANDLE DOCX = DriverInit(AMYUNIPRINTERNAME);
// The CDISetDefaultPrinter function sets the system default printer to the one
// initialized by the DriverInit functions.
CDISetDefaultPrinter(DOCX);
// Set Printer options
SetFileNameOptions(DOCX, NoPrompt);
// The EnablePrinter() method needs to be called right before each print job.
// Calling the EnablePrinter() method will start a 20 second time-out value
EnablePrinter(DOCX, strLicenseTo, strActivationCode);
// Set Papersize
SetPaperSize(DOCX, PAPERSIZE::Legal);
// Apply Settings
SetDefaultConfig(DOCX);
// Create Device Context for DOCX printer
HDC printerDC = CDICreateDC(DOCX);
DOCINFO di;
::ZeroMemory(&di, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = _T("myDocTitle");
di.lpszOutput = _T("c:\\temp\\amyuni.docx");
StartDoc(printerDC, &di);
StartPage(printerDC);
TextOut(printerDC, 0, 200, _T("Hello World"), lstrlen(_T("Hello World")));
TextOut(printerDC, 0, 400, _T("Amyuni Technologies"), lstrlen(_T("Amyuni Technologies")));
EndPage(printerDC);
EndDoc(printerDC);
DeleteDC(printerDC);
// The RestoreDefaultPrinter function resets the system default printer
// to the printer that was the default before the call to SetDefaultPrinter.
RestoreDefaultPrinter(DOCX);
// This function will simply detach from an existing printer because the handle was created using DriverInit
DriverEnd(DOCX);
// Destroy DOCX object
DOCX = NULL;
return 0;
}