public static bool SaveDocument(RadFlowDocument document, string selectedFormat)
        {
            IFormatProvider<RadFlowDocument> formatProvider = null;
            switch (selectedFormat)
            {
                case "Docx":
                    formatProvider = new DocxFormatProvider();
                    break;
                case "Rtf":
                    formatProvider = new RtfFormatProvider();
                    break;
                case "Html":
                    formatProvider = new HtmlFormatProvider();
                    break;
                case "Txt":
                    formatProvider = new TxtFormatProvider();
                    break;
                case "Pdf":
                    formatProvider = new PdfFormatProvider();
                    break;
            }

            if (formatProvider == null)
            {
                return false;
            }

            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = String.Format("{0} files|*{1}|All files (*.*)|*.*",
                selectedFormat,
                formatProvider.SupportedExtensions.First());
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    formatProvider.Export(document, stream);
                }

                return true;
            }
            else
            {
                return false;
            }
        }
        public static IWorkbookFormatProvider GetFormatProvider(string extension)
        {
            IWorkbookFormatProvider formatProvider;
            switch (extension)
            {
                case XlsxFormat:
                    formatProvider = new XlsxFormatProvider();
                    break;
                case CsvFormat:
                    formatProvider = new CsvFormatProvider();
                    ((CsvFormatProvider)formatProvider).Settings.HasHeaderRow = true;
                    break;
                case TxtFormat:
                    formatProvider = new TxtFormatProvider();
                    break;
                case PdfFormat:
                    formatProvider = new PdfFormatProvider();
                    break;
                default:
                    formatProvider = null;
                    break;
            }

            return formatProvider;
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            PdfFormatProvider provider = new PdfFormatProvider();

            RadFixedDocument document = provider.Import(File.ReadAllBytes(InputFileWithInteractiveForms));

            ModifyFormFieldValues(document);

            string modifiedFileName = "Modified.pdf";

            if (File.Exists(modifiedFileName))
            {
                File.Delete(modifiedFileName);
            }

            File.WriteAllBytes(modifiedFileName, provider.Export(document));

            ProcessStartInfo psi = new ProcessStartInfo()
            {
                FileName        = modifiedFileName,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
        private void Export(object param)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = String.Format("{0} files|*.{1}|{2} files|*.{3}", "Pdf", "pdf", "Text", "txt");

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    RadFixedDocument document = this.CreateDocument();
                    switch (dialog.FilterIndex)
                    {
                        case 1:
                            PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
                            pdfFormatProvider.Export(document, stream);
                            break;
                        case 2:
                            using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
                            {
                                TextFormatProvider textFormatProvider = new TextFormatProvider();
                                writer.Write(textFormatProvider.Export(document));
                            }
                            break;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static IWorkbookFormatProvider GetFormatProvider(string extension)
        {
            IWorkbookFormatProvider formatProvider;

            switch (extension)
            {
            case XlsxFormat:
                formatProvider = new XlsxFormatProvider();
                break;

            case CsvFormat:
                formatProvider = new CsvFormatProvider();
                ((CsvFormatProvider)formatProvider).Settings.HasHeaderRow = true;
                break;

            case TxtFormat:
                formatProvider = new TxtFormatProvider();
                break;

            case PdfFormat:
                formatProvider = new PdfFormatProvider();
                break;

            default:
                formatProvider = null;
                break;
            }

            return(formatProvider);
        }
Ejemplo n.º 6
0
        private void OnExportClick(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog
            {
                DefaultExt = "pdf",
                Filter = "Diagram files|*.pdf|All Files (*.*)|*.*",
#if WPF
				FileName = "Diagram.pdf"
#else
                DefaultFileName = "Diagram.pdf"
#endif
            };
            if (dialog.ShowDialog() == true)
            {
                var enclosingBounds = this.diagram.CalculateEnclosingBounds();
                enclosingBounds = enclosingBounds.InflateRect(30);

                RadFixedDocument document = new RadFixedDocument();
                document.Pages.Add(ExportHelper.ExportDiagram(this.diagram, enclosingBounds));

                PdfFormatProvider provider = new PdfFormatProvider();
                using (var output = dialog.OpenFile())
                {
                    provider.Export(document, output);
                }
            }
        }
    }
Ejemplo n.º 7
0
 private void UsePdfSettingsExportWorkbook()
 {
     #region radspreadprocessing-formats-and-conversion-pdf-settings_0
     PdfFormatProvider provider = new PdfFormatProvider();
     provider.ExportSettings = new PdfExportSettings(ExportWhat.EntireWorkbook, false);
     #endregion
 }
        public HttpResponseMessage Post([FromBody] MyPdfContent value)
        {
            RadFixedDocument document;

            // determine if we're using images or not and generate the document accordingly
            if (string.IsNullOrEmpty(value.ImageBase64))
            {
                // if there's no image, generate a sample with graphics
                document = GenerateSampleDocument(value);
            }
            else
            {
                // if there is image data, insert the image
                document = GenerateImageDocument(value);
            }

            // Now we export the RadDocument as a PDF file and save it to the server
            var provider = new PdfFormatProvider();

            provider.Export(document);
            byte[] bytes = provider.Export(document);

            var response = new HttpResponseMessage();

            response.Content = new ByteArrayContent(bytes);
            response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentDisposition.FileName = value.RequestedFileName;
            response.Content.Headers.ContentType   = new MediaTypeHeaderValue("application/pdf");
            response.Content.Headers.ContentLength = bytes.Length;

            return(response);
        }
Ejemplo n.º 9
0
        internal void SaveFileAndPreview()
        {
            string resultFileName = string.Format("ExportedDocument_ImageQuality-{0}.pdf", this.imageQuality);

            if (File.Exists(resultFileName))
            {
                File.Delete(resultFileName);
            }

            PdfFormatProvider provider = new PdfFormatProvider();

            using (Stream stream = File.OpenWrite(resultFileName))
            {
                provider.ExportSettings.ImageQuality = this.imageQuality;
                provider.Export(this.document, stream);
            }

            ProcessStartInfo psi = new ProcessStartInfo()
            {
                FileName        = resultFileName,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
        public void Export(string format)
        {
            var workbook  = this.GenerateWorkBook();
            var extension = format;

            SaveFileDialog dialog = new SaveFileDialog()
            {
                DefaultExt  = extension,
                FileName    = "File",
                Filter      = extension + "files (*." + extension + ")|*." + extension + "|All files (*.*)|*.*",
                FilterIndex = 1
            };

            if (dialog.ShowDialog() == true)
            {
                BinaryWorkbookFormatProviderBase provider;
                if (format == "xlsx")
                {
                    provider = new XlsxFormatProvider();
                }
                else
                {
                    provider = new PdfFormatProvider();
                }

                using (Stream output = dialog.OpenFile())
                {
                    provider.Export(workbook, output);
                }

                this.subItemsCount = 0;
                this.parentItemsDictionary.Clear();
            }
        }
Ejemplo n.º 11
0
        public static void Export(RadDocument document, params string[] titles)
        {
            var filePath = Path.GetTempFileName().Replace(".tmp", ".pdf");

            var documentHeader = CreateHeader(titles);
            document.Sections.First.Headers.Default = new Header() { Body = documentHeader };

            if (document != null)
            {
                document.LayoutMode = DocumentLayoutMode.Paged;
                document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                document.SectionDefaultPageMargin = new Padding(40, 60, 30, 30);

                document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

                IDocumentFormatProvider provider = new PdfFormatProvider();

                using (Stream stream = new FileStream(filePath, FileMode.Create))
                {
                    provider.Export(document, stream);
                }
            }

            Process.Start(filePath);
        }
Ejemplo n.º 12
0
        public static void Export(RadDocument document, params string[] titles)
        {
            var filePath = Path.GetTempFileName().Replace(".tmp", ".pdf");

            var documentHeader = CreateHeader(titles);

            document.Sections.First.Headers.Default = new Header()
            {
                Body = documentHeader
            };

            if (document != null)
            {
                document.LayoutMode = DocumentLayoutMode.Paged;
                document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                document.SectionDefaultPageMargin = new Padding(40, 60, 30, 30);

                document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

                IDocumentFormatProvider provider = new PdfFormatProvider();

                using (Stream stream = new FileStream(filePath, FileMode.Create))
                {
                    provider.Export(document, stream);
                }
            }

            Process.Start(filePath);
        }
Ejemplo n.º 13
0
        private byte[] CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();

            byte[]           resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jpg");
            EncodedImageData rgbJpeg       = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.DCTDecode });

            this.CreatePageWithImage(document, "JPEG", rgbJpeg);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jpg");
            EncodedImageData jpeg2000Gray = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.DCTDecode });

            this.CreatePageWithImage(document, "JPEG", jpeg2000Gray);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jp2");
            EncodedImageData rgbJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.JPXDecode });

            this.CreatePageWithImage(document, "JPEG 2000", rgbJpc);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jp2");
            EncodedImageData grayScaleJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.JPXDecode });

            this.CreatePageWithImage(document, "JPEG 2000", grayScaleJpc);

            if (File.Exists(TestFileName))
            {
                File.Delete(TestFileName);
            }

            byte[] documentBytes = new PdfFormatProvider().Export(document);

            return(documentBytes);
        }
        public void SaveFile(string filePath)
        {
            string defaultFileName = string.Format("PDF with ImageQuality {0}.pdf", this.imageQuality);

            string resultFile = Path.Combine(filePath, defaultFileName);

            this.PrepareDirectory(filePath, resultFile);

            PdfFormatProvider provider;

            provider = new PdfFormatProvider();

            using (Stream stream = File.OpenWrite(resultFile))
            {
                provider.ExportSettings.ImageQuality = this.imageQuality;
                provider.Export(this.document, stream);
            }

            Console.WriteLine("Document created.");

            ProcessStartInfo psi = new ProcessStartInfo()
            {
                FileName        = resultFile,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
Ejemplo n.º 15
0
        private static RadFixedDocument ImportDocument(string fileName)
        {
            PdfFormatProvider provider = new PdfFormatProvider();
            RadFixedDocument  document = provider.Import(File.ReadAllBytes(fileName));

            return(document);
        }
Ejemplo n.º 16
0
        private void ExportToPdf()
        {
            RadDocument document = GenerateRadDocument();
            var         provider = new PdfFormatProvider();

            ShowPrintPreviewDialog(document, provider);
        }
Ejemplo n.º 17
0
        private byte[] CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();

            byte[] resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jpg");
            EncodedImageData rgbJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", rgbJpeg);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jpg");
            EncodedImageData jpeg2000Gray = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", jpeg2000Gray);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jp2");
            EncodedImageData rgbJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.JPXDecode });
            this.CreatePageWithImage(document, "JPEG 2000", rgbJpc);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jp2");
            EncodedImageData grayScaleJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.JPXDecode });
            this.CreatePageWithImage(document, "JPEG 2000", grayScaleJpc);

            if (File.Exists(TestFileName))
            {
                File.Delete(TestFileName);
            }

            byte[] documentBytes = new PdfFormatProvider().Export(document);

            return documentBytes;
        }
