How do I use the COM components (XpdfPrint, XpdfRasterizer, XpdfText, etc.) in Visual C++?

Applies to: XpdfInfo, XpdfText, XpdfPrint, XpdfRasterizer, XpdfAnalyze, XpdfPS, XpdfImageExtract

Most of the example code for Glyph & Cog's COM components is in Visual Basic, but using them from C++ is just as easy.

The key thing is to use the #import directive with the no_namespace flag. For example, to call XpdfPrint from C++, the code would look like this:

#import "XpdfPrint.dll" no_namespace int main(int argc, char *argv[]) { // this needs to be called, usually somewhere near the beginning // of your program CoInitialize(NULL); ... printSomething(); ... } void printSomething() { IXpdfPrintPtr pdf; HRESULT hr; if (FAILED(hr = pdf.CreateInstance(__uuidof(XpdfPrint)))) { printf("Failed to create XpdfPrint object: %08x\n", hr); return; } if (FAILED(pdf->loadFile("c:\\file.pdf"))) { printf("loadFile() failed\n"); return; } if (FAILED(pdf->printPDF3(pdf->GetprintSetPrinterFlag(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "printer17", 0, 0))) { printf("printPDF3() failed\n"); return; } }

Similar code can be used with the other COM components.

Note that VC++ uses Get and Set functions to access COM properties. In the example code above, GetprintSetPrinterFlag() is used to read the printSetPrinterFlag property.