Exemplo n.º 1
0
        public static Dictionary<int, string> PDFToImage(string file, string outputPath, int dpi)
        {


            string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            Ghostscript.NET.Rasterizer.GhostscriptRasterizer rasterizer = null;
            Ghostscript.NET.GhostscriptVersionInfo vesion = new Ghostscript.NET.GhostscriptVersionInfo(new System.Version(0, 0, 0), path + @"\gsdll64.dll", string.Empty, Ghostscript.NET.GhostscriptLicense.GPL);

            Dictionary<int, string> dictionary = new Dictionary<int, string>();

            using (rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
            {
                rasterizer.Open(file, vesion, false);

                for (int i = 1; i <= rasterizer.PageCount; i++)
                {
                    string pageFilePath = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(@file).Replace(".pdf", "") + "-p" + i.ToString() + ".tiff");

                    using (System.Drawing.Image img = rasterizer.GetPage(dpi, dpi, i))
                    {
                        
                            if (File.Exists(pageFilePath))
                            {
                              

                                //img.Save(pageFilePath, System.Drawing.Imaging.ImageFormat.Tiff);
                                dictionary.Add(i, pageFilePath);

                            }
                            else
                            {
                                img.Save(pageFilePath, System.Drawing.Imaging.ImageFormat.Tiff);
                                dictionary.Add(i, pageFilePath);
                                
                            }
                       
                            
                      
                    }
                    
                }
                rasterizer.Close();
                rasterizer.Dispose();

             
            }
            return dictionary;
        }