Two Pilots™    Home  |  Navigation  |  Site Map  |  Products  |  Download  |  Prices  |  For Partners  |  Support

All forums · Statistics · Search ·

Two Pilots forum / For software developers / database to be connected to pdf using vc++
Author Message
# Posted: 23 Nov 2005 13:22 · Edited by: Admin


i have created a program in vc++ that will connect to mysql
my problem is to display the datatabse table in acrabat reader
how can i do that

my code is as follows

// pdf.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "sqlext.h"
#include "string.h"
#include "iostream"

#import "PDFCreatorPilot2.DLL"
using namespace PDFCreatorPilot2;

int main(int argc, char* argv[])


HRESULT hr = CoInitialize(NULL);
HENV hEnv = NULL; // Env Handle from SQLAllocEnv()
HDBC hDBC = NULL; // Connection handle
HSTMT hStmt = NULL;// Statement handle
UCHAR szDSN[SQL_MAX_DSN_LENGTH] = "test";// Data Source Name buffer
UCHAR *szUID=NULL;// User ID buffer
UCHAR *szPasswd=NULL;// Password buffer
UCHAR szModel[128];// Model buffer
SDWORD cbModel;// Model buffer bytes recieved
char buff[9] = "Testing";
UCHAR szSqlStr[128]= "INSERT INTO test (name) VALUES('goahead')" ;

RETCODE retcode;

SQLAllocEnv (&hEnv);

// Allocate memory for the connection handle
SQLAllocConnect (hEnv, &hDBC);

// Connect to the data source "test" using userid and password.
retcode = SQLConnect (hDBC, szDSN, SQL_NTS,szUID, SQL_NTS, szPasswd, SQL_NTS);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
// Allocate memory for the statement handle
retcode = SQLAllocStmt (hDBC, &hStmt);

// Prepare the SQL statement by assigning it to the statement handle
retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));

// Execute the SQL statement handle
retcode = SQLExecute (hStmt);

// Project only column 1 which is the models
SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel), &cbModel);

// Get row of data from the result set defined above in the statement
retcode = SQLFetch (hStmt);

// check for errors
if (FAILED(hr)) {
MessageBox(0,"OLE initialization errp","error",MB_OK);
return -1;

// declare PDF Creator Pilot object
IpiPDFDocument2* PDF = NULL;
CLSID clsid;

// get inuque ID for PDF Creator Pilot
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

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

// start document generation

// 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 world you are near to completeion");

// finalize document generation

// disconnect from library

// uninitialize OLE libraries

// Free the allocated statement handle
SQLFreeStmt (hStmt, SQL_DROP);

// Disconnect from datasource
SQLDisconnect (hDBC);

// Free the allocated connection handle
SQLFreeConnect (hDBC);

// Free the allocated ODBC environment handle
SQLFreeEnv (hEnv);

printf("Hello World!\n");
return 0;

Insted of text i want my database table content to display
plz help
its urgent

# Posted: 23 Nov 2005 14:27

Dear Ramneek,

I can recommend you to use our HTML2PDF Add-On. You can prepare HTML template,
fill it with data and convert to PDF. It is much easier than manually draw tables.

Thank you very much !

Best regards,
Two Pilots



Powered by miniBB 2.0 RC7 © 2001-2004 Page creation time (sec.): 0.012


Page top