/// <summary> /// Add PowerPoint presentations to the conversion queue /// </summary> /// <param name="files">Path to files to be added</param> /// <returns></returns> private async Task AddFilesAsync(string[] files) { if (firstAdd) // remove "drag & drop" placeholder { listboxFiles.Items.Clear(); firstAdd = false; } // add presentations foreach (string s in files) { OfficeFileInfo file = null; await Task.Run(() => { try { if (s.Contains(".ppt")) { file = new PptInfo(s); } else if (s.Contains(".doc")) { file = new DocInfo(s); } } catch (PathTooLongException ex) { ex.Data.Add("Path", s); throw; } catch (UnauthorizedAccessException ex) { ex.Data.Add("Path", s); throw; } }); if (file != null) { listboxFiles.Items.Add(file); } } // create path to default output folder if (listboxFiles.Items.Count > 0) // were files added? // if not use default { string path = Path.GetDirectoryName((listboxFiles.Items[0] as OfficeFileInfo).Path); string dest = Path.Combine(new[] { path, "PDF-Conversions" }); txtDestDir.Text = dest; // show listbox file count lblProgress.Content = string.Format("{0} documents(s).", listboxFiles.Items.Count); } }
/// <summary> /// Converts ppts to PDF documents asynchronously /// </summary> /// <param name="ppApp">The PowerPoint application</param> /// <param name="info">A PptInfo object of the file to be converted to pdf</param> /// <param name="newPath">Full path of the converted file</param> private Task ppConvertAsync(PP.Application ppApp, PptInfo info, string destDir) { return(Task.Run(() => { // open presentation in PP in the bg PP.Presentation pres = ppApp.Presentations.Open(info.Path, WithWindow: Microsoft.Office.Core.MsoTriState.msoFalse); // build path for converted file string newPath = Path.Combine(new[] { destDir, Path.ChangeExtension(Path.GetFileName(info.Path), "pdf") }); // convert to pdf pres.SaveAs(newPath, PP.PpSaveAsFileType.ppSaveAsPDF); pres.Close(); Util.ReleaseComObject(pres); })); }