CreateDC, CDICreateDC

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.

 

Syntax

ActiveX:

OLE_HANDLE CreateDC()

DLL:

HDC CDICreateDC(HANDLE hPrinter)

 

Parameters

hPrinter

Handle to printer returned by any of the DriverInit function calls.

 

Return Value

The return value is a printer device context (hDC) if the function succeeds, NULL otherwise.

 

Member of CDIntfEx.CDIntfEx.

 

Example

// PDF 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,

    A3 = 8,

    CustomSize = 256

};

 

int main()

{

     // Constants for Activation codes

    #define strLicenseTo  "Amyuni PDF Converter Evaluation"

    #define strActivationCode "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

    #define AMYUNIPRINTERNAME "Amyuni PDF 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 PDF = DriverInit(AMYUNIPRINTERNAME);

 

    // The CDISetDefaultPrinter function sets the system default printer to the one

    // initialized by the DriverInit functions.

    CDISetDefaultPrinter(PDF);

 

    // The EnablePrinter() method needs to be called right before each print job.

    // and before the configuration

    // Calling the EnablePrinter() method will start a 20 second time-out value

    EnablePrinter(PDF, strLicenseTo, strActivationCode);

 

    // Set Printer options

    SetFileNameOptions(PDF, NoPrompt);

 

    // Set Papersize

    SetPaperSize(PDF, PAPERSIZE::Legal);

 

    // Apply Settings

    SetDefaultConfig(PDF);

 

    // Create Device Context for PDF printer

    HDC printerDC = CDICreateDC (PDF);

 

    DOCINFO di;

    ::ZeroMemory (&di, sizeof(DOCINFO));

    di.cbSize = sizeof(DOCINFO);

 

    di.lpszDocName = _T("myDocTitle");

    di.lpszOutput = _T("c:\\temp\\amyuni.pdf");

 

    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(PDF);

 

    // This function will simply detach from an existing printer because the handle was created using DriverInit

    DriverEnd(PDF);

 

    // Destroy PDF object

    PDF = nullptr;    

 

    return 0;

}