Ejemplo n.º 18
0
        public void Export(string filePath)
        {
            PdfFormatProvider formatProvider = new PdfFormatProvider();

            formatProvider.ExportSettings.ImageQuality = ImageQuality.High;

            string resultFile = System.IO.Path.Combine(filePath, this.defaultDocumentName);

            this.PrepareDirectory(filePath, resultFile);

            using (FileStream stream = File.OpenWrite(resultFile))
            {
                RadFixedDocument document = this.CreateDocument();
                formatProvider.Export(document, stream);
            }

            Console.WriteLine("The document is generated.");

            ProcessStartInfo psi = new ProcessStartInfo()
            {
                FileName        = resultFile,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
Ejemplo n.º 19
0
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            var data = Factory.GetDummyOrders();

            SaveFileDialog d = new SaveFileDialog();
            d.Filter = "PDF file format|*.pdf";

            // Save the document...
            if (d.ShowDialog() == true)
            {
                var grid = CreateGrid(data);
                var document = CreateDocument(grid);

                if (document != null)
                {
                    document.LayoutMode = DocumentLayoutMode.Paged;
                    document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                    document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

                    IDocumentFormatProvider provider = new PdfFormatProvider();
                    using (var output = d.OpenFile())
                    {
                        provider.Export(document, output);
                    }
                }
            }
        }
Ejemplo n.º 20
0
        private void OnExportClick(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog
            {
                DefaultExt = "pdf",
                Filter     = "Diagram files|*.pdf|All Files (*.*)|*.*",
#if WPF
                FileName = "Diagram.pdf"
#else
                DefaultFileName = "Diagram.pdf"
#endif
            };

            if (dialog.ShowDialog() == true)
            {
                var enclosingBounds = this.diagram.CalculateEnclosingBounds();
                enclosingBounds = enclosingBounds.InflateRect(30);

                RadFixedDocument document = new RadFixedDocument();
                document.Pages.Add(ExportHelper.ExportDiagram(this.diagram, enclosingBounds));

                PdfFormatProvider provider = new PdfFormatProvider();
                using (var output = dialog.OpenFile())
                {
                    provider.Export(document, output);
                }
            }
        }
    }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            Console.Write("Press Enter for converting a sample document to PDF or paste a path to a file you would like to convert: ");
            string input = Console.ReadLine();

            DocumentConverter converter = new DocumentConverter();

            PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();

            // The PdfFormatProvider instance accepts a renderer in its settings. The renderer needs to implement the IPdfChartRenderer interface,
            // more specifically the RenderChart method. The method takes a FixedContentEditor in its parameters, which will draw the chart, and the
            // other parameters contain the information necessary to draw it. The WpfPdfChartImageRenderer is an example implementation which uses
            // the Telerik.Windows.Controls.Spreadsheet and Telerik.Windows.Controls.Chart assemblies to draw the chart.
            pdfFormatProvider.ExportSettings.ChartRenderer = new WpfPdfChartImageRenderer();

            converter.PdfFormatProvider = pdfFormatProvider;

            if (string.IsNullOrEmpty(input))
            {
                converter.ConvertSampleDocument();
            }
            else
            {
                converter.ConvertCustomDocument(input);
            }

            Console.ReadKey();
        }
