Esempio n. 1
0
        static void Main(string[] args)
        {
            //How to convert PDF to 1-bit black and white PNG
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";

            string pdfPath   = @"..\..\..\..\..\simple text.pdf";
            string imagePath = Path.ChangeExtension(pdfPath, ".png");

            f.OpenPdf(pdfPath);

            if (f.PageCount > 0)
            {
                //save 1st page to png file, 120 dpi
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
                f.ImageOptions.Dpi         = 120;
                //Make "Black and White 1-bit indexed" image
                f.ImageOptions.ColorDepth = SautinSoft.PdfFocus.CImageOptions.eColorDepth.BlackWhite1bpp;

                if (f.ToImage(imagePath, 1) == 0)
                {
                    // 0 - converting successfully
                    // 2 - can't create output file, check the output path
                    // 3 - converting failed
                    System.Diagnostics.Process.Start(imagePath);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string pdfPath   = @"..\..\..\..\..\simple text.pdf";
            string imagePath = Path.ChangeExtension(pdfPath, ".png");

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";
            f.OpenPdf(pdfPath);

            if (f.PageCount > 0)
            {
                //Set color depth: Grayscale 24 bit
                f.ImageOptions.ColorDepth = SautinSoft.PdfFocus.CImageOptions.eColorDepth.Grayscale24bpp;

                //Convert 1st page from PDF to image file
                if (f.ToImage(imagePath, 1) == 0)
                {
                    // 0 - converting successfully
                    // 2 - can't create output file, check the output path
                    // 3 - converting failed
                    System.Diagnostics.Process.Start(imagePath);
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            string pdfPath   = @"..\..\simple text.pdf";
            string imagePath = "Result.gif";

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";
            f.OpenPdf(pdfPath);

            if (f.PageCount > 0)
            {
                //Set "GIF" format for image
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;

                //Convert 1st page from PDF to image file
                if (f.ToImage(imagePath, 1) == 0)
                {
                    // 0 - converting successfully
                    // 2 - can't create output file, check the output path
                    // 3 - converting failed
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(imagePath)
                    {
                        UseShellExecute = true
                    });
                }
            }
        }
Esempio n. 4
0
        public ActionResult getData(string category, string name, string equation, HttpPostedFileBase file)
        {
            string fileName = category + name;
            string path = "";
            string pathOfFolder = "";
            p = new Picture(category, name, equation, file);
            Vuforia v;
            if (file.ContentLength > 0)
            {

                path = Path.Combine(Server.MapPath("~/Content/images"), fileName);
                pathOfFolder = Server.MapPath("~/Content/images") + "\\";
                file.SaveAs(path);
            }

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            f.OpenPdf(path);

            if (f.PageCount > 0)
            {
                f.ImageOptions.Dpi = 300;
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

                for (int page = 1; page <= f.PageCount; page++)
                {
                    f.ToImage(pathOfFolder + "MyPDFImage.jpg", page);
                }
            }

            return View("TargetSelection");
            //v = new Vuforia(fileName, path);
            //v.postTarget();
        }
Esempio n. 5
0
        private Bitmap[] PdfToImage(string pdfPath)
        {
            Log("Inizio conversione PDF -> Immagine");
            List <Bitmap> images = new List <Bitmap>();

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            string jpegDir = System.IO.Path.GetDirectoryName(pdfPath);

            f.OpenPdf(pdfPath);

            if (f.PageCount > 0)
            {
                f.ImageOptions.ImageFormat = ImageFormat.Jpeg;
                f.ImageOptions.Dpi         = 300;
                f.ImageOptions.JpegQuality = 100;

                for (int page = 1; page <= f.PageCount; page++)
                {
                    byte[] imageData = f.ToImage(page);
                    var    ms        = new MemoryStream(imageData);
                    images.Add(new Bitmap(ms));
                    Log("Convertita immagine n°" + page);
                }
            }

            Log("Finita conversione PDF");

            return(images.ToArray());
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            //Convert PDF into specified Image height & width
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";

            // Set initial values
            string pdfPath     = @"..\..\..\..\..\simple text.pdf";
            string imageFolder = Path.GetDirectoryName(pdfPath);
            int    width       = 1600; // Width in Px
            int    height      = 1900; // Height in Px

            //Set image options
            f.ImageOptions.ImageFormat = ImageFormat.Png;
            f.ImageOptions.Resize(new Size {
                Width = width, Height = height
            }, false);


            f.OpenPdf(pdfPath);
            if (f.PageCount > 0)
            {
                // Convert all pages to PNG images
                f.ToImage(imageFolder, "Page");

                //Show image
                System.Diagnostics.Process.Start(imageFolder);
            }
        }
Esempio n. 7
0
        public ActionResult getData(string category, string name, string equation, HttpPostedFileBase file)
        {
            string fileName     = category + name;
            string path         = "";
            string pathOfFolder = "";

            p = new Picture(category, name, equation, file);
            Vuforia v;

            if (file.ContentLength > 0)
            {
                path         = Path.Combine(Server.MapPath("~/Content/images"), fileName);
                pathOfFolder = Server.MapPath("~/Content/images") + "\\";
                file.SaveAs(path);
            }

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            f.OpenPdf(path);

            if (f.PageCount > 0)
            {
                f.ImageOptions.Dpi         = 300;
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

                for (int page = 1; page <= f.PageCount; page++)
                {
                    f.ToImage(pathOfFolder + "MyPDFImage.jpg", page);
                }
            }

            return(View("TargetSelection"));
            //v = new Vuforia(fileName, path);
            //v.postTarget();
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            //Convert PDF files to 300-dpi TIFF files
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";

            string[] pdfFiles        = Directory.GetFiles(@"..\..\..\..\..\", "*.pdf");
            string   folderWithTiffs = @"..\..\..\..\..\";

            foreach (string pdffile in pdfFiles)
            {
                f.OpenPdf(pdffile);

                if (f.PageCount > 0)
                {
                    //Set image format: TIFF, 300 dpi
                    f.ImageOptions.Dpi         = 300;
                    f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;

                    //Save all pages to tiff files with 300 dpi
                    f.ToImage(folderWithTiffs, Path.GetFileNameWithoutExtension(pdffile));
                }
                f.ClosePdf();
            }
            //Show folder with tiffs
            System.Diagnostics.Process.Start(folderWithTiffs);
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            string pdfPath   = @"..\..\simple text.pdf";
            string imagePath = "Result.png";

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";
            f.OpenPdf(pdfPath);

            if (f.PageCount > 0)
            {
                //In most cases we recommend to set 200 dpi to decrease the image size and converting speed
                //Now set 300 dpi - very high quality
                f.ImageOptions.Dpi = 300;

                //Convert 1st page from PDF to image file
                if (f.ToImage(imagePath, 1) == 0)
                {
                    // 0 - converting successfully
                    // 2 - can't create output file, check the output path
                    // 3 - converting failed
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(imagePath)
                    {
                        UseShellExecute = true
                    });
                }
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            // Convert PDF 1st page to PNG file.
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            // this property is necessary only for registered version.
            //f.Serial = "XXXXXXXXXXX";

            string pdfPath   = @"..\..\..\..\..\simple text.pdf";
            string imagePath = Path.ChangeExtension(pdfPath, ".png");

            f.OpenPdf(pdfPath);

            if (f.PageCount > 0)
            {
                //save 1st page to png file, 120 dpi
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
                f.ImageOptions.Dpi         = 120;
                if (f.ToImage(imagePath, 1) == 0)
                {
                    // 0 - converting successfully
                    // 2 - can't create output file, check the output path
                    // 3 - converting failed
                    System.Diagnostics.Process.Start(imagePath);
                }
            }
        }
Esempio n. 11
0
        public string LerArquivoPdf(Stream streamPdf)
        {
            string pdfPath = Path.Combine(Directory.GetCurrentDirectory(), "tmp", $"tmp-pdf-{Guid.NewGuid()}.pdf");

            using (var fileStream = File.Create(pdfPath))
            {
                streamPdf.Seek(0, SeekOrigin.Begin);
                streamPdf.CopyTo(fileStream);
            }

            try
            {
                SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
                f.OpenPdf(pdfPath);
                int pageCount = f.PageCount;

                if (f.PageCount > 0)
                {
                    //Set image properties: Jpeg, 200 dpi
                    f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                    f.ImageOptions.Dpi         = 300;

                    string pathImage = Path.Combine(Directory.GetCurrentDirectory(), "tmp");
                    string nameImage = $"tmp-img-{Guid.NewGuid()}_";

                    try
                    {
                        //Save all PDF pages as page1.jpg, page2.jpg ... pageN.jpg
                        f.ToImage(Path.Combine(Directory.GetCurrentDirectory(), "tmp"), nameImage);


                        string res = LerArquivoImagem(Path.Combine(pathImage, nameImage + "1.jpg"));
                        f.ClosePdf();

                        File.Delete(pdfPath);
                        File.Delete(Path.Combine(pathImage, nameImage + "1.jpg"));
                        return(res);
                    }
                    catch (Exception e)
                    {
                        File.Delete(pdfPath);
                        File.Delete(Path.Combine(pathImage, nameImage + "1.jpg"));
                        Debug.WriteLine(e.Message);
                        return($"Erro ao tentar ler resultado do documento enviado, erro: {e.Message}");
                    }
                }

                return("");
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return($"Erro ao tentar ler resultado do documento enviado, erro: {e.Message}");
            }
        }
Esempio n. 12
0
        private static void test4()
        {
            // Open document
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            f.OpenPdf(System.IO.File.ReadAllBytes("template.pdf"));
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";


            if (f.PageCount > 0)
            {
                //set image properties
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                f.ImageOptions.Dpi         = 300;

                //Let's convert 1st page from PDF document
                byte[] image = f.ToImage(1);

                f.ToImage("image2_out.jpg", 1);
            }
        }
Esempio n. 13
0
        public static List <Image> pdfToImages(String pdfPath, int idProjet)
        {
            List <Image> images = new List <Image>();

            // Convert PDF to JPG with high Quality
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            // This property is necessary only for registered version
            // f.Serial = "XXXXXXXXXXX";

            string pdfName = Path.GetFileNameWithoutExtension(pdfPath);
            string pdfDir  = Path.GetDirectoryName(pdfPath);
            String jpegDir = ConfigurationManager.AppSettings["MainFolder"].ToString();


            f.OpenPdf(pdfPath);

            if (f.PageCount > 0)
            {
                // Set image properties: Jpeg, 200 dpi
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                f.ImageOptions.Dpi         = 200;

                // Set 95 as JPEG quality
                f.ImageOptions.JpegQuality = 95;

                //Save all PDF pages to image folder, each file will have name Page 1.jpg, Page 2.jpg, Page N.jpg
                for (int page = 1; page <= f.PageCount; page++)
                {
                    string jpegFile = Path.Combine(jpegDir, String.Format(pdfName + " page {0}.jpg", page));
                    Image  image    = new Image(jpegFile, mainForm.utilisateur.idUtilisateur, idProjet);

                    // 0 - converted successfully
                    // 2 - can't create output file, check the output path
                    // 3 - conversion failed
                    int result = f.ToImage(jpegFile, page);
                    if (result.Equals(0))
                    {
                        images.Add(image);
                    }
                    else
                    {
                        Console.WriteLine("error");
                    }
                }
                return(images);
            }
            return(null);
        }
        private String convertPDFtoJPG(string filePDFFullName)
        {
            int    len          = filePDFFullName.LastIndexOf(".");
            string fileLocation = filePDFFullName.Substring(0, len) + ".jpg";

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            f.OpenPdf(@filePDFFullName);
            if (f.PageCount > 0)
            {
                f.ImageOptions.Dpi         = 300;
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                f.ToImage(fileLocation, 1);
            }
            f.ClosePdf();
            return(fileLocation);
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            f.OpenPdf(@"D:\Integra training\fileConversion\scansmpl.pdf");

            if (f.PageCount > 0)
            {
                f.ImageOptions.Dpi         = 200;
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

                for (int page = 1; page <= f.PageCount; page++)
                {
                    f.ToImage(@"D:\Integra training\fileConversion\images\" + "page" + page + ".jpg", page);
                }
                Console.ReadKey();
            }
        }
Esempio n. 16
0
        private String convertPDFtoJPG(string fileNameInp, string str)
        {
            string fileLocation = "";
            string fileNameOut  = str;

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            f.OpenPdf(@fileNameInp);
            if (f.PageCount > 0)
            {
                f.ImageOptions.Dpi         = 300;
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

                int    len      = openFileDialog1.SafeFileName.LastIndexOf(".");
                string fileName = openFileDialog1.SafeFileName.Substring(0, len);
                fileLocation = @fileNameOut + fileName + ".jpg";
                f.ToImage(fileLocation, 1);
            }
            f.ClosePdf();
            return(fileLocation);
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            // Convert PDF to JPG with high Quality
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            // This property is necessary only for registered version
            // f.Serial = "XXXXXXXXXXX";
            string pdfFile = @"..\..\..\..\..\simple text.pdf";
            string jpegDir = Path.GetDirectoryName(pdfFile);

            f.OpenPdf(pdfFile);

            if (f.PageCount > 0)
            {
                // Set image properties: Jpeg, 200 dpi
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                f.ImageOptions.Dpi         = 200;

                // Set 95 as JPEG quality
                f.ImageOptions.JpegQuality = 95;

                //Save all PDF pages to image folder, each file will have name Page 1.jpg, Page 2.jpg, Page N.jpg
                for (int page = 1; page <= f.PageCount; page++)
                {
                    string jpegFile = Path.Combine(jpegDir, String.Format("Page {0}.jpg", page));

                    // 0 - converted successfully
                    // 2 - can't create output file, check the output path
                    // 3 - conversion failed
                    int result = f.ToImage(jpegFile, page);

                    // Show only 1st page
                    if (page == 1 && result == 0)
                    {
                        System.Diagnostics.Process.Start(jpegFile);
                    }
                }
            }
        }
Esempio n. 18
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.PostedFile.FileName.Length == 0 || FileUpload1.FileBytes.Length == 0)
        {
            Result.Text = "Please select PDF file at first!";
            return;
        }
        Result.Text = "Converting ...";

        SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
        //this property is necessary only for registered version
        //f.Serial = "XXXXXXXXXXX";

        f.OpenPdf(FileUpload1.FileBytes);

        if (f.PageCount > 0)
        {
            //set image properties
            f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            f.ImageOptions.Dpi         = 200;

            //Let's convert 1st page from PDF document
            byte[] image = f.ToImage(1);

            //show image
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "image/jpeg";
            Response.AddHeader("Content-Disposition:", "attachment; filename=Page1.jpg");
            Response.BinaryWrite(image);
            Response.Flush();
            Response.End();
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }
Esempio n. 19
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.PostedFile.FileName.Length == 0 || FileUpload1.FileBytes.Length == 0)
        {
            Result.Text = "Please select PDF file at first!";
            return;
        }

        SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
        //this property is necessary only for registered version
        //f.Serial = "XXXXXXXXXXX";

        f.OpenPdf(FileUpload1.FileBytes);

        if (f.PageCount > 0)
        {
            //set image properties
            f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
            f.ImageOptions.Dpi         = 72;

            //Let's convert whole PDF document
            ArrayList pages = f.ToImage();

            //Show images
            if (pages.Count > 0)
            {
                int width    = 3;
                int imgWidth = 300;

                HtmlTable table = new HtmlTable();
                table.Border      = 1;
                table.CellPadding = 3;
                table.CellSpacing = 3;

                HtmlTableRow  row;
                HtmlTableCell cell;
                HtmlImage     img;

                string imagePath = Server.MapPath("~");
                string imageName = "Page";

                row = new HtmlTableRow();
                int count = 0;
                foreach (byte[] page in pages)
                {
                    count++;
                    string src = imageName + count.ToString() + ".png";
                    File.WriteAllBytes(Path.Combine(imagePath, src), page);

                    cell = new HtmlTableCell();
                    cell.Style.Add("vertical-align", "top");
                    img = new HtmlImage();

                    img.Src        = src;
                    img.Width      = imgWidth;
                    cell.InnerHtml = "<div align=\"center\">Page" + count.ToString() + "</div>";

                    cell.Controls.Add(img);
                    row.Cells.Add(cell);

                    if (count % width == 0)
                    {
                        table.Rows.Add(row);
                        row = new HtmlTableRow();
                    }
                }
                table.Rows.Add(row);
                this.Controls.Add(table);
            }
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }