views:

87

answers:

1

Hello,

I am trying to convert a RTF document to PDF. I have this code:

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

#include <windows.h>
#include <tchar.h>
#include <objbase.h>
#include <atlbase.h>

#import "MSVBVM60.DLL" rename ( "EOF", "VBEOF" ), rename ( "RGB", "VBRGB" ) //if you don't use this you will be in BIG trouble
#import "PDFCreator.exe" 

int _tmain(int argc, _TCHAR* argv[])
{

 CoInitialize(NULL);
 {

  CComPtr<PDFCreator::_clsPDFCreator> pdfObject;
  HRESULT hr = pdfObject.CoCreateInstance(L"PDFCreator.clsPDFCreator");
  pdfObject->cStart("/NoProcessingAtStartup", 1);

  PDFCreator::_clsPDFCreatorOptionsPtr opt = pdfObject->GetcOptions();

  opt->UseAutosave = 1;
  opt->UseAutosaveDirectory = 1;
  opt->AutosaveDirectory = "c:\\temp\\";
  opt->AutosaveFormat = 0; // for PDF
  opt->AutosaveFilename = "gigi13";
  pdfObject->PutRefcOptions(opt);
  pdfObject->cClearCache();
  _bstr_t DefaultPrinter = pdfObject->cDefaultPrinter;
  pdfObject->cDefaultPrinter = "PDFCreator";
  hr = pdfObject->cPrintFile("c:\\temp\\RTF\\garage.rtf");

  pdfObject->cPrinterStop = false;

  while(true)
  {
   printf("sleep\n");
   Sleep(1000);
   if(pdfObject->cCountOfPrintjobs == 0)
    break;
  }

  printf("done\n");

  pdfObject->cPrinterStop = true;

  pdfObject->cDefaultPrinter = DefaultPrinter;
 }

 CoUninitialize();

 return 0;
}

When running this code sample instead of creating directly the PDF it prompts me with a Save dialog offering me the option to the output only with the option of choosing a TIFF file (which is not wanted). Can someone point me into the right direction or offer some suggestions?

Thanks,

Iulian

+2  A: 

This is only a guess... I had a similar problem -- not when using PDFCreator programmatically (this is beyond my capabilities), but when using it as my standard printer to print to PDFs.

First I used it for a couple of days without any problem. Not I had installed it, but my partner. As I said... it just worked, and created beautiful PDFs.

Then, somehow, someone on our home computer (we are 3 different persons using it) must have changed the setting (maybe inadvertedly) to make it output TIFF instead of PDFs. For me, my default printer was named "PDFcreator" and it confused the hell out of me why it suddenly wanted to create TIFFs.

Meanwhile I've poked a lot in the user interface of all its settings, and learned to know where to look if something goes wrong.

The newest version in its lefthand treeview panel lists an item named "Save". If you select it, you can configure default filename conventions as well as "Standard save format". In my case in the dropdown listview there was "TIFF" selected instead of "PDF".

Looking at your code, you are somehow calling PDFCreator.exe (I don't understand the details, but I can see this string in your code). My bet would go towards this: somehow, the user account which your code uses to run under has his Standard save format set to TIFF. It may be that you look at the printer settings (on my Windows XP, I just type control printers, and rightclick the PDFCreator printername to select Properties...) and find nothing suspicious.

However, PDFcreator stores its settings for each user into a different location, probably in %userprofile%\local settings\temp\pdfcreator\..., or even in the registry...

Thanks for the hint, I will look into it.
Iulian Şerbănoiu
I will take this as an answer but unfortunately it does not solve my problem. Thanks again for trying (see my comment at the question).
Iulian Şerbănoiu