Ejemplo n.º 22
0
            static byte[] ConvertToPDF(RadFlowDocument document)
            {
                using MemoryStream ms = new MemoryStream();
                PdfFormatProvider convertFormatProvider = new PdfFormatProvider();

                convertFormatProvider.Export(document, ms);
                return(ms.ToArray());
            }
Ejemplo n.º 23
0
 private void ExportToPdf(Stream fileStream)
 {
     using (fileStream)
     {
         PdfFormatProvider provider = new PdfFormatProvider();
         provider.Export(workbook, fileStream);
     }
 }
 private void ExportPdf()
 {
     using (Stream stream = this.saveFileDialog.OpenFile())
     {
         PdfFormatProvider formatProvider = new PdfFormatProvider();
         formatProvider.Export(this.radSpreadsheet.Workbook, stream);
     }
 }
Ejemplo n.º 25
0
 private void ExportToPdf(string fileName)
 {
     using (Stream fileStream = this.GetFileStream(fileName))
     {
         PdfFormatProvider provider = new PdfFormatProvider();
         provider.Export(workbook, fileStream);
     }
 }
Ejemplo n.º 26
0
 public void ExportToPdf(string fileName)
 {
     using (Stream fileStream = new FileStream(fileName, FileMode.OpenOrCreate))
     {
         PdfFormatProvider provider = new PdfFormatProvider();
         provider.Export(workbook, fileStream);
     }
 }
