#include "StdAfx.h"
#include "PdfCreator.h"
#import "PDFCreatorPilot2.DLL"
using namespace PDFCreatorPilot2;


CPdfCreator::CPdfCreator()
{
	//PDFCreatorPilot2::piPDFDocument* PDF = NULL;
	PDFCreatorPilot2::IpiPDFDocument2* PDF = NULL;
	// declare PDF Creator Pilot object
	//IpiPDFDocument* PDF = NULL;
	CLSID clsid;

	// get inuque ID for PDF Creator Pilot
	HRESULT hr = CLSIDFromProgID(OLESTR("PDFCreatorPilot2.piPDFDocument"), &clsid);

	//// check for errors
	//if (FAILED(hr)) {
	//	MessageBox(0,"Can't get CLSID for PDF Creator Pilot","error",MB_OK);
	//	goto Uninit;
	//};

	// create PDF Creator Pilot object
	hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL,__uuidof(IpiPDFDocument2), (LPVOID*)&PDF);

	//// check for errors
	//if (FAILED(hr)) {
	//	MessageBox(0,"Can't create PDF Creator Pilot object","error",MB_OK);
	//	goto Uninit;
	//};

	// initialize PDF Engine
	
	PDF->StartEngine("demo","demo");

	// set PDF ouput filename
	PDF->FileName = "HelloPDF_VC.PDF";
	PDF->AutoLaunch = true; // auto-open generated pdf document

	// start document generation 
	PDF->BeginDoc();

	// draw "HELLO, PDF" message on the current PDF page
	// set active font name, parameters, size and charset
	PDF->PDFPAGE_SetActiveFont("Verdana", true, false, false, false, 14, charsetANSI_CHARSET);

	// draw text
	PDF->PDFPAGE_TextOut(10, 20, 0, "HELLO, PDF!");

	// finalize document generation
	PDF->EndDoc();

	// disconnect from library
	PDF->Release();
}

CPdfCreator::~CPdfCreator()
{
}
