Click here to Skip to main content
15,918,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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
 }
Posted
Updated 28-Mar-12 0:48am
v3

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.
 
Share this answer
 
you can use iTextsharp.dll file OR pd4ml.dll file.
iTextsharp is a opensource.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900