Ejemplo n.º 27
0
        private void SaveDocumentAsPdf(RadFixedDocument document, string fileName)
        {
            PdfFormatProvider provider = new PdfFormatProvider();

            using (Stream output = File.OpenWrite(fileName))
            {
                provider.Export(document, output);
            }
        }
Ejemplo n.º 28
0
        public static void ExportToPagedFile(FrameworkElement element, Stream stream, bool lanscaped)
        {
            RadFixedDocument  document = PDFExportHelper.CreatePagedDocument(element, lanscaped);
            PdfFormatProvider provider = new PdfFormatProvider {
                ExportSettings = { ImageQuality = ImageQuality.High }
            };

            provider.Export(document, stream);
        }
Ejemplo n.º 29
0
        private void Save(string format)
        {
            if (this.document == null)
            {
                Console.WriteLine("Cannot save. A document is not loaded.");
                return;
            }

            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (format)
            {
            case "docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "html":
                formatProvider = new HtmlFormatProvider();
                break;

            case "rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "txt":
                formatProvider = new TxtFormatProvider();
                break;

            case "pdf":
                formatProvider = new PdfFormatProvider();
                break;
            }

            if (formatProvider == null)
            {
                Console.WriteLine("Not supported document format.");
                return;
            }

            string path = "Converted." + format;

            using (FileStream stream = File.OpenWrite(path))
            {
                formatProvider.Export(this.document, stream);
            }

            Console.WriteLine("Document converted.");

            ProcessStartInfo psi = new ProcessStartInfo()
            {
                FileName        = path,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
Ejemplo n.º 30
0
        public MainViewModel()
        {
            this.document = new RadFixedDocument();
            this.provider = new PdfFormatProvider();
            this.saveFileCommand = new DelegateCommand((parameter) => SaveFile());
            this.imageQualityValues = new ObservableCollection<ImageQuality>();
            this.InitializeImageQualityValues();

            this.GenerateDocumentContent();
        }
        public Example()
        {
            this.InitializeComponent();

            this.dialog = new OpenFileDialog();
            this.dialog.Filter = "PDF Files (*.pdf)|*.pdf";
            this.documentStream = App.GetResourceStream(new Uri("/PdfViewer;component/SampleData/Book.pdf", UriKind.Relative)).Stream;
            RadFixedDocument doc = new PdfFormatProvider(this.documentStream, FormatProviderSettings.ReadOnDemand).Import();
            this.book.ItemsSource = doc.Pages;
        }
Ejemplo n.º 32
0
 private void Import()
 {
     #region radpdfprocessing-formats-and-conversion-pdf-pdfformatprovider_0
     PdfFormatProvider provider = new PdfFormatProvider();
     using (Stream input = File.OpenRead("Sample.pdf"))
     {
         RadFixedDocument document = provider.Import(input);
     }
     #endregion
 }
Ejemplo n.º 33
0
        public MainViewModel()
        {
            this.document           = new RadFixedDocument();
            this.provider           = new PdfFormatProvider();
            this.saveFileCommand    = new DelegateCommand((parameter) => SaveFile());
            this.imageQualityValues = new ObservableCollection <ImageQuality>();
            this.InitializeImageQualityValues();

            this.GenerateDocumentContent();
        }
Ejemplo n.º 34
0
        private RadFixedDocument GetDocumentFromTemplate(string fileName)
        {
            PdfFormatProvider provider = new PdfFormatProvider();
            RadFixedDocument  document;

            using (Stream stream = File.OpenRead(fileName))
            {
                document = provider.Import(stream);
            }
            return(document);
        }
Ejemplo n.º 35
0
        private void OpenFile(Stream stream)
        {
            using (stream)
            {
                PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
                pdfFormatProvider.ImportSettings = PdfImportSettings.ReadOnDemand;
                RadFixedDocument document = pdfFormatProvider.Import(stream);

                this.pdfViewer.Document = document;
            }
        }
Ejemplo n.º 36
0
 private void ExportPdf()
 {
     #region radspreadprocessing-formats-and-conversion-pdf-pdfformatprovider_0
     PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
     using (Stream output = GetFileStream())
     {
         Workbook workbook = CreateSampleWorkbook();
         pdfFormatProvider.Export(workbook, output);
     }
     #endregion
 }
Ejemplo n.º 37
0
 private void Export()
 {
     #region radpdfprocessing-formats-and-conversion-pdf-pdfformatprovider_1
     PdfFormatProvider provider = new PdfFormatProvider();
     using (Stream output = File.OpenWrite("sample.pdf"))
     {
         RadFixedDocument document = CreateRadFixedDocument();
         provider.Export(document, output);
     }
     #endregion
 }
        public Example()
        {
            InitializeComponent();
            this.ApplyThemeSpecificChanges();

            this.providerPdf = new PdfFormatProvider();

            this.LoadSampleDocument();
            this.UpdatePdfViewer();
            this.DataContext = new Context() { Uri = GetResourceUri(DefaultSampleDocument).OriginalString };
        }
Ejemplo n.º 39
0
        public CreateClientLetterTelerik(string sourcePath, string saveAsFile, CashFlowInformation information, CashFlowDetail detail)
        {
            this.sourcePath  = sourcePath;
            SaveAsFile       = saveAsFile;
            this.information = information;
            this.detail      = detail;

            FillStrings(detail);
            RadFlowDocument wordDocument = new RadFlowDocument();

            provider = new DocxFormatProvider();

            try
            {
                using (Stream input = File.OpenRead(sourcePath))
                {
                    wordDocument = provider.Import(input);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Das Word-Template konnte nicht geöffnet werden. {ex.Message}");
            }

            editor = new RadFlowDocumentEditor(wordDocument);
            ReplacePlaceholder(detail);

            int    pos      = saveAsFile.LastIndexOf(".");
            string fileName = saveAsFile.Substring(0, pos) + ".docx";

            using (Stream output = File.OpenWrite(fileName))
            {
                provider.Export(editor.Document, output);
            }



            string pdfFile = fileName.Replace(".docx", ".pdf");

            // cpmversion of a flowdocument to a fixeddocument

            PdfFormatProvider pdfProvider   = new PdfFormatProvider();
            RadFixedDocument  fixedDocument = pdfProvider.ExportToFixedDocument(editor.Document);

            // write the fixeddocuement to file
            Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider fixedProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();


            using (Stream output = File.OpenWrite(pdfFile))
            {
                fixedProvider.Export(fixedDocument, output);
            }
        }
Ejemplo n.º 40
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            RadFixedDocument document = new RadFixedDocument();
            FixedContentEditor editor = new FixedContentEditor(document.Pages.AddPage());
            editor.DrawText("Hello PdfProcessing!");

            PdfFormatProvider provider = new PdfFormatProvider();
            MemoryStream stream = new MemoryStream();
            provider.Export(document, stream);

            this.ViewModel.DocumentStream = stream;
        }
        protected void ExportaPDF()
        {
            var document = CreateDocument(this, null);

            if (document != null)
            {
                document.LayoutMode = DocumentLayoutMode.Paged;
                document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

                IDocumentFormatProvider provider = new PdfFormatProvider();

                var dialog = new System.Windows.Forms.SaveFileDialog();
                dialog.DefaultExt = "*.pdf";
                dialog.Filter     = "Adobe PDF Document (*.pdf)|*.pdf";

                var dialogRes = dialog.ShowDialog();

                if (dialogRes == System.Windows.Forms.DialogResult.OK)
                {
                    using (var output = dialog.OpenFile())
                    {
                        provider.Export(document, output);
                    }
                }
            }


            //string extension = "pdf";

            //System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog()
            //{
            //    DefaultExt = extension,
            //    Filter = String.Format("{1} files (*.{0})|*.{0}|Pdf files (*.pdf)|*.pdf", extension, "Pdf"),
            //    FilterIndex = 2,
            //    Title = "Selecione o local onde deseja exportar."
            //};



            //if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            //{
            //    using (Stream stream = saveFileDialog1.OpenFile())
            //    {
            //        Telerik.Windows.Controls.GridViewExportOptions exp = new Telerik.Windows.Controls.GridViewExportOptions();
            //        exp.ShowColumnFooters = true;
            //        exp.ShowColumnHeaders = true;
            //        exp.ShowGroupFooters = true;

            //        this.Export(stream, exp);
            //    }
            //}
        }
        private void Open_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this.dialog.ShowDialog() == true)
            {
                this.CloseStream();
#if SILVERLIGHT
                this.documentStream = this.dialog.File.OpenRead();
#elif WPF
                this.documentStream = this.dialog.OpenFile();
#endif
                RadFixedDocument doc = new PdfFormatProvider(this.documentStream, FormatProviderSettings.ReadOnDemand).Import();
                this.book.ItemsSource = doc.Pages;
            }
        }
