将.docx转换为.pdf甲酸盐生成 [英] converting .docx to .pdf formate generation

查看:75
本文介绍了将.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
 }

推荐答案

如果它在开发计算机上运行,​​但在另一台计算机上失败,则说明您的设置可能没有应用程序所需的一切.如果您使用任何外部库,请记住将它们包括在您的设置中.
If it''s running on development machine and fail on the other, your setup probably does not have everything your application needs. If you use any external libraries remember to include them in your setup.


您可以使用iTextsharp.dll文件或pd4ml.dll文件.
iTextsharp是一个开源.
you can use iTextsharp.dll file OR pd4ml.dll file.
iTextsharp is a opensource.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