代码之家  ›  专栏  ›  技术社区  ›  Gareth

PDF创建器将打印TIFF而不是PDF

  •  0
  • Gareth  · 技术社区  · 6 年前

    我正在尝试将RTF文档转换为PDF。我有这个代码:

    // 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;
    }
    

    当运行此代码示例而不是直接创建PDF时,它会用一个“保存”对话框提示我,该对话框只提供选择TIFF文件(不需要)的输出选项。有人能给我指出正确的方向或提出一些建议吗?

    谢谢,

    尤利安

    1 回复  |  直到 14 年前
        1
  •  3
  •   simplybest55    14 年前

    这只是猜测…我也遇到了类似的问题——不是以编程方式使用pdfcreator(这超出了我的能力),而是使用它作为标准打印机打印到pdfs。

    首先,我用了几天没有任何问题。不是我安装的,而是我的搭档。正如我所说的…它刚刚成功,创造了漂亮的PDF。

    然后,不知何故,我们家电脑上的某个人(我们是3个使用它的不同的人)一定改变了设置(可能是无意的),使它输出TIFF而不是PDF。对于我来说,我的默认打印机名为“pdfcreator”,它把我搞糊涂了,为什么它突然想要创建tiff。

    同时,我在所有设置的用户界面中都进行了大量的浏览,并学会了如何查看出错的地方。

    最新版本的左侧树视图面板列出了一个名为“保存”的项。如果选择它,则可以配置默认的文件名约定以及 “标准保存格式 “。在我的下拉列表视图中,选择了“tiff”而不是“pdf”。

    看看你的代码,你不知何故打电话来 PDFCreator.exe (我不理解细节,但我可以在代码中看到这个字符串)。我的赌注是这样的:不知何故,您的代码运行所使用的用户帐户 标准保存格式 设置为TIFF。可能是您查看打印机设置(在我的Windows XP上,我只需键入 control printers ,然后右键单击pdfcreator printername以选择 属性… )没有任何可疑之处。

    但是,pdfcreator将每个用户的设置存储到不同的位置,可能在 %userprofile%\local settings\temp\pdfcreator\... 或者甚至在注册表中…