Ejemplo n.º 43
0
        private void Export(object param)
        {
            PdfFormatProvider formatProvider = new PdfFormatProvider();
            formatProvider.ExportSettings.ImageQuality = ImageQuality.High;

            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = String.Format("{0} files|*.{1}", "Pdf", "pdf");

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    RadFixedDocument document = this.CreateDocument();
                    formatProvider.Export(document, stream);
                }
            }
        }
Ejemplo n.º 44
0
        protected override void WriteToFile()
        {
            using (var pdfStream = File.Open(OutputFileLocation, FileMode.Create))
            {
                var pdfFormatProvider = new PdfFormatProvider();

                var pdfExportSettings = new PdfExportSettings();
                pdfExportSettings.ImagesCompressionMode = PdfImagesCompressionMode.Automatic;
                pdfExportSettings.ImagesDeflaterCompressionLevel = -1;
                pdfExportSettings.ContentsCompressionMode = PdfContentsCompressionMode.Automatic;
                var pdfDocInfo = new PdfDocumentInfo();
                pdfDocInfo.Title = this.RootMap.Name;
                pdfDocInfo.Subject = this.RootMap.Name;
                pdfDocInfo.Producer = "Glyma Export";
                pdfExportSettings.DocumentInfo = pdfDocInfo;
                pdfFormatProvider.ExportSettings = pdfExportSettings;
                pdfFormatProvider.Export(Document, pdfStream);
            }
        }
