crazyvonzipper 0 Newbie Poster

HI

i am trying to convert a doc file to a pdf file.

please see my conversion code below

private string m_SourceFilePath;
private string m_DestFilePath;

public bool DoConversion()
{

bool returnValue;


Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF;

object paramMissing = Type.Missing;
Word.ApplicationClass wordApplication = new Word.ApplicationClass();
Word.Document wordDocument = null;

try
{

object paramSourceDocPath = m_SourceFilePath;
string paramExportFilePath = m_DestFilePath;
Word.WdExportFormat paramExportFormat = exportFormat;
bool paramOpenAfterExport = false;

Word.WdExportOptimizeFor paramExportOptimizeFor =
Word.WdExportOptimizeFor.wdExportOptimizeForPrint;

Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
int paramStartPage = 0;
int paramEndPage = 0;
Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
Word.WdExportCreateBookmarks paramCreateBookmarks =
Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false;

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);

if (wordDocument != null)
{
wordDocument.ExportAsFixedFormat(paramExportFilePath, paramExportFormat, paramOpenAfterExport, paramExportOptimizeFor, paramExportRange, paramStartPage, paramEndPage, paramExportItem, paramIncludeDocProps, paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing);

// Set the result as true
returnValue = true;

}

}
catch (Exception E)
{

// The conversion failed
returnValue = false;  

}
finally
{

if (wordDocument != null)
{

wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); wordDocument = null;

}
if (wordApplication != null)
{

wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing); wordApplication = null;

}

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();

}

// Return the result
return returnValue;

}

this code works perfectly on my local machine ( running windows vista home premium ) with VS 2008 SP2, however, once we deploy the ASP.NET web application on our windows server 2003 standard edition, the conversion just hangs

- We DO have miscrosoft office small business 2007 installed on the server ( with a 60 day trial license for now )

- The WORD (.doc) document is generated using ASPOSE WORDS and saves all merge fields correctly, this doc must then be made .pdf

- we do not have ASPOSE PDF

- At first we received an error stating that there were no permission to access the COM object, we then proceeded to add the required permissions, and now it just basically hangs.

- in the back end i can see that the document is being generated properly, and then the temp document thumb appears as in to say that the document is open, but the thumb is only 1b and then the application hangs.

The code that runs the process is listed below:

// Reset output frame
frameoutput.Attributes["src"] = "#";

// Set the case document path
string m_docPath = MapPath("~/xxxxxxx");

// Create the temp path folder for the generated documents
string m_tempPath = MapPath(string.Format("~/Temp/{0}", DateTime.Now.ToString("yyyyMMdd")));

// Create the temp path if it does not exist
if (!System.IO.Directory.Exists(m_tempPath))
{ System.IO.Directory.CreateDirectory(m_tempPath); }

// Set the document name
string fname = "xxxxxxxxx.dot";

/*****************************************************************/

// Build document here and return file name, create attachment and add to collection
Document_Policy_Certificate doc = new Document_Policy_Certificate(m_docPath, m_tempPath, fname, PolicyId, BookingId, true);

string url = "";

lock (doc)
{ url = doc.BuildDocument(); }

MicrosoftOfficePdfConverter converter = new MicrosoftOfficePdfConverter(Server.MapPath(url), Server.MapPath(url.Replace(".doc", ".pdf")));

lock (converter)
{ converter.DoConversion(); }

Response.Redirect(url.Replace(".doc", ".pdf"));

}

and the code to generate the DOC file is listed below

namespace xxxxxxxxxx
{

public class Document_xxxxxx_xxxxxxxxxxx
{

private string m_docPath;
private string m_tempPath;
private string m_fileName;
private string m_PolicyId;
private string m_BookingId;
private bool m_outputToBrowser;

public Document_Policy_Certificate(string docPath, string tempPath, string fileName, string PolicyId, string BookingId, bool OutputToBrowser)
{

this.m_docPath = docPath;
this.m_tempPath = tempPath;
this.m_fileName = fileName;
this.m_PolicyId = PolicyId;
this.m_BookingId = BookingId;
this.m_outputToBrowser = OutputToBrowser;

}

public string BuildDocument()
{

// Handler that handles all our database calls
DbWebHandler handler = new DbWebHandler(ConfigurationManager.ConnectionStrings["xxxx"].ToString());

// Generate the SQL Query to retrieve values
string sql = string.Format("EXEC xxx_xxxxx_xxxx_xxxxxx_xxxxxxxxxxx '{0}', '{1}'", this.m_PolicyId, this.m_BookingId);

// Retrieve values into a dataset object via the handle
DataSet ds = handler.GetDataSet(sql);

if (ds != null && ds.Tables[0].Rows.Count > 0)
{

// Build the document
Aspose.Words.Document doc = new Document(Path.Combine(this.m_docPath, this.m_fileName));

// Create field array
string[] fields = new string[] 
{

"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx",
"xxx"

};

// Create value array
object[] values = new object[] 
{

ds.Tables[0].Rows[0][0].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][1].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][2].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][3].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][4].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][5].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][6].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][7].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][8].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][9].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][10].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][11].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][12].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][13].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][15].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][16].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][17].ToString().Replace("|", "'"),
ds.Tables[0].Rows[0][18].ToString().Replace("|", "'")

};

// Populate the document with info
doc.MailMerge.Execute(fields, values);

// File attachment name
string fname = Path.GetFileNameWithoutExtension(m_fileName) + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".doc";

// Close the handler
handler.CloseConnection();

// Save the document to the temp folder
doc.Save(Path.Combine(this.m_tempPath, fname), SaveFormat.Doc);

// If not output to browser then return the full path
if (!this.m_outputToBrowser)
{

// Return the path to the file
return Path.Combine(this.m_tempPath, fname);

}
else
{

// Else return the url path to the file
return string.Format("/Temp/{0}", DateTime.Now.ToString("yyyyMMdd")) + @"/" + fname;

}

}
else
{

// Close the handler
handler.CloseConnection();

// Return empty string
return "";

}

}

}

}

Any advise would be greatly appreciated, maybe someone can explain to me why this is happening, my bets are that it might be either the the trial license on MS Office Small
Regards,

CVZ ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.