private void SaveReport_Click(object sender, EventArgs e) { //Save Report to local address. var dialog = new SaveFileDialog(); dialog.Filter = "Pdf Files|*.pdf"; dialog.ShowDialog(); string content = CreatePdfString(); byte[] pdf = PdfService.GetPdfStrem(content); string path = dialog.FileName; bool result = FileService.SaveFileAsync(pdf, path).Result; if (result) { MessageBox.Show("El archivo se ha guardado.", "LTI", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Ha ocurrido un error al intentar generar el archivo. Por favor, inténtelo de nuevo más tarde.", "LTI", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Task <bool> Print(string html, string PrinterName) { return(Task.Run(async() => { try { byte[] pdf = PdfService.GetPdfStrem(html); // Save it in local var fileName = "tempPdf.pdf"; var rootPath = LocalPath; var filePath = Path.Combine(rootPath, fileName); await FileService.SaveFileAsync(pdf, filePath); IPrinter printer = new Printer(); printer.PrintRawFile(PrinterName, filePath, paused: false); return true; }catch (Exception exp) { Console.WriteLine($"Error: {exp}"); return false; } })); }