Ejemplo n.º 45
0
        private void Export(System.Windows.Controls.Border element)
        {
            PrepareForExport(element);

            var dialog = new SaveFileDialog
            {
                DefaultExt = "pdf",
                Filter = "Pdf files|*.pdf|All Files (*.*)|*.*",
            };
            if (dialog.ShowDialog() == true)
            {
                RadFixedDocument document = this.CreateDocument(element);
                PdfFormatProvider provider = new PdfFormatProvider();
                provider.ExportSettings.ImageQuality = ImageQuality.High;

                using (var output = dialog.OpenFile())
                {
                    provider.Export(document, output);
                }
            }
        }
Ejemplo n.º 46
0
		private void Export_Pdf_Click(object sender, RoutedEventArgs e)
		{
			SaveFileDialog dialog = new SaveFileDialog();
			dialog.DefaultExt = "*.pdf";
			dialog.Filter = "Adobe PDF Document (*.pdf)|*.pdf";

			if (dialog.ShowDialog() == true)
			{
				RadDocument document = this.CreateDocument();
				document.LayoutMode = DocumentLayoutMode.Paged;
				document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
				document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

				PdfFormatProvider provider = new PdfFormatProvider();

				using (Stream output = dialog.OpenFile())
				{
					provider.Export(document, output);
				}
			}
		}
