本文介绍了将.docx转换为.pdf甲酸盐生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的Windows应用程序中,我想以.docx和.pdf formate生成一些报告.所以首先我生成了.docx并使用下面给出的代码将该.docx文件转换为.pdf在我的系统中运行正常.将.docx转换为.pdf时产生错误.代码在这里

Hi,
In my windows application i want to generate some report, in .docx and .pdf formate. so first i have generated .docx and the converting this .docx file in .pdf using the code given below.it is working fine in my system.but after making the setup file and running on other system on which visual studio is not avialable it creating error whlie converting .docx to .pdf. code is here

for (int i = 0; i < count; i++)
{
  object paramSourceDocPath = @txt_desination.Text + "\\" + client_name[i].Trim() + invoice_date[i] + ".docx";
  object paramMissing = Type.Missing;

  ApplicationClass wordApplication = new ApplicationClass();
  Document wordDocument = null;

  //Change the path of the .pdf file and filename to your file name.
  string paramExportFilePath = @txt_desination.Text + "\\" + client_name[i].Trim() + invoice_date[i] + ".pdf";
  WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
  bool paramOpenAfterExport = false;
  WdExportOptimizeFor paramExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
  WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
  int paramStartPage = 0;
  int paramEndPage = 0;
  WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
  bool paramIncludeDocProps = true;
  bool paramKeepIRM = true;
  WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
  bool paramDocStructureTags = true;
  bool paramBitmapMissingFonts = true;
  bool paramUseISO19005_1 = false;
  try
  {
    // Open the source document.
    wordDocument = wordApplication.Documents.Open(
    ref paramSourceDocPath, ref paramMissing, ref paramMissing,
    ref paramMissing, ref paramMissing, ref paramMissing,
    ref paramMissing, ref paramMissing, ref paramMissing,
    ref paramMissing, ref paramMissing, ref paramMissing,
    ref paramMissing, ref paramMissing, ref paramMissing,
    ref paramMissing);

    // Export it in the specified format.
    if (wordDocument != null)
      wordDocument.ExportAsFixedFormat(paramExportFilePath,
                                        paramExportFormat, paramOpenAfterExport,
                                        paramExportOptimizeFor, paramExportRange, paramStartPage,
                                        paramEndPage, paramExportItem, paramIncludeDocProps,
                                        paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                                        paramBitmapMissingFonts, paramUseISO19005_1,
                                        ref paramMissing);

  }
  catch (Exception ex)
  {
    // Respond to the error
    MessageBox.Show(ex.Message);
  }
  finally
  {
    // Close and release the Document object.
    if (wordDocument != null)
    {
      wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
      wordDocument = null;
    }

    // Quit Word and release the ApplicationClass object.
    if (wordApplication != null)
    {
      wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
      wordApplication = null;
    }

    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();
    GC.WaitForPendingFinalizers();
  }
//showing error export failed because this feature id not installed
 }

推荐答案



这篇关于将.docx转换为.pdf甲酸盐生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 13:33
查看更多