private static bool SavePdfToStream(string inputFile, MemoryStream fileStream, MemoryStream documentStream, ref bool isLandscape) { var extension = Path.GetExtension(inputFile); if (string.IsNullOrEmpty(extension)) throw new ArgumentException(inputFile); try { fileStream.Position = 0; switch (extension.ToUpperInvariant()) { case ".DOC": case ".DOCX": case ".RTF": case ".DOT": case ".DOTX": var doc = new Aspose.Words.Document(fileStream); if (doc.PageCount > 0) { var pageInfo = doc.GetPageInfo(0); isLandscape = pageInfo.WidthInPoints > pageInfo.HeightInPoints; } doc.Save(documentStream, Aspose.Words.SaveFormat.Pdf); break; case ".XLS": case ".XLSX": var workbook = new Aspose.Cells.Workbook(fileStream); for (var i = 0; i < workbook.Worksheets.Count; i++) { if (!workbook.Worksheets[i].IsVisible) continue; isLandscape = workbook.Worksheets[i].PageSetup.Orientation == Aspose.Cells.PageOrientationType.Landscape; break; } workbook.Save(documentStream, Aspose.Cells.SaveFormat.Pdf); break; //Microsoft Visio case ".VSD": case ".VSS": case ".VST": case ".VSX": case ".VTX": case ".VDW": case ".VDX": var vsdDiagram = new Aspose.Diagram.Diagram(fileStream); if (vsdDiagram.Pages.Count > 0) isLandscape = vsdDiagram.Pages[0].PageSheet.PrintProps.PrintPageOrientation.Value == Aspose.Diagram.PrintPageOrientationValue.Landscape; vsdDiagram.Save(documentStream, Aspose.Diagram.SaveFileFormat.PDF); break; //Microsoft Project case ".MPP": var project = new Aspose.Tasks.Project(fileStream); project.Save(documentStream, Aspose.Tasks.Saving.SaveFileFormat.PDF); isLandscape = true; break; //PowerPoint case ".PPT": case ".PPS": case ".POT": using (var pres = new Aspose.Slides.Presentation(fileStream)) { isLandscape = pres.SlideSize.Size.Width > pres.SlideSize.Size.Height; pres.Save(documentStream, Aspose.Slides.Export.SaveFormat.Pdf); } break; case ".PPTX": case ".PPSX": case ".POTX": //case ".XPS": using (var presEx = new Aspose.Slides.Presentation(fileStream)) { isLandscape = presEx.SlideSize.Orientation == Aspose.Slides.SlideOrienation.Landscape; presEx.Save(documentStream, Aspose.Slides.Export.SaveFormat.Pdf); } break; case ".PDF": { using (var pdf = new Aspose.Pdf.Document(fileStream)) { var page = pdf.Pages.OfType<Aspose.Pdf.Page>().FirstOrDefault(); if (page != null && page.MediaBox != null) { isLandscape = page.MediaBox.Width > page.MediaBox.Height; } } fileStream.Seek(0, SeekOrigin.Begin); fileStream.CopyTo(documentStream); } break; } } finally { fileStream.Close(); } return true; }
public static void ConvertToPdf(string inputFilePath, string outputFilePath) { var extension = Path.GetExtension(inputFilePath); if (extension == null) { return; } switch (extension.ToUpperInvariant()) { case ".DOC": case ".DOCX": case ".RTF": case ".DOT": case ".DOTX": var doc = new Document(inputFilePath); doc.Save(outputFilePath, Aspose.Words.SaveFormat.Pdf); break; case ".XLS": case ".XLSX": var workbook = new Workbook(inputFilePath); workbook.Save(outputFilePath, Aspose.Cells.SaveFormat.Pdf); break; //Microsoft Visio case ".VSD": case ".VSS": case ".VST": case ".VSX": case ".VTX": case ".VDW": case ".VDX": var diagram = new Diagram(inputFilePath); diagram.Save(outputFilePath, SaveFileFormat.PDF); break; //Microsoft Project case ".MPP": var project = new Aspose.Tasks.Project(inputFilePath); project.Save(outputFilePath, Aspose.Tasks.Saving.SaveFileFormat.PDF); break; //PowerPoint case ".PPT": case ".PPS": case ".POT": using (var pres = new Aspose.Slides.Presentation(inputFilePath)) pres.Save(outputFilePath, Aspose.Slides.Export.SaveFormat.Pdf); break; case ".PPTX": case ".PPSX": case ".POTX": //case ".XPS": using (var presEx = new Aspose.Slides.Presentation(inputFilePath)) presEx.Save(outputFilePath, Aspose.Slides.Export.SaveFormat.Pdf); break; case ".PDF": File.Copy(inputFilePath, outputFilePath); break; } }
private void button1_Click(object sender, RibbonControlEventArgs e) { DateTime currentdate = System.DateTime.Now; #region get path and project info //get active project and path MSPROJECT.Project project1 = Globals.ThisAddIn.Application.ActiveProject; string projectpath = project1.Path.ToString(); projectname = project1.Name.ToString(); string datadir = projectpath; bool baseline_ = false; //project1.SaveAs(datadir + "\\" + "temp.mpp"); DialogResult result = MessageBox.Show("All Projects Will Be Saved and Closed. Proceed?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); try { if (result == DialogResult.Yes) { Globals.ThisAddIn.Application.FileCloseAllEx(MSPROJECT.PjSaveType.pjSave); Aspose.Tasks.Project prj = new Aspose.Tasks.Project(datadir + "\\" + projectname); // Declare ChildTasksCollector class object ChildTasksCollector collector = new ChildTasksCollector(); // Use TaskUtils to get all children tasks in RootTask TaskUtils.Apply(prj.RootTask, collector, 0); //create entity SchedulingEntities db = new SchedulingEntities(); Schedule_Actual actual = new Schedule_Actual(); Schedule_Baseline baseline = new Schedule_Baseline(); #region view all tasks DialogResult baselineresult = MessageBox.Show("Create/Update Baseline?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (baselineresult == DialogResult.Yes) { baseline_ = true; } else { } foreach (Task tsk2 in collector.Tasks) { Calendar tskCal = tsk2.Get(Tsk.Calendar); string taskinfo = tsk2.ToString(); int id1 = tsk2.Get(Tsk.Id); if (id1 == 0) { string jobnumber = tsk2.Get(Tsk.Name); actual.job = jobnumber; actual.createdate = currentdate; if (baseline_ == true) { baseline.job = jobnumber; baseline.createdate = currentdate; } } if (tsk2.Get(Tsk.Name) == "Design") { DateTime designStart = tsk2.Get(Tsk.Start); DateTime designEnd = tsk2.Get(Tsk.Finish); actual.designend = designEnd; actual.designstart = designStart; if (baseline_ == true) { baseline.designstart = designStart; baseline.designend = designEnd; } } if (tsk2.Get(Tsk.Name) == "Processing") { DateTime processingStart = tsk2.Get(Tsk.Start); DateTime processingEnd = tsk2.Get(Tsk.Finish); actual.processingend = processingEnd; actual.processingstart = processingStart; if (baseline_ == true) { baseline.processingend = processingEnd; baseline.processingstart = processingStart; } } if (tsk2.Get(Tsk.Name) == "Weld Fab") { DateTime weldStart = tsk2.Get(Tsk.Start); DateTime weldEnd = tsk2.Get(Tsk.Finish); actual.weldstart = weldStart; actual.weldend = weldEnd; if (baseline_ == true) { baseline.weldstart = weldStart; baseline.weldend = weldEnd; } } if (tsk2.Get(Tsk.Name) == "Machine") { DateTime machineStart = tsk2.Get(Tsk.Start); DateTime machineEnd = tsk2.Get(Tsk.Finish); actual.machineend = machineEnd; actual.machinestart = machineStart; if (baseline_ == true) { baseline.machineend = machineEnd; baseline.machinestart = machineStart; } } if (tsk2.Get(Tsk.Name) == "Assembly") { DateTime assemblyStart = tsk2.Get(Tsk.Start); DateTime assemblyEnd = tsk2.Get(Tsk.Finish); actual.assemblystart = assemblyStart; actual.assemblyend = assemblyEnd; if (baseline_ == true) { baseline.assemblyend = assemblyEnd; baseline.assemblystart = assemblyStart; } } if (tsk2.Get(Tsk.Name) == "QA BUY OFF") { DateTime qaStart = tsk2.Get(Tsk.Start); DateTime qaEnd = tsk2.Get(Tsk.Finish); actual.qastart = qaStart; actual.qaend = qaEnd; if (baseline_ == true) { baseline.qaend = qaEnd; baseline.qastart = qaStart; } } if (tsk2.Get(Tsk.Name) == "Material") { DateTime matStart = tsk2.Get(Tsk.Start); DateTime matEnd = tsk2.Get(Tsk.Finish); actual.materialstart = matStart; actual.materialend = matEnd; if (baseline_ == true) { baseline.materialstart = matStart; baseline.materialend = matEnd; } } } db.Schedule_Actual.Add(actual); if (baseline_ == true) { db.Schedule_Baseline.Add(baseline); } db.SaveChanges(); SaveOptions saveOptions = new PdfSaveOptions(); saveOptions.PageSize = PageSize.Ledger; saveOptions.SaveFormat.Equals(SaveFileFormat.PDF); saveOptions.FitContent = true; saveOptions.Timescale = Timescale.ThirdsOfMonths; saveOptions.PresentationFormat = PresentationFormat.GanttChart; saveOptions.LegendOnEachPage = false; projectname = projectname.Replace("-", "_"); string filename = "R:\\wipviewer2017\\prjfiles\\" + projectname + ".pdf"; prj.Save(filename, saveOptions); email_team(filename); PdfPageEditor pEdit = new PdfPageEditor(); } #endregion else if (result == DialogResult.No) { // DO NOTHING } } catch (Exception ee) { MessageBox.Show(ee.ToString()); } #endregion }