Esempio n. 1
0
        /// <summary>
        /// Von dem Doc-Dokument wird die erste Seite in tiff konvertiert und gespeichert.
        /// die funktion liefert den Path zu der neue Datei zurück.
        /// </summary>
        public string GetFirstPageAsImageFromDocument(DocumentParam param)
        {
            try
            {
                string   fileName = string.Empty;
                FileInfo fileInfo = new FileInfo(param.FilePath);

                if (fileInfo.Exists == false)
                {
                    return(fileName);
                }

                string pathFolder = Path.GetTempPath();

                FilesFunctions.DeleteFilesInFolder(pathFolder, Tiff);
                string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, true, Pdf);
                using (RichEditDocumentServer richServer = new RichEditDocumentServer())
                {
                    richServer.LoadDocument(param.FilePath);

                    //Specify export options:
                    PdfExportOptions options = new PdfExportOptions
                    {
                        Compressed   = false,
                        ImageQuality = PdfJpegImageQuality.Highest
                    };
                    //Export the document to the stream:

                    using (FileStream pdfFileStream = new FileStream(tempName, FileMode.Create))
                    {
                        richServer.ExportToPdf(pdfFileStream, options);
                    }
                }

                var pdf = new PdfTiffConverter();

                var parammeter = new DocumentParam
                {
                    Resolution   = param.Resolution,
                    Colour       = param.Colour,
                    Compression  = param.Compression,
                    Quality      = param.Quality,
                    KeepOriginal = param.KeepOriginal,
                    ConTyp       = param.ConTyp,
                    Doctyp       = param.Doctyp,
                    FilePath     = tempName
                };

                fileName = pdf.GetFirstPageAsImageFromDocument(parammeter);


                return(fileName);
            }
            catch (Exception ex)
            {
                FileLogger.FileLogger.Instance.WriteExeption(ex);
                return(string.Empty);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Konvertiert die PDF-Datei in Tiff-Dateien.
        /// Gibt eine liste mit den Pfaden der Tiff-Dateien zurück.
        /// </summary>
        public List <string> ConvertPDFToImage(string pathFolder, bool tempPrefix, DocumentParam param)
        {
            List <string> list = new List <string>();

            try
            {
                if (string.CompareOrdinal(pathFolder, string.Empty) == 0)
                {
                    return(list);
                }

                FileInfo fileInfo = new FileInfo(param.FilePath);

                if (fileInfo.Exists == false)
                {
                    return(list);
                }

                FilesFunctions.DeleteFilesInFolder(pathFolder, Tiff);

                // open existing PDF document
                using (PdfDocument pdfDocument = new PdfDocument(param.FilePath, true))
                {
                    // set resolution
                    //pdfDocument.RenderingSettings.Resolution = new Resolution(param.Resolution, param.Resolution);

                    //// set rendering mode - optimal balance between rendering speed and quality
                    //pdfDocument.RenderingSettings.RenderingMode = PdfRenderingMode.HighSpeed;

                    for (int pageCount = 0; pageCount < pdfDocument.Pages.Count; pageCount++)
                    {
                        string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, tempPrefix, Tiff);

                        // create new TIFF file
                        using (TiffFile tiffFile = new TiffFile(tempName, TiffFileFormat.LittleEndian))
                        {
                            tiffFile.Pages.EncoderSettings.Compression = TiffCompression.Zip;
                            tiffFile.Pages.Add(pdfDocument.Pages[pageCount].Render());
                            tiffFile.SaveChanges();
                            list.Add(tempName);
                        }
                    }
                }


                return(list);
            }
            catch (Exception ex)
            {
                FileLogger.FileLogger.Instance.WriteExeption(ex);
                return(list);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Konvertiert die PDF-Datei in Jpeg-Dateien.
        /// Gibt eine liste mit den Pfaden der Jpeg-Dateien zurück.
        /// </summary>
        public List <string> ConvertPDFToImage(string pathFolder, bool tempPrefix, DocumentParam param)
        {
            List <string> list = new List <string>();

            try
            {
                if (string.CompareOrdinal(pathFolder, string.Empty) == 0)
                {
                    return(list);
                }

                FileInfo fileInfo = new FileInfo(param.FilePath);

                if (fileInfo.Exists == false)
                {
                    return(list);
                }



                FilesFunctions.DeleteFilesInFolder(pathFolder, Jpeg);

                using (PdfDocument pdfDocument = new PdfDocument(param.FilePath, true))
                {
                    //pdfDocument.RenderingSettings.Resolution = new Resolution(150, 150);
                    JpegEncoder jpeGencoder = new JpegEncoder
                    {
                        Settings = { Quality = param.Quality, SaveAsGrayscale = false }
                    };


                    for (int pageCount = 0; pageCount < pdfDocument.Pages.Count; pageCount++)
                    {
                        string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, tempPrefix, Jpeg);
                        // get image of PDF page as VintasoftImage object
                        using (VintasoftImage vsImage = pdfDocument.Pages[pageCount].Render())
                        {
                            // save VintasoftImage object as JPEG file
                            vsImage.Save(tempName, jpeGencoder);
                            list.Add(tempName);
                        }
                    }
                }
                return(list);
            }
            catch (Exception ex)
            {
                FileLogger.FileLogger.Instance.WriteExeption(ex);
                return(list);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Konvertiert die Doc-Datei in Tiff-Dateien.
        /// Gibt eine liste mit den Pfaden der Tiff-Dateien zurück.
        /// </summary>
        public List <string> ConvertPDFToImage(string pathFolder, bool tempPrefix, DocumentParam param)
        {
            List <string> list = new List <string>();

            try
            {
                FileInfo fileInfo = new FileInfo(param.FilePath);

                if (fileInfo.Exists == false)
                {
                    return(list);
                }

                FilesFunctions.DeleteFilesInFolder(pathFolder, Tiff);
                //string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, tempPrefix, Pdf);

                string temp = $@"{Path.GetTempPath()}\Synios\{Path.GetFileNameWithoutExtension(fileInfo.FullName)}{Pdf}";


                using (RichEditDocumentServer richServer = new RichEditDocumentServer())
                {
                    richServer.LoadDocument(param.FilePath);

                    //Specify export options:
                    PdfExportOptions options = new PdfExportOptions
                    {
                        Compressed   = false,
                        ImageQuality = PdfJpegImageQuality.Highest
                    };
                    //Export the document to the stream:

                    using (FileStream pdfFileStream = new FileStream(temp, FileMode.Create))
                    {
                        richServer.ExportToPdf(pdfFileStream, options);
                    }
                }


                var pdf = new PdfTiffConverter();

                var parammeter = new DocumentParam
                {
                    Resolution   = param.Resolution,
                    Colour       = param.Colour,
                    Compression  = param.Compression,
                    Quality      = param.Quality,
                    KeepOriginal = param.KeepOriginal,
                    ConTyp       = param.ConTyp,
                    Doctyp       = param.Doctyp,
                    FilePath     = temp
                };

                list = pdf.ConvertPDFToImage(pathFolder, tempPrefix, parammeter);


                return(list);
            }
            catch (Exception ex)
            {
                FileLogger.FileLogger.Instance.WriteExeption(ex);
                return(list);
            }
        }