Ejemplo n.º 47
0
        private byte[] CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();

            byte[] resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jpg");
            EncodedImageData rgbJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", rgbJpeg);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jpg");
            EncodedImageData grayJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", grayJpeg);

            // decode is used for inverting the colors of the cmyk image.
            // More information on the matter can be found here: http://graphicdesign.stackexchange.com/a/15906
            double[] decode = new double[] { 1, 0, 1, 0, 1, 0, 1, 0 };
            resourceBytes = ResourceHelper.GetResourceBytes("Resources/cmyk.jpg");
            EncodedImageData cmykJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceCmyk, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", cmykJpeg, decode);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jp2");
            EncodedImageData rgbJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.JPXDecode });
            this.CreatePageWithImage(document, "JPEG 2000", rgbJpc);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jp2");
            EncodedImageData grayScaleJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.JPXDecode });
            this.CreatePageWithImage(document, "JPEG 2000", grayScaleJpc);

            if (File.Exists(TestFileName))
            {
                File.Delete(TestFileName);
            }

            byte[] documentBytes = new PdfFormatProvider().Export(document);

            return documentBytes;
        }
Ejemplo n.º 48
0
 private void ExportPdf()
 {
     using (Stream stream = this.saveFileDialog.OpenFile())
     {
         PdfFormatProvider formatProvider = new PdfFormatProvider();
         formatProvider.Export(this.radSpreadsheet.Workbook, stream);
     }
 }
Ejemplo n.º 49
0
        private void SaveButtonClick(object sender, RoutedEventArgs e)
        {
            //TODO: Need to scroll through to force generation of items controls

            //Open a SaveFileDialog to let the user save the document as a PDF
            var saveDialog = new SaveFileDialog { DefaultExt = ".pdf", Filter = "PDF|*.pdf", DefaultFileName = GetFileName() + ".pdf" };

            var dialogResult = saveDialog.ShowDialog();
            if (dialogResult != true) return;

            var provider = new PdfFormatProvider();
            using (var output = saveDialog.OpenFile())
                provider.Export(ManifestRichTextBox.Document, output);
        }
Ejemplo n.º 50
0
 public void ExportToPdf(string fileName)
 {
     using (Stream fileStream = new FileStream(fileName, FileMode.OpenOrCreate))
     {
         PdfFormatProvider provider = new PdfFormatProvider();
         provider.Export(workbook, fileStream);
     }
 }
Ejemplo n.º 51
0
 public static void ExportPivotToPdf(RadPivotGrid pivot, params string[] titles)
 {
     var filePath = Path.GetTempFileName().Replace(".tmp", ".pdf");
     RadDocument document = GenerateRadDocument(pivot);
     var documentHeader = CreateHeader(titles);
     document.Sections.First.Headers.Default = new Header() { Body = documentHeader };
     var provider = new PdfFormatProvider();
     using (Stream stream = new FileStream(filePath, FileMode.Create))
     {
         provider.Export(document, stream);
     }
     Process.Start(filePath);
 }
Ejemplo n.º 52
0
 private void ExportToPdf(string fileName)
 {
     using (Stream fileStream = this.GetFileStream(fileName))
     {
         PdfFormatProvider provider = new PdfFormatProvider();
         provider.Export(workbook, fileStream);
     }
 }
Ejemplo n.º 53
0
 private void ExportToPdf(Stream fileStream)
 {
     using (fileStream)
     {
         PdfFormatProvider provider = new PdfFormatProvider();
         provider.Export(workbook, fileStream);
     }            
 }
