public void OnSaveClicked(object sender, EventArgs args) { // create flow document and register necessary styles FlowDocument doc = new FlowDocument(); doc.Margin = new Thickness (10,10,10,10); // the style for all document's textblocks doc.StyleManager.RegisterStyle("TextBlock, TextBox", new Style() { Font = new Font("Helvetica",20), Color = RgbColors.Black, Display = Display.Block }); // the style for the section that contains employee data doc.StyleManager.RegisterStyle ("#border", new Style () { Padding = new Thickness(10,10,10,10), BorderColor = RgbColors.DarkRed, Border = new Border(5), BorderRadius=5 } ); // add PDF form fields for later processing doc.Fields.Add (new TextField ("firstName", currentEmployee.FirstName)); doc.Fields.Add (new TextField ("lastName", currentEmployee.LastName)); doc.Fields.Add (new TextField ("position", currentEmployee.CurrentPosition)); // create section and add text block inside Section section = new Section (){Id="border"}; // ios PDF preview doesn't display fields correctly, // uncomment this code to use simple text blocks instead of text boxes // section.Add(new TextBlock(string.Format("First name: {0}",currentEmployee.FirstName))); // section.Add(new TextBlock(string.Format("Last name: {0}",currentEmployee.LastName))); // section.Add(new TextBlock(string.Format("Position: {0}",currentEmployee.CurrentPosition))); section.Add(new TextBlock("First name: ")); section.Add(new TextBox("firstName")); section.Add(new TextBlock("Last name: ")); section.Add(new TextBox("lastName")); section.Add(new TextBlock("Position: ")); section.Add(new TextBox("position")); doc.Add (section); // get io service and generate output file path var fileManager = DependencyService.Get<IFileIO>(); string filePath = Path.Combine (fileManager.GetMyDocumentsPath (), "form.pdf"); // generate document using(Stream outputStream = fileManager.CreateFile(filePath)) { doc.Write (outputStream, new ResourceManager()); } // request preview DependencyService.Get<IPDFPreviewProvider>().TriggerPreview (filePath); }
static FlowDocumentExt() { Default = new FlowDocument(); Default.AddLine(); Default.AddLine("欢迎使用Chrome更新器!"); Default.AddLine(Environment.NewLine); Default.AddLine("本更新器可以查询Chrome安装文件的下载地址,"); Default.AddLine("如果您设置了系统代理,会尝试前往谷歌官方网站查询,如果没有代理则会从耍下的服务器获取。"); Default.AddLine(Environment.NewLine); Default.Add("如果遇到问题可以前往 耍下"); Default.Add("交", new RgbaColor(202, 202, 202, 100)); Default.Add("流 群:"); Default.Add("14724233", "tencent://groupwpa/?subcmd=all\u0026param=7B2267726F757055696E223A31343732343233332C2274696D655374616D70223A313435373135343134397D0A"); Default.Add("进行交流。"); Default.AddLine(Environment.NewLine); Default.Add("本工具发布地址为:"); Default.Add("https://csharp.love/chrome_update_tool.html", "https://csharp.love/chrome_update_tool.html"); }
public void SaveDocument(string path) { using (FileStream outPutStream = GetOutputStream(path)) { try { Section section = new Section(); // //// add some text content TextBlock text = new TextBlock("Hessfjkljsdfsdfsdfsdcześć ty tyłek, przejdźdsfdfsdsfsdff你好你屁股jflksdfljeeeeeeeeehalloxydsfdfsdsfsdffjflksdfljeeeeeeeeehallo"); text.Display = Display.Block; section.Add(text); _pdfDocument.Add(section); _pdfDocument.Write(outPutStream, resourceManager); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(FlowDocumentExt.Default); } var result = (AppUpdate)value; #region dirty hack var vm = (ChromeUpdaterCore)Application.Current.MainWindow.DataContext; var doc = new FlowDocument(); if (!string.IsNullOrEmpty(vm.SelectedPath)) { var canWrite = ChromeUpdaterCore.HasWriteAccess(vm.SelectedPath); if (!canWrite) { doc.AddLine($"提示:程序无权对目录:{vm.SelectedPath} 进行操作,故无法进行一键更新!", FlowDocumentExt.Red); } var chromeExePath = System.IO.Path.Combine(vm.SelectedPath, "chrome.exe"); var canExtract = false; if (System.IO.File.Exists(chromeExePath)) { if (vm.IsX64Selected != vm.CurrentChromeInfo.IsX64) { doc.AddLine($"请注意,您当前选择的架构为{(vm.IsX64Selected ? "x64" : "x86")},但是您本地的Chrome架构为{(vm.CurrentChromeInfo.IsX64 ? "x64" : "x86")}!", FlowDocumentExt.Yellow); canExtract = true; } if (vm.BranchSelected != vm.CurrentChromeInfo.Branch) { doc.AddLine($"请注意,您当前选择的分支为{vm.BranchSelected},但是您本地的Chrome分支为{(vm.CurrentChromeInfo.Branch == null ? "未知" : vm.CurrentChromeInfo.Branch.ToString())}!", FlowDocumentExt.Yellow); canExtract = true; } if (ChromeUpdaterCore.IsBiggerVersion(vm.CurrentChromeInfo.Version, result.version)) { doc.AddLine($"请注意,当前查询到的版本({result.version}/{(vm.IsX64Selected ? "x64" : "x86")}/{vm.BranchSelected})的版本号大于您现有的Chrome版本号({vm.CurrentChromeInfo.Version})!", FlowDocumentExt.Green); canExtract = true; } else { doc.AddLine($"您当前的chrome版本:{vm.CurrentChromeInfo} 是最新的!", FlowDocumentExt.Blue); } } else { if (System.IO.Directory.GetFiles(vm.SelectedPath).Length > 0) { doc.AddLine("请注意,您选择的文件夹不为空并且里面没有找到chrome,请重新选择一个文件夹!", FlowDocumentExt.Yellow); } else { canExtract = true; } } doc.AddLine($"\n查询到的信息({vm.BranchSelected}/{(vm.IsX64Selected ? "x64" : "x86")}):\n", FlowDocumentExt.Blue); doc.Add(result.ToString(), FlowDocumentExt.Blue); if (canWrite && canExtract) { doc.Add(" 下载安装包并解压:", FlowDocumentExt.Blue); doc.AddImage(Arthas.Utility.Media.ResObj.GetImageSource(System.Reflection.Assembly.GetExecutingAssembly(), "Resources.icon-download-e.png"), () => { vm.CmdDownloadAndExtract.Execute(null); }); } } if (ChromeUpdaterCore.Writeable) { doc.Add(" 下载安装包:", FlowDocumentExt.Blue); doc.AddImage(Arthas.Utility.Media.ResObj.GetImageSource(System.Reflection.Assembly.GetExecutingAssembly(), "Resources.icon-download.png"), () => { vm.CmdDownload.Execute(null); }); } doc.AddLine(""); foreach (var s in result.url) { doc.AddLine(s, null, () => { vm.CmdCopyToClipboard.Execute(s); }); } return(doc); #endregion }
public static void Add(this FlowDocument Document, string title, string url) { Document.Add(title, null, () => System.Diagnostics.Process.Start(url)); }
/* * * private string printPdfFile() { * string returnValue = ""; * try * { * String fileName = "Order" + DateTime.Now.ToString("ddMMyyyy"); * // System.IO.FileStream fs = new FileStream(Server.MapPath("pdf") + "\\" + "First PDF document.pdf", FileMode.Create); * * System.IO.FileStream fs = new FileStream(Environment.GetEnvironmentVariable("Assets") + "Order.pdf", FileMode.Create); * // Create an instance of the document class which represents the PDF document itself. * Document document = new Document(PageSize.A4, 25, 25, 30, 30); * // Create an instance to the PDF file by creating an instance of the PDF Writer class, using the document and the filestrem in the constructor. * * PdfWriter writer = PdfWriter.GetInstance(document, fs); * * * // Open the document to enable you to write to the document * * document.Open(); * * // Add a simple and well known phrase to the document in a flow layout manner * * document.Add(new Paragraph("Hello World!")); * * // Close the document * * document.Close(); * // Close the writer instance * * writer.Close(); * // Always close open file handles explicitly * fs.Close(); * returnValue = fileName; * } * catch (Exception ee) { * returnValue = "ERROR" + ee.Message; * } * return returnValue; * } */ private string printPdfFile() { string returnValue = ""; try { string fileName = ""; // create flow document and register necessary styles FlowDocument doc = new FlowDocument(); doc.Margin = new Thickness(10, 10, 10, 10); // the style for all document's textblocks doc.StyleManager.RegisterStyle("TextBlock, TextBox", new Style() { Font = new Font("Helvetica", 20), Color = RgbColors.Black, Display = Display.Block }); // the style for the section that contains employee data doc.StyleManager.RegisterStyle("#border", new Style() { Padding = new Thickness(10, 10, 10, 10), BorderColor = RgbColors.DarkRed, Border = new Border(5), BorderRadius = 5 } ); // add PDF form fields for later processing doc.Fields.Add(new TextField("firstName", "Hello")); doc.Fields.Add(new TextField("lastName", "test12345")); doc.Fields.Add(new TextField("position", "Manager")); // create section and add text block inside Section section = new Section() { Id = "border" }; // ios PDF preview doesn't display fields correctly, // uncomment this code to use simple text blocks instead of text boxes // section.Add(new TextBlock(string.Format("First name: {0}",currentEmployee.FirstName))); // section.Add(new TextBlock(string.Format("Last name: {0}",currentEmployee.LastName))); // section.Add(new TextBlock(string.Format("Position: {0}",currentEmployee.CurrentPosition))); section.Add(new TextBlock("First name: ")); section.Add(new TextBox("firstName")); section.Add(new TextBlock("Last name: ")); section.Add(new TextBox("lastName")); section.Add(new TextBlock("Position: ")); section.Add(new TextBox("position")); doc.Add(section); // get io service and generate output file path var fileManager = DependencyService.Get <IFileIO>(); //string filePath = Path.Combine(fileManager.GetMyDocumentsPath(), "form.pdf"); string filePath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "form.pdf"); //System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) // generate document using (Stream outputStream = fileManager.CreateFile(filePath)) { doc.Write(outputStream, new ResourceManager()); } // request preview DependencyService.Get <IPDFPreviewProvider>().TriggerPreview(filePath); returnValue = fileName; } catch (Exception e) { returnValue = e.Message; } return(returnValue); }