USE PDFCREATE TO CREATE A PDF FILE
来源:http://www.pdfforge.org/files/old_forum/1002.html
a working sample with C++ & COM
2007-08-15 22:56:18 by eckart
hi,
here is a working sample of how to use PDFCreator in Visual C++ (after searching on internet for something similar I guess this is the only sample)
This sample is reading c:\2.txt file and output to c:\pdf\2.pdf
1. you need to #import 1
#import "C:\WINDOWS\system32\MSVBVM60.DLL" rename ( "EOF", "VBEOF" ), rename ( "RGB", "VBRGB" ) //if you don't use this you will be in BIG trouble
#import "C:\Program Files\PDFCreator\PDFCreator.exe"
2. start your PDF engine
::CoInitialize(NULL);
CComPtr<pdfcreator::_clspdfcreator> pdfObject;
HRESULT hr = pdfObject.CoCreateInstance(L"PDFCreator.clsPDFCreator");
if (!FAILED(hr))
{
if (pdfObject->cStart(L"/NoProcessingAtStartup", FALSE)==FALSE)
{
AfxMessageBox("can't start printer");
return;
};
PDFCreator::_clsPDFCreatorOptionsPtr opt= pdfObject->GetcOptions();
opt->PutUseAutosave(1);
opt->PutUseAutosaveDirectory(1);
opt->PutAutosaveDirectory(L"c:\\pdf\\"); //here you put your output folder
opt->PutAutosaveFormat(0); //0 for PDF
opt->PutAutosaveFilename(L"2.pdf"); //pdf output file name
pdfObject->PutRefcOptions(opt);
pdfObject->PutcDefaultPrinter(L"PDFCreator"); //use PDFCreator printer from ControlPanel->Printers
pdfObject->cClearCache();
//pdfObject->cSaveOptions(L"1");
pdfObject->PutcPrinterStop(VARIANT_FALSE); //let's start with PDFCreator Printer Process Queue ON
pdfObject->cPrintFile(L"c:\\2.txt"); //input of the file that will be translated into PDF format
Sleep(4000); //lets wait for processing, TODO implement __clsPDFCreator_eReadyEventHandler
BSTR fn = pdfObject->GetcOutputFilename(); //if your PDFCreator Printer is OFF you will get nothing ""
AfxMessageBox(CString((const wchar_t*)fn));
pdfObject->cClose();
}
pdfObject.Release();
//--------------------------------
*tada*
if this sample is not working I guess is not my fault ;-)
thanks,
--adi
adrian.paleacu[a]gmail.[0m
2008-12-16 10:56:50 by hwewet
Hi!
This sample works fine, but is it possible to do this
without the #import instructions ???
by the way, i dont want use the *.tlh *.tli files of course!