Hi to all,
I'm tring to creare an utility that receive a RadGridView and show me a preview of it.
I created 2 static methods CreateOpenXMLDocument that creates a Workbook starting by RadGridView control.
Second one is PreviewList that save the workbook in PDF File, and then I use PDFViewer.
PDFViewer show me an error that I've attached here.
If a try to open the PDF file, my PDF reader inform me that it's corrupted.
Where I wrong?
01.private static Workbook CreateOpenXMLDocument(RadGridView gridView)02.{03. gridView.ElementExportingToDocument += P_GridView_ElementExportingToDocument;04. var workbook = gridView.ExportToWorkbook();05. var worksheet = workbook.Worksheets[0];06. int columns = gridView.Columns.Count;07. 08. ColumnSelection columnSelection = worksheet.Columns[0, columns - 1];09. columnSelection.AutoFitWidth();10. 11. return workbook;12.}13. 14.public static void PreviewList(RadGridView gridView)15.{16. var workbook = CreateOpenXMLDocument(gridView);17. PdfFormatProvider provider = new PdfFormatProvider();18. 19. string tempPath = System.IO.Path.GetTempPath();20. string tempGiud = Guid.NewGuid().ToString().Replace("{}-", "");21. 22. string fileToPreview = string.Format(@"{0}{1}.pdf", tempPath, tempGiud);23. 24. using (Stream output = System.IO.File.OpenWrite(fileToPreview))25. {26. var exportSettings = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.Export.PdfExportSettings(Telerik.Windows.Documents.Spreadsheet.FormatProviders.ExportWhat.ActiveSheet, true);27. var pdfFileSettings = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExportSettings();28. 29. pdfFileSettings.ComplianceLevel = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfComplianceLevel.None;30. pdfFileSettings.ImageQuality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.High;31. 32. exportSettings.PdfFileSettings = pdfFileSettings;33. provider.ExportSettings = exportSettings;34. 35. provider.Export(workbook);36. }37. 38. PDFPreviewDialog win = new PDFPreviewDialog();39. win.Tag = fileToPreview;40. win.Center2_3();41. win.ShowDialog();42. 43. System.IO.File.Delete(fileToPreview);44.}