// Creating graphic control from an image file // public BSkyGraphicControl CreateBSkyGraphicControl(string fullpathimgfilename)//11Sep2012 { BSkyGraphicControl bsgc = new BSkyGraphicControl(); bsgc.ControlType = "Graphic"; if (!File.Exists(fullpathimgfilename)) { fullpathimgfilename = "../libs/BlueSky/Images/ImgErr.png";//@".\Images\ImgErr.png"; //return bsgc; if (!File.Exists(fullpathimgfilename)) { return(bsgc); } } //Setting image source// Image myImage = new Image(); var bitmap = new BitmapImage(); var stream = File.OpenRead(fullpathimgfilename); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.StreamSource = stream; bitmap.EndInit(); stream.Close(); stream.Dispose(); myImage.Source = bitmap; bsgc.BSkyImageSource = myImage.Source; return(bsgc); }
private static void BSkyGraphicControlToImageFile(BSkyGraphicControl bsgc, string fullpathimgfilename) { System.Windows.Controls.Image myImage = new System.Windows.Controls.Image(); myImage.Source = bsgc.BSkyImageSource; System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage(); bitmapImage = ((System.Windows.Media.Imaging.BitmapImage)myImage.Source); System.Windows.Media.Imaging.PngBitmapEncoder pngBitmapEncoder = new System.Windows.Media.Imaging.PngBitmapEncoder(); System.IO.FileStream stream = new System.IO.FileStream(fullpathimgfilename, FileMode.Create); pngBitmapEncoder.Interlace = PngInterlaceOption.On; pngBitmapEncoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapImage)); pngBitmapEncoder.Save(stream); stream.Flush(); stream.Close(); }
private void mypanel_ContextMenuClosing(object sender, ContextMenuEventArgs e) { bool deleteControl = false; FrameworkElement fe = e.Source as FrameworkElement; #region find control type AUParagraph aup = fe as AUParagraph; if (aup != null) { deleteControl = aup.DeleteControl; } BSkyNotes bsn = fe as BSkyNotes; if (bsn != null) { deleteControl = bsn.DeleteControl; } BSkyGraphicControl bsgc = fe as BSkyGraphicControl; if (bsgc != null) { deleteControl = bsgc.DeleteControl; } AUXGrid auxg = fe as AUXGrid; if (auxg != null) { deleteControl = auxg.DeleteControl; } #endregion if (deleteControl) { MessageBox.Show("Delete is not allowed in the Output Viewer"); } }
private void createDiskFileFromImageSource(BSkyGraphicControl bsgc) { Image myImage = new System.Windows.Controls.Image(); myImage.Source = bsgc.BSkyImageSource; string grpctrlimg = Path.Combine(System.IO.Path.GetTempPath().Replace("\\", "/"), confService.GetConfigValueForKey("bskygrphcntrlimage"));//23nov2012 // load default value if no path is set or invalid path is set if (grpctrlimg.Trim().Length == 0 || !IsValidFullPathFilename(grpctrlimg, false)) { MessageBox.Show(this, "Key 'bskygrphcntrlimage' not found in config file. Aborting..."); return; } System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage(); bitmapImage = ((System.Windows.Media.Imaging.BitmapImage)myImage.Source); System.Windows.Media.Imaging.PngBitmapEncoder pngBitmapEncoder = new System.Windows.Media.Imaging.PngBitmapEncoder(); System.IO.FileStream stream = new System.IO.FileStream(@grpctrlimg, FileMode.Create); pngBitmapEncoder.Interlace = PngInterlaceOption.On; pngBitmapEncoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapImage)); pngBitmapEncoder.Save(stream); stream.Flush(); stream.Close(); }
private void createBSkyGraphic(Image img, CommandOutput lst)//30Aug2012 { lst.NameOfAnalysis = "R-Graphics"; BSkyGraphicControl bsgc = new BSkyGraphicControl(); bsgc.BSkyImageSource = img.Source; bsgc.ControlType = "Graphic"; lst.Add(bsgc); }
private static void ExportOutputPDF(CommandOutput output, MigraDoc.DocumentObjectModel.Document Doc, bool extratags, List <string> filelist, bool issessionout = false)//csv of excel { if (output.NameOfAnalysis == null) { output.NameOfAnalysis = string.Empty; } foreach (DependencyObject obj in output) { FrameworkElement element = obj as FrameworkElement; //31Aug2012 AUXGrid xgrid = element as AUXGrid; if ((element as AUParagraph) != null) { AUParagraph aup = element as AUParagraph; if (!aup.IsVisible) { continue; } if (aup.Text != null) ///// <aup> means AUParagraph { MigraDoc.DocumentObjectModel.Paragraph PDFpara = BSky.ExportToPDF.ExportAUParagraph.ExportFormattedText(aup.Text, aup.FontWeight, aup.FontSize, aup.textcolor, aup.FontStyle); //aup.ExportPDFParagraph(); PDFpara.AddLineBreak(); Doc.LastSection.Add(PDFpara.Clone()); } } else if ((element as AUXGrid) != null) { AUXGrid xgrid = element as AUXGrid; //31Aug2012 if (!xgrid.IsVisible) { continue; } ////////// Printing Header ////////// <fgheader> means flexgrid header string header = xgrid.Header.Text; AUParagraph FGTitle = new AUParagraph(); FGTitle.Text = header; FGTitle.FontWeight = FontWeights.SemiBold; if (APAStyle) { FGTitle.FontStyle = FontStyles.Italic; } //FGTitle.textcolor = MigraDoc.DocumentObjectModel.Paragraph PDFpara = BSky.ExportToPDF.ExportAUParagraph.ExportFormattedText(FGTitle.Text, FGTitle.FontWeight, FGTitle.FontSize, FGTitle.textcolor, FGTitle.FontStyle); //FGTitle.ExportPDFParagraph(); PDFpara.AddLineBreak(); Doc.LastSection.Add(PDFpara.Clone()); //////////////// Printing Errors /////////// if (xgrid.Metadata != null)//// <errhd> means error heading { // Error/Warning Title AUParagraph ErrWarnTitle = new AUParagraph(); ErrWarnTitle.Text = "Errors/Warnings: ";; ErrWarnTitle.FontWeight = FontWeights.SemiBold; //ErrWarnTitle.FontStyle = FontStyles.Normal; //ErrWarnTitle.textcolor = MigraDoc.DocumentObjectModel.Paragraph PDFparaErrWarnTitle = BSky.ExportToPDF.ExportAUParagraph.ExportFormattedText(ErrWarnTitle.Text, ErrWarnTitle.FontWeight, ErrWarnTitle.FontSize, ErrWarnTitle.textcolor, ErrWarnTitle.FontStyle); //ErrWarnTitle.ExportPDFParagraph(); PDFparaErrWarnTitle.AddLineBreak(); Doc.LastSection.Add(PDFparaErrWarnTitle.Clone()); // Error/Warning Messages AUParagraph ErrWarnMsgPara = null; foreach (KeyValuePair <char, string> keyval in xgrid.Metadata) { ErrWarnMsgPara = new AUParagraph(); ErrWarnMsgPara.Text = keyval.Key.ToString() + ":" + keyval.Value; MigraDoc.DocumentObjectModel.Paragraph PDFparaErrWarnMsg = BSky.ExportToPDF.ExportAUParagraph.ExportFormattedText(ErrWarnMsgPara.Text, ErrWarnMsgPara.FontWeight, ErrWarnMsgPara.FontSize, ErrWarnMsgPara.textcolor, ErrWarnMsgPara.FontStyle); //ErrWarnMsgPara.ExportPDFParagraph(); PDFparaErrWarnMsg.AddLineBreak(); Doc.LastSection.Add(PDFparaErrWarnMsg.Clone()); } } //////// Printing Grid //////////// AUGrid grid = xgrid.Grid; float remainingpagesize = 0.0f;//remaining page height float currentTblHt = 0.0f; float PDFpageHeight = Doc.DefaultPageSetup.PageHeight; BSky.ExportToPDF.ExportAUXGrid.APAStyle = APAStyle; List <MigraDoc.DocumentObjectModel.Tables.Table> TablePortions = BSky.ExportToPDF.ExportAUXGrid.ExportMultiHeaderFlexgridToPDF(PDFpageHeight, grid, strMaxTblCol, strMaxTblRow, strPDFfontsize); //xgrid.ExportMultiHeaderFlexgridToPDF(PDFpageHeight); foreach (MigraDoc.DocumentObjectModel.Tables.Table ptbl in TablePortions) { if (ptbl == null) { continue; } //Add Partial Table ID (so that printouts can be arranged in proper order) if (ptbl.Tag != null) { Doc.LastSection.AddParagraph(ptbl.Tag.ToString()); } //add table part to doc Doc.LastSection.Add(ptbl); Doc.LastSection.AddParagraph().AddLineBreak(); } /////////////////Printing Footer /////////////// string starfootnotes = string.Empty; bool templatedDialog = false; if (templatedDialog) { //I think this works for templated dialogs if (xgrid.FootNotes != null) { // Printing Foonotes Title if (xgrid.FootNotes.Count > 0) { AUParagraph FooterTitle = new AUParagraph(); FooterTitle.Text = "Footnotes: "; //Footnote Title FooterTitle.FontWeight = FontWeights.SemiBold; MigraDoc.DocumentObjectModel.Paragraph PDFparaFooterTitle = BSky.ExportToPDF.ExportAUParagraph.ExportFormattedText(FooterTitle.Text, FooterTitle.FontWeight, FooterTitle.FontSize, FooterTitle.textcolor, FooterTitle.FontStyle); //FooterTitle.ExportPDFParagraph(); PDFparaFooterTitle.AddLineBreak(); Doc.LastSection.Add(PDFparaFooterTitle.Clone()); } AUParagraph footnote = null; foreach (KeyValuePair <char, string> keyval in xgrid.FootNotes) { footnote = new AUParagraph(); footnote.Text = keyval.Key.ToString() + ":" + keyval.Value; MigraDoc.DocumentObjectModel.Paragraph PDFparaFootnotesMsg = BSky.ExportToPDF.ExportAUParagraph.ExportFormattedText(footnote.Text, footnote.FontWeight, footnote.FontSize, footnote.textcolor, footnote.FontStyle); //footnote.ExportPDFParagraph(); PDFparaFootnotesMsg.AddLineBreak(); Doc.LastSection.Add(PDFparaFootnotesMsg.Clone()); } } } else //This works for non-templated dialogs { AUParagraph starfootnote = new AUParagraph(); starfootnote.Text = xgrid.StarFootNotes; starfootnote.FontSize = 9; //table cell text(& R syntax) looks size 12. So I want it to be smaller than other text. MigraDoc.DocumentObjectModel.Paragraph PDFparaStarFooterText = BSky.ExportToPDF.ExportAUParagraph.ExportFormattedText(starfootnote.Text, starfootnote.FontWeight, starfootnote.FontSize, starfootnote.textcolor, starfootnote.FontStyle); //FooterTitle.ExportPDFParagraph(); PDFparaStarFooterText.AddLineBreak(); Doc.LastSection.Add(PDFparaStarFooterText.Clone()); } } else if ((element as BSkyGraphicControl) != null)//Graphics 31Aug2012 { BSkyGraphicControl bsgc = element as BSkyGraphicControl; //To only Export Graphics those are visible (checked in the left navigation tree, in output window) if (!bsgc.IsVisible) { continue; } //Create image filename string imgfilename = "PDF" + bsgc.ImageName + ".png"; string synedtimg = Path.Combine(tempDir, imgfilename); //Saving Image separately BSkyGraphicControlToImageFile(bsgc, synedtimg); //not imgfilename MigraDoc.DocumentObjectModel.Paragraph imgPara = BSky.ExportToPDF.ExportGraphics.ExportToPDF(synedtimg); //bsgc.ExportToPDF(synedtimg);// not imgfilename //finally add image to the PDF doc. Doc.LastSection.Add(imgPara); } else if ((element as BSkyNotes) != null) // Notes Control 05Nov2012. { BSkyNotes bsn = element as BSkyNotes; //To only Export Notes those are visible (checked in the left navigation tree, in output window) if (!bsn.IsVisible) { continue; } //Put a title AUParagraph NotesTitle = new AUParagraph(); NotesTitle.Text = "Notes"; //Footnote Title NotesTitle.FontWeight = FontWeights.SemiBold; MigraDoc.DocumentObjectModel.Paragraph PDFparaNotesTitle = BSky.ExportToPDF.ExportAUParagraph.ExportFormattedText(NotesTitle.Text, NotesTitle.FontWeight, NotesTitle.FontSize, NotesTitle.textcolor, NotesTitle.FontStyle); //NotesTitle.ExportPDFParagraph(); PDFparaNotesTitle.AddLineBreak(); Doc.LastSection.Add(PDFparaNotesTitle.Clone()); //Now Notes data in PdfPTable MigraDoc.DocumentObjectModel.Tables.Table notestable = BSky.ExportToPDF.ExportNotes.ExportToPDF(bsn.NotesData, strPDFfontsize);// bsn.ExportToPDF(); Doc.LastSection.Add(notestable); Doc.LastSection.AddParagraph().AddLineBreak(); } } ////for export to excel////E }