Ejemplo n.º 54
0
        /// <summary>
        /// Lancement de l'export PDF
        /// </summary>
        /// <param name="parameter"></param>
        public void ExportPDF(object parameter)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.DefaultExt = "*.pdf";
            dialog.Filter = "Adobe PDF Document (*.pdf)|*.pdf";

            if (dialog.ShowDialog() == true)
            {
                //Récupération du DataPager pour imprimer toute la grid sans la pagination
                bool paged = ExportAndPrintHelper.GetParameterAtIndex(parameter, ExportAndPrintHelper.RadDataPagerIndex) != null && ExportAndPrintHelper.GetParameterAtIndex(parameter, ExportAndPrintHelper.RadDataPagerIndex) is RadDataPager;

                RadDataPager pager = paged ? (RadDataPager)ExportAndPrintHelper.GetParameterAtIndex(parameter, ExportAndPrintHelper.RadDataPagerIndex) : null;

                int originalPageSize = 0;
                int originalPageIndex = 0;

                if (paged)
                {
                    originalPageSize = pager.PageSize;
                    originalPageIndex = pager.PageIndex;

                    pager.PageSize = 0;
                }
                try
                {
                    RadGridView grid = ExportAndPrintHelper.InverseVisibilityColumnsToExport(parameter,
                        ExportAndPrintHelper.ColumnsToExportIndex, ExportAndPrintHelper.RadGridViewIndex);

                    RadDocument document = ExportAndPrintHelper.CreateDocument(grid);

                    PdfFormatProvider provider = new PdfFormatProvider();

                    using (Stream output = dialog.OpenFile())
                    {
                        provider.Export(document, output);
                    }
                }
                catch (OutOfMemoryException ex)
                {
                    throw ex;
                }
                catch (IOException ex)
                {
                    throw ex;
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    if (paged)
                    {
                        pager.PageSize = originalPageSize;
                        pager.PageIndex = originalPageIndex;
                    }

                    ExportAndPrintHelper.InverseVisibilityColumnsToExport(parameter,
                        ExportAndPrintHelper.ColumnsToExportIndex, ExportAndPrintHelper.RadGridViewIndex);
                }
            }
        }
Ejemplo n.º 55
0
        public static void Export(this RadGridView grid, ExportSettings settings)
        {
            var dialog = new SaveFileDialog();

            switch (settings.Format)
            {
                case ExportFormat.Pdf:
                    dialog.DefaultExt = "*.pdf";
                    dialog.Filter = "Adobe PDF 文档 (*.pdf)|*.pdf";
                    break;
                case ExportFormat.Excel:
                    dialog.DefaultExt = "*.xlsx";
                    dialog.Filter = "Excel 工作簿 (*.xlsx)|*.xlsx";
                    break;
                case ExportFormat.Word:
                    dialog.DefaultExt = "*.docx";
                    dialog.Filter = "Word 文档 (*.docx)|*.docx";
                    break;
                case ExportFormat.Csv:
                    dialog.DefaultExt = "*.csv";
                    dialog.Filter = "CSV (逗号分隔) (*.csv)|*.csv";
                    break;
            }

            if (settings.FileName != null)
            {
                dialog.DefaultFileName = settings.FileName;
            }

            if (dialog.ShowDialog() == true)
            {
                switch (settings.Format)
                {
                    case ExportFormat.Csv:
                        using (var output = dialog.OpenFile())
                        {
                            grid.Export(output, new GridViewExportOptions
                                {
                                    Format = Telerik.Windows.Controls.ExportFormat.Csv,
                                    ShowColumnFooters = grid.ShowColumnFooters,
                                    ShowColumnHeaders = grid.ShowColumnHeaders,
                                    ShowGroupFooters = grid.ShowGroupFooters
                                });
                        }
                        break;
                    case ExportFormat.Excel:
                        {
                            var workbook = CreateWorkBook(grid);

                            if (workbook != null)
                            {
                                var provider = new XlsxFormatProvider();
                                using (var output = dialog.OpenFile())
                                {
                                    provider.Export(workbook, output);
                                }
                            }
                        }
                        break;
                    default:
                        {
                            var document = CreateDocument(grid, settings);

                            if (document != null)
                            {
                                document.LayoutMode = DocumentLayoutMode.Paged;
                                document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                                document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

                                IDocumentFormatProvider provider = null;

                                switch (settings.Format)
                                {
                                    case ExportFormat.Pdf:
                                        provider = new PdfFormatProvider();
                                        break;
                                    case ExportFormat.Word:
                                        provider = new DocxFormatProvider();
                                        break;
                                }

                                using (var output = dialog.OpenFile())
                                {
                                    if (provider != null) provider.Export(document, output);
                                }
                            }
                        }
                        break;
                }
            }
        }
Ejemplo n.º 56
0
 private void ExportToPdf()
 {
     RadDocument document = GenerateRadDocument();
     var provider = new PdfFormatProvider();
     ShowPrintPreviewDialog(document, provider);
 }