/// <summary> /// Convert word document into PDF file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void btnConvert_Click(object sender, EventArgs e) { try { //PDFConverter conv = new PDFConverter(); PDFConverterHelper conv = new PDFConverterHelper(""); if (conv.isDocIDValidated(listItemId, list) == true) { if (conv.PDFConvertJob(srcFileName, trgFileName) == true) { lblStatus.Text = "PDF conversion has started. Please wait while the document is in the queue for conversion...";// + conv.PDFConvertJob(srcFileName, trgFileName).ToString(); } else { lblStatus.Text = "PDF conversion has failed."; } } else { lblStatus.Text = "Please select a valid word document (*.doc or *.docx) file type!"; } conv = null; } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ClassName, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "Convert_Click-" + ex.Message, ex.StackTrace); } }
/// <summary> /// Convert selected multiple word documents into PDF files /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void btnConvert_Click(object sender, EventArgs e) { try { PDFConverterHelper conv = new PDFConverterHelper(""); StringBuilder sb = new StringBuilder(""); int numConvertedPDF = 0; for (int index = 0; index <= selectedItems.Length - 1; index++) { if (selectedItems[index].Length > 0) { SPListItem listItem = selectedDocumentLibrary.GetItemById(int.Parse(selectedItems[index])); //Get each selected document item if (conv.isDocIDValidated(listItem.ID.ToString(), selectedDocumentLibrary) == true) { conv.ConvertDocToPDF(listItem); numConvertedPDF = numConvertedPDF + 1; } else { sb.Append("Invalid Word document file type (*.doc or *.docx) for: " + listItem.File.ToString() + "<br>"); } } } if (numConvertedPDF > 0) { if (numConvertedPDF > 1) { lblStatus.Text = sb.ToString() + "<br>PDF conversion has started. Please wait while " + numConvertedPDF + " documents are in the job queue for conversion..."; } else { lblStatus.Text = sb.ToString() + "<br>PDF conversion has started. Please wait while " + numConvertedPDF + " document is in the job queue for conversion..."; } } else { lblStatus.Text = sb.ToString(); } conv = null; } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ClassName, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "btnConvert_Click-" + ex.Message, ex.StackTrace); } }