Exemple #1
0
        /// <summary>
        /// This example demonstrates how to implement custom cache when rendering document.
        /// </summary>
        public static void Run()
        {
            string outputDirectory = Constants.GetOutputDirectoryPath();

            RedisCache cache = new RedisCache("sample_");
            Func <ConverterSettings> settingsFactory = () => new ConverterSettings
            {
                Cache = cache
            };

            using (Converter converter = new Converter(Constants.SAMPLE_PDF, settingsFactory))
            {
                PdfConvertOptions options = new PdfConvertOptions();

                Stopwatch stopWatch = Stopwatch.StartNew();
                converter.Convert("converted.pdf", options);
                stopWatch.Stop();

                Console.WriteLine("Time taken on first call to Convert method {0} (ms).", stopWatch.ElapsedMilliseconds);

                stopWatch.Restart();
                converter.Convert("converted-1.pdf", options);
                stopWatch.Stop();

                Console.WriteLine("Time taken on second call to Convert method {0} (ms).", stopWatch.ElapsedMilliseconds);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            Func <LoadOptions> getLoadOptions = () => new WordProcessingLoadOptions
            {
                Password = "******"
            };

            using (Converter converter = new Converter(Constants.SAMPLE_DOCX_WITH_PASSWORD, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions
                {
                    PageNumber = 2,
                    PagesCount = 1,
                    Rotate     = Rotation.On180,
                    Dpi        = 300,
                    Width      = 1024,
                    Height     = 768
                };
                converter.Convert(outputFile, options);
            }
            Console.WriteLine("\nPassword protected document converted successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #3
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();

            Func <LoadOptions> getLoadOptions = () => new EmailLoadOptions
            {
                ConvertOwner = true,
                ConvertOwned = true,
                // convert email itself and the attachments
                Depth = 2
            };

            using (Converter converter = new Converter(Constants.SAMPLE_EML_WITH_ATTACHMENT, getLoadOptions))
            {
                int index = 1;
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(() =>
                {
                    string fileName = index == 1 ? "converted.pdf" : $"converted-attachment-{index - 1}.pdf";
                    index++;
                    string outputFile = Path.Combine(outputFolder, fileName);
                    return(new FileStream(outputFile, FileMode.Create));
                }, options);
            }

            Console.WriteLine("\nEmail document converted successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #4
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

#if NETCOREAPP
            Func <LoadOptions> getLoadOptions = () => new SpreadsheetLoadOptions
            {
                SkipEmptyRowsAndColumns = true,
                OnePagePerSheet         = true
            };
#else
            Contracts.Func <LoadOptions> getLoadOptions = () => new SpreadsheetLoadOptions
            {
                SkipEmptyRowsAndColumns = true,
                OnePagePerSheet         = true
            };
#endif
            using (Converter converter = new Converter(Constants.SAMPLE_XLSX, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nSpreadsheet document converted successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #5
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

#if NETCOREAPP
            Func <LoadOptions> getLoadOptions = () => new EmailLoadOptions
            {
                ConvertOwned   = false,
                TimeZoneOffset = TimeSpan.FromHours(5)
            };
#else
            Contracts.Func <LoadOptions> getLoadOptions = () => new EmailLoadOptions
            {
                ConvertOwned   = false,
                TimeZoneOffset = TimeSpan.FromHours(5)
            };
#endif
            using (Converter converter = new Converter(Constants.SAMPLE_EML, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nEmail document converted successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #6
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

#if NETCOREAPP
            Func <LoadOptions> getLoadOptions = () => new CsvLoadOptions
            {
                ConvertDateTimeData = true,
                ConvertNumericData  = true
            };
#else
            Contracts.Func <LoadOptions> getLoadOptions = () => new CsvLoadOptions
            {
                ConvertDateTimeData = true,
                ConvertNumericData  = true
            };
#endif
            using (Converter converter = new Converter(Constants.SAMPLE_CSV, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nCsv document converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

#if NETCOREAPP
            Func <LoadOptions> getLoadOptions = () => new PresentationLoadOptions
            {
                DefaultFont     = "Helvetica",
                FontSubstitutes = new List <FontSubstitute>
                {
                    FontSubstitute.Create("Tahoma", "Arial"),
                    FontSubstitute.Create("Times New Roman", "Arial"),
                }
            };
#else
            Contracts.Func <LoadOptions> getLoadOptions = () => new PresentationLoadOptions
            {
                DefaultFont     = "Helvetica",
                FontSubstitutes = new List <FontSubstitute>
                {
                    FontSubstitute.Create("Tahoma", "Arial"),
                    FontSubstitute.Create("Times New Roman", "Arial"),
                }
            };
#endif
            using (Converter converter = new Converter(Constants.PPTX_WITH_NOTES, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nPresentation document converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

#if NETCOREAPP
            Func <ConverterSettings> settingsFactory = () => new ConverterSettings
            {
                Listener = new ConverterListener()
            };

            Func <LoadOptions> getLoadOptions = () => new WordProcessingLoadOptions
            {
                Password = "******"
            };
#else
            Contracts.Func <ConverterSettings> settingsFactory = () => new ConverterSettings
            {
                Listener = new ConverterListener()
            };

            Contracts.Func <LoadOptions> getLoadOptions = () => new WordProcessingLoadOptions
            {
                Password = "******"
            };
#endif
            using (Converter converter = new Converter(Constants.SAMPLE_DOCX_WITH_PASSWORD, getLoadOptions, settingsFactory))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nPassword protected document converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

#if NETCOREAPP
            Func <LoadOptions> getLoadOptions = () => new TxtLoadOptions
            {
                LeadingSpacesOptions           = TxtLeadingSpacesOptions.ConvertToIndent,
                DetectNumberingWithWhitespaces = true
            };
#else
            Contracts.Func <LoadOptions> getLoadOptions = () => new TxtLoadOptions
            {
                LeadingSpacesOptions           = TxtLeadingSpacesOptions.ConvertToIndent,
                DetectNumberingWithWhitespaces = true
            };
#endif
            using (Converter converter = new Converter(Constants.SAMPLE_TXT, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nTxt document converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

#if NETCOREAPP
            Func <LoadOptions> getLoadOptions = () => new CadLoadOptions
            {
                Width  = 1920,
                Height = 1080
            };
#else
            Contracts.Func <LoadOptions> getLoadOptions = () => new CadLoadOptions
            {
                Width  = 1920,
                Height = 1080
            };
#endif
            using (Converter converter = new Converter(Constants.SAMPLE_DWG_WITH_LAYOUTS_AND_LAYERS, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }


            Console.WriteLine("\nCad document converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputDirectory = Constants.GetOutputDirectoryPath();
            string convertedFile   = Path.Combine(outputDirectory, "converted.pdf");

            using (Converter converter = new Converter(Constants.SAMPLE_DOCX))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(convertedFile, options);
            }

            Console.WriteLine($"\nSource document converted successfully.\nCheck output in {outputDirectory}.");
        }
Exemple #12
0
        public static void Run()
        {
            string url             = "https://github.com/groupdocs-conversion/GroupDocs.Conversion-for-.NET/blob/master/Examples/GroupDocs.Conversion.Examples.CSharp/Resources/SampleFiles/sample.docx?raw=true";
            string outputDirectory = Constants.GetOutputDirectoryPath();
            string outputFile      = Path.Combine(outputDirectory, "converted.pdf");

            using (Converter converter = new Converter(() => GetRemoteFile(url)))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine($"\nSource document converted successfully.\nCheck output in {outputDirectory}.");
        }
        public static void Run()
        {
            string blobName        = "sample.docx";
            string outputDirectory = Constants.GetOutputDirectoryPath();
            string outputFile      = Path.Combine(outputDirectory, "converted.pdf");

            using (Converter converter = new Converter(() => DownloadFile(blobName)))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine($"\nSource document converted successfully.\nCheck output in {outputDirectory}.");
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            using (Converter converter = new Converter(Constants.SAMPLE_DOCX))
            {
                PdfConvertOptions options = new PdfConvertOptions();

                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nConversion to pdf completed successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #15
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            CultureInfo.CurrentCulture = new CultureInfo("fr-FR");

            using (Converter converter = new Converter(Constants.SAMPLE_EML))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nEmail document converted successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #16
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "pot-converted-to.pdf");

            // Load the source POT file
            using (var converter = new GroupDocs.Conversion.Converter(Constants.SAMPLE_POT))
            {
                var options = new PdfConvertOptions();
                // Save converted PDF file
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nConversion to pdf completed successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputDirectory = Constants.GetOutputDirectoryPath();
            string outputFile      = Path.Combine(outputDirectory, "converted.pdf");
            string filePath        = "ftp://localhost/sample.doc";

            using (Converter converter = new Converter(() => GetFileFromFtp(filePath)))
            {
                PdfConvertOptions options = new PdfConvertOptions();

                converter.Convert(outputFile, options);
            }

            Console.WriteLine($"\nSource document converted successfully.\nCheck output in {outputDirectory}.");
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile = Path.Combine(outputFolder, "otg-converted-to.tex");
            
            // Load the source OTG file
            using (var converter = new GroupDocs.Conversion.Converter(Constants.SAMPLE_OTG))
            {
                PdfConvertOptions options = new PdfConvertOptions { Format = GroupDocs.Conversion.FileTypes.PdfFileType.Tex };
                // Save converted TEX file
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nConversion to tex completed successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            using (Converter converter = new Converter(Constants.SAMPLE_DOCX))
            {
                PdfConvertOptions options = new PdfConvertOptions
                {
                    PageNumber = 2,
                    PagesCount = 2
                };
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nDocument converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            Func <LoadOptions> getLoadOptions = () => new CsvLoadOptions
            {
                Separator = ','
            };

            using (Converter converter = new Converter(Constants.SAMPLE_CSV, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nCsv document converted successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #21
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            Func <LoadOptions> getLoadOptions = () => new WordProcessingLoadOptions
            {
                HideWordTrackedChanges = true
            };

            using (Converter converter = new Converter(Constants.SAMPLE_DOCX_WITH_TRACKED_CHANGES, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nWordProcessing document converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            Func <LoadOptions> getLoadOptions = () => new CadLoadOptions
            {
                LayoutNames = new[] { "Layout1", "Layout3" }
            };

            using (Converter converter = new Converter(Constants.SAMPLE_DWG_WITH_LAYOUTS_AND_LAYERS, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nCad document converted successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #23
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            var possibleConversions = Converter.GetPossibleConversions("docx");
            var loadOptions         = (WordProcessingLoadOptions)possibleConversions.LoadOptions;

            loadOptions.Password = "******";

            using (Converter converter = new Converter(Constants.SAMPLE_DOCX_WITH_PASSWORD, () => loadOptions))
            {
                var convertOptions = new PdfConvertOptions();
                converter.Convert(outputFile, convertOptions);
            }

            Console.WriteLine("\nDocument converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            Func <LoadOptions> getLoadOptions = () => new PresentationLoadOptions
            {
                ShowHiddenSlides = true
            };

            using (Converter converter = new Converter(Constants.SAMPLE_PPTX_HIDDEN_PAGE, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nPresentation document converted successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #25
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            Func <LoadOptions> getLoadOptions = () => new TxtLoadOptions
            {
                Encoding = Encoding.GetEncoding("shift_jis")
            };

            using (Converter converter = new Converter(Constants.SAMPLE_TXT_SHIFT_JS_ENCODED, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nTxt document converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile = Path.Combine(outputFolder, "converted.pdf");

            Func<LoadOptions> getLoadOptions = () => new TxtLoadOptions
            {
                TrailingSpacesOptions = TxtTrailingSpacesOptions.Trim
            };

            using (Converter converter = new Converter(Constants.SAMPLE_TXT, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nTxt document converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");


            var imageLoadOptions = new ImageLoadOptions();

            imageLoadOptions.SetOcrConnector(new OcrConnector());

            using (Converter converter = new Converter(Constants.SAMPLE_JPEG, () => imageLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nDocument converted successfully. \nCheck output in {0}", outputFolder);
        }
Exemple #28
0
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            Func <LoadOptions> getLoadOptions = () => new SpreadsheetLoadOptions
            {
                ShowHiddenSheets = true,
                OnePagePerSheet  = true,
            };

            using (Converter converter = new Converter(Constants.SAMPLE_XLSX_WITH_HIDDEN_SHEET, getLoadOptions))
            {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.Convert(outputFile, options);
            }

            Console.WriteLine("\nSpreadsheet document converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "converted.pdf");

            using (FileStream outputStream = new FileStream(outputFile, FileMode.Create))
            {
                using (Converter converter = new Converter(Constants.SAMPLE_DOCX))
                {
                    var convertOptions = new PdfConvertOptions();
                    converter.Convert(() => new MemoryStream(), convertedStream =>
                    {
                        convertedStream.CopyTo(outputStream);
                    }, convertOptions);
                }
            }

            Console.WriteLine("\nDocument converted successfully. \nCheck output in {0}", outputFolder);
        }
        public static void Run()
        {
            string outputFolder = Constants.GetOutputDirectoryPath();
            string outputFile   = Path.Combine(outputFolder, "ost-converted-{0}-to.pdf");

            // Load the source OST file
            using (var converter = new GroupDocs.Conversion.Converter(Constants.SAMPLE_OST, fileType => fileType == PersonalStorageFileType.Ost
                                                                                                                ? new PersonalStorageLoadOptions()
                                                                                                                : null))
            {
                var options = new PdfConvertOptions();
                var counter = 1;
                // Save converted PDF file
                converter.Convert(
                    (FileType fileType) => new FileStream(string.Format(outputFile, counter++), FileMode.Create),
                    options
                    );
            }

            Console.WriteLine("\nConversion to pdf completed successfully. \nCheck output in {0}", outputFolder);
        }