Esempio n. 1
0
        static void Main(string[] args)
        {
            byte[] pdfBytes = File.ReadAllBytes(@"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages.pdf");

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

            f.OpenPdf(pdfBytes);

            if (f.PageCount > 0)
            {
                byte[] word = f.ToWord();
                System.IO.File.WriteAllBytes(@"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages_sautinSoft.rtf", word);

                f.HtmlOptions.IncludeImageInHtml = true;
                f.HtmlOptions.InlineCSS          = true;
                string html = f.ToHtml();

                System.IO.File.WriteAllText(@"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages_sautinSoft.html", html);

                //Console.WriteLine(html);
                //Console.WriteLine("In base64 rtf: {0}", Convert.ToBase64String(word));

                string rez = GetText(@"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages.pdf");
                System.IO.File.WriteAllText(@"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages_iTextSharp.txt", rez);
                System.IO.File.WriteAllText(@"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages_iTextSharp.rtf", rez);


                string rHTML = ConvertPdf(@"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages.pdf", @"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages_iTextSharp.html");


                //string spireReturn = SpirePDF(@"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages.pdf", @"C:\Users\adit.shah\source\repos\aditshh\RTFToPDF\SampleFile\sampleWithImages_SpirePDF.html");
                Console.ReadLine();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            #region Property
            //Put your pdf file path
            string pathToPdf  = @"C:/Users/dhire/Downloads/Compressed/Convert PDF file to HTML file in C# - Step by Step/table.pdf";
            string pathToHtml = Path.ChangeExtension(pathToPdf, ".htm");

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

            #region Declaration
            f.HtmlOptions.IncludeImageInHtml = true;
            f.HtmlOptions.Title = "Simple text";

            f.OpenPdf(pathToPdf);

            if (f.PageCount > 0)
            {
                int result = f.ToHtml(pathToHtml);

                if (result == 0)
                {
                    System.Diagnostics.Process.Start(pathToHtml);
                }
            }

            #endregion
        }
Esempio n. 3
0
        private static void ConvertPdfStreamToHtml()
        {
            string pathToPdf  = @"..\..\..\..\..\simple text.pdf";
            string pathToHtml = Path.ChangeExtension(pathToPdf, ".htm");

            // This list will be filled by images after the PDF to HTML conversion.
            List <Image> imgCollection = new List <Image>();

            // Convert PDF to HTML in memory
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            // Let's force the component to store images inside HTML document
            // using base-64 encoding.
            // Thus the component will not use HDD.
            f.HtmlOptions.IncludeImageInHtml = true;
            f.HtmlOptions.Title     = "Simple text";
            f.HtmlOptions.InlineCSS = true;

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

            // Read a PDF document to byte array
            // Assume that we have a PDF document as Stream.

            using (FileStream fs = File.OpenRead(pathToPdf))
            {
                f.OpenPdf(fs);

                if (f.PageCount > 0)
                {
                    // Convert PDF to HTML string.
                    string html = f.ToHtml(1, f.PageCount, imgCollection);

                    // Show info about images.
                    Console.WriteLine("After converting we've got {0} image(s):", imgCollection.Count);
                    foreach (Image img in imgCollection)
                    {
                        Console.WriteLine("\t {0,4} x {1,4} px", img.Width, img.Height);
                    }

                    Console.WriteLine("Press any key ...");
                    Console.ReadLine();

                    // Save HTML to a file only for demonstration purposes.
                    if (html != null)
                    {
                        File.WriteAllText(pathToHtml, html);
                        System.Diagnostics.Process.Start(pathToHtml);
                    }
                }
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // Convert PDF to separate HTMLs.
            // Each PDF page will be converted to a single HTML document.
            string        pdfFile = @"..\..\simple text.pdf";
            DirectoryInfo htmlDir = new DirectoryInfo("htmls");

            if (!htmlDir.Exists)
            {
                htmlDir.Create();
            }

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

            // This property is necessary only for licensed version.
            //f.Serial = "XXXXXXXXXXX";
            f.HtmlOptions.IncludeImageInHtml = false;

            // Path (must exist) to a directory to store images after converting.
            f.HtmlOptions.ImageFolder = htmlDir.FullName;

            f.OpenPdf(pdfFile);

            if (f.PageCount > 0)
            {
                // Convert each PDF page to separate HTML document.
                // simple text.html, simple text.html ... simple text.html.
                for (int page = 1; page <= f.PageCount; page++)
                {
                    f.HtmlOptions.Title          = $"Page {page}";
                    f.HtmlOptions.ImageSubFolder = String.Format("page{0}_images", page);
                    string htmlString = f.ToHtml(page, page);

                    // Save htmlString to file
                    string htmlFile = Path.Combine(htmlDir.FullName, $"Page{page}.html");
                    File.WriteAllText(htmlFile, htmlString);

                    // Let's open only 1st and last pages.
                    if (page == 1 || page == f.PageCount)
                    {
                        // Open the result for demonstration purposes.
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlFile)
                        {
                            UseShellExecute = true
                        });
                    }
                }
            }
        }
Esempio n. 5
0
        private static void ConvertPdfStreamToHtml()
        {
            // We need files only for demonstration purposes.
            // The whole conversion process will be done in memory.

            string templateFile = "/Users/user/Downloads/1022out.pdf";
            string outFile      = "/Users/user/Downloads/1022out.html";


            // Convert PDF to HTML in memory
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

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

            // Let's force the component to store images inside HTML document
            // using base-64 encoding.
            // Thus the component will not use HDD.
            f.HtmlOptions.IncludeImageInHtml = true;
            f.HtmlOptions.Title = "Simple text";

            // Assume that we have a PDF document as Stream.
            using (FileStream fs = File.OpenRead(templateFile))
            {
                f.OpenPdf(fs);

                if (f.PageCount > 0)
                {
                    // Convert PDF to HTML to a MemoryStream.
                    using (MemoryStream msHtml = new MemoryStream())
                    {
                        int res = f.ToHtml(msHtml);
                        // Open the result for demonstation purposes.
                        if (res == 0)
                        {
                            File.WriteAllBytes(outFile, msHtml.ToArray());
                            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                            {
                                UseShellExecute = true
                            });
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        private static void ConvertPdfBytesToHtml()
        {
            // We need files only for demonstration purposes.
            // The whole conversion process will be done in memory.
            string pdfFile  = @"..\..\simple text.pdf";
            string htmlFile = "Result.html";

            // Convert PDF to HTML in memory
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

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

            // Let's force the component to store images inside HTML document
            // using base-64 encoding.
            // Thus the component will not use HDD.
            f.HtmlOptions.IncludeImageInHtml = true;
            f.HtmlOptions.Title = "Simple text";

            // Read a PDF document to byte array
            // Assume that we already have the  PDF as array of bytes.
            byte[] pdf = File.ReadAllBytes(pdfFile);

            f.OpenPdf(pdf);

            if (f.PageCount > 0)
            {
                // Convert PDF to HTML in memory
                string html = f.ToHtml();

                // Save HTML to the file only for demonstration purpose.
                if (html != null)
                {
                    File.WriteAllText(htmlFile, html);
                    // Open the result for demonstration purposes.
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlFile)
                    {
                        UseShellExecute = true
                    });
                }
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            // Convert PDF to separate HTMLs.
            // Each PDF page will be converted to a single HTML document.

            // Path to PDF file.
            string pdfPath = Path.GetFullPath(@"..\..\..\..\..\simple text.pdf");

            // Directory to store HTML documents.
            string htmlDir = Path.GetDirectoryName(pdfPath);

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

            f.HtmlOptions.IncludeImageInHtml = false;
            // Path (must exist) to a directory to store images after converting. Notice also to the property "ImageSubFolder".
            f.HtmlOptions.ImageFolder = htmlDir;

            f.OpenPdf(pdfPath);

            // Convert each PDF page to separate HTML document.
            // simple text.html, simple text.html ... simple text.html.
            for (int page = 1; page <= f.PageCount; page++)
            {
                f.HtmlOptions.Title          = String.Format("Simple Text - Page {0}", page);
                f.HtmlOptions.ImageSubFolder = String.Format("images-page{0}", page);
                string htmlString = f.ToHtml(page, page);

                // Save htmlString to file
                string htmlPath = Path.Combine(htmlDir, String.Format("Page{0}.html", page));
                File.WriteAllText(htmlPath, htmlString);

                // Let's show first and last HTML pages.
                if (page == 1 || page == f.PageCount)
                {
                    System.Diagnostics.Process.Start(htmlPath);
                }
            }
        }
Esempio n. 8
0
        private static void ConvertPdfStreamToHtml()
        {
            string pathToPdf  = @"..\..\..\..\..\simple text.pdf";
            string pathToHtml = Path.ChangeExtension(pathToPdf, ".htm");

            // Convert PDF to HTML in memory
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            // Let's force the component to store images inside HTML document
            // using base-64 encoding.
            // Thus the component will not use HDD.
            f.HtmlOptions.IncludeImageInHtml = true;
            f.HtmlOptions.Title     = "Simple text";
            f.HtmlOptions.InlineCSS = true;

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

            // Read a PDF document to byte array
            // Assume that we have a PDF document as Stream.

            using (FileStream fs = File.OpenRead(pathToPdf))
            {
                f.OpenPdf(fs);

                if (f.PageCount > 0)
                {
                    // Convert PDF to HTML string.
                    string html = f.ToHtml();

                    // Save HTML to a file only for demonstration purposes.
                    if (html != null)
                    {
                        File.WriteAllText(pathToHtml, html);
                        System.Diagnostics.Process.Start(pathToHtml);
                    }
                }
            }
        }
        public Task ConvertPDFToHTML()
        {
            var tcs = new TaskCompletionSource <int>();

            this.htmlPath = string.Empty;
            SautinSoft.PdfFocus f = null;

            try
            {
                this.htmlPath = GetTempFolderPath() + DateTime.Now.ToFileTime() + ".html";

                this.master.bi.LogBusyProgress("Openning pdf file..");
                f = new SautinSoft.PdfFocus();
                f.OpenPdf(inputFilePath);

                if (f.PageCount > 0)
                {
                    this.master.bi.LogBusyProgress("Converting pdf to html..");
                    f.ToHtml(htmlPath);
                }
            }
            catch (Exception ex)
            {
                this.master.bi.BusyOff();
                this.htmlPath = string.Empty;
                Helper.LogError(this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (f != null)
                {
                    f.ClosePdf();
                }
            }

            return(tcs.Task);
        }
        public ActionResult Index(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var getfileextension = System.IO.Path.GetExtension(file.FileName);

                if (string.IsNullOrEmpty(getfileextension) || getfileextension != ".pdf")
                {
                    ViewBag.Message = "Only pdf file allow to convert.";
                }
                else
                {
                    try
                    {
                        //Get the File Name. Remove space characters from File Name.
                        string fileName = file.FileName.Replace(" ", string.Empty);

                        var filename = System.IO.Path.GetFileNameWithoutExtension(fileName);

                        var tickervalue     = DateTime.Now.Ticks;
                        var newpdffilename  = string.Format("{0}{1}{2}", filename, tickervalue, ".pdf");
                        var newhtmlfilename = string.Format("{0}{1}{2}", filename, tickervalue, ".html");

                        //Save the PDF file.

                        var brieffile = "brief_1/";
                        var lastrec   = _context.tblBriefs.OrderByDescending(o => o.Id).FirstOrDefault();

                        if (lastrec != null)
                        {
                            brieffile = "brief_" + (lastrec.Id + 1) + "/";
                        }

                        var brieffilepath = Server.MapPath("~/htmlfiles/") + brieffile;

                        if (!Directory.Exists(brieffilepath))
                        {
                            Directory.CreateDirectory(brieffilepath);
                        }

                        string inputPath      = brieffilepath + newpdffilename;
                        string outputhtmlPath = brieffilepath + newhtmlfilename;

                        file.SaveAs(inputPath);

                        #region Convert Html using Sautinsoft

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

                        f.EmbeddedImagesFormat                     = SautinSoft.PdfFocus.eImageFormat.Auto;
                        f.HtmlOptions.IncludeImageInHtml           = true;
                        f.HtmlOptions.InlineCSS                    = true;
                        f.HtmlOptions.RenderMode                   = SautinSoft.PdfFocus.CHtmlOptions.eHtmlRenderMode.Fixed;
                        f.HtmlOptions.UseNumericCharacterReference = true;
                        f.HtmlOptions.KeepCharScaleAndSpacing      = true;
                        f.OpenPdf(inputPath);

                        if (f.PageCount > 0)
                        {
                            int res = f.ToHtml(outputhtmlPath);
                        }

                        #endregion

                        #region save data in brief table
                        tblBrief tbl = new tblBrief()
                        {
                            FileName    = Path.GetFileNameWithoutExtension(newhtmlfilename),
                            FilePath    = "~/htmlfiles/" + brieffile,
                            CreatedDate = DateTime.UtcNow
                        };

                        _context.tblBriefs.Add(tbl);
                        _context.SaveChanges();
                        #endregion

                        ViewBag.Message       = "File uploaded and converted";
                        ViewBag.generatedfile = newhtmlfilename;
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    }
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }

            var AllDataList = _context.tblBriefs.OrderByDescending(o => o.CreatedDate).ToList();

            return(View(AllDataList));
        }
Esempio n. 11
0
        private static void ConvertPdfBytesToHtml()
        {
            // We need files only for demonstration purposes.
            // The whole conversion process will be done in memory.
            string pdfFile  = @"..\..\simple text.pdf";
            string htmlFile = "Result.htm";

            // This is the list with extracted images.
            // It will be filled by images after the conversion.
            List <Image> imgCollection = new List <Image>();

            // Convert PDF to HTML in memory
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

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

            // Let's force the component to store images inside HTML document
            // using base-64 encoding.
            // Thus the component will not use HDD.
            f.HtmlOptions.IncludeImageInHtml = true;
            f.HtmlOptions.Title = "Simple text";


            // Read a PDF document to byte array.
            // Assume that we already have the  PDF as array of bytes.
            byte[] pdf = File.ReadAllBytes(pdfFile);

            f.OpenPdf(pdf);

            if (f.PageCount > 0)
            {
                // Convert PDF to HTML in memory
                string htmlString = f.ToHtml(1, f.PageCount, imgCollection);

                // Save HTML to a file only for the demonstration purpose.
                if (htmlString != null)
                {
                    // Show info about images and save them
                    Console.WriteLine("After converting we've got {0} image(s):", imgCollection.Count);
                    DirectoryInfo imgDir = new DirectoryInfo("Extracted Images");
                    if (!imgDir.Exists)
                    {
                        imgDir.Create();
                    }

                    int count = 1;
                    foreach (Image img in imgCollection)
                    {
                        Console.WriteLine("\t {0,4} x {1,4} px", img.Width, img.Height);
                        string imageFileName = Path.Combine(imgDir.FullName, String.Format($"pict{count}.jpg"));
                        img.Save(imageFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        count++;
                    }
                    // Open the result for demonstration purposes.
                    File.WriteAllText(htmlFile, htmlString);
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlFile)
                    {
                        UseShellExecute = true
                    });
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(imgDir.FullName)
                    {
                        UseShellExecute = true
                    });
                }
            }
        }
Esempio n. 12
0
        public ActionResult UploadEdit(string[] FormatTags, string[] Pseudonyms, HttpPostedFileBase file, FormCollection form, [Bind(Include = "ProfileID, Title, LikesOn," +
                                                                                                                                               "CommentsOn, CritiqueOn, DescriptionText")] Writing doc)
        {
            String FileExt = Path.GetExtension(file.FileName).ToUpper();

            if (CheckExtEdit(FileExt))
            {
                AccessPermission ap = new AccessPermission()
                {
                    PublicAccess    = form["PublicAccess"] != null ? true : false,
                    FriendAccess    = form["FriendAccess"] != null ? true : false,
                    PublisherAccess = form["PublisherAccess"] != null ? true : false,
                    MinorAccess     = form["MinorAccess"] != null ? true : false
                };
                db.AccessPermissions.Add(ap);
                db.SaveChanges();

                if (!ModelState.IsValid)
                {
                    Stream       str        = file.InputStream;
                    BinaryReader Br         = new BinaryReader(str);
                    Byte[]       FileData   = Br.ReadBytes((Int32)str.Length);
                    string       html       = string.Empty;
                    string[]     namestring = file.FileName.Split('.');

                    if (FileExt == ".PDF" || FileExt == "PDF")
                    {
                        SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
                        f.OpenPdf(FileData);

                        if (f.PageCount > 0)
                        {
                            f.HtmlOptions.IncludeImageInHtml = true;
                            f.HtmlOptions.Title = "Simple text";
                            html = f.ToHtml();
                        }
                    }
                    else if (FileExt == ".DOCX" || FileExt == "DOCX" || FileExt == ".DOC" || FileExt == "DOC")
                    {
                        html = ConvertToHtml(Path.GetFullPath(file.FileName));
                    }
                    else
                    {
                        ViewBag.FileStatus = "Model Invalid";
                        return(View());
                    }

                    Writing wr = new Writing()
                    {
                        ProfileID          = Int32.Parse(form["ProfileID"]),
                        AccessPermissionID = ap.AccessPermissionID,
                        Title      = form["Title"],
                        AddDate    = DateTime.Now,
                        EditDate   = null,
                        LikesOn    = form["LikesOn"] != null ? true : false,
                        CommentsOn = form["CommentsOn"] != null ? true : false,
                        CritiqueOn = form["CritiqueOn"] != null ? true : false,
                        UsePseudonymsInAdditionToUsername = form["UsePseudonymsInAdditionToUsername"] != null ? true : false,
                        DocType         = ".HTML",
                        DescriptionText = form["DescriptionText"],
                        Document        = Encoding.Unicode.GetBytes(html),
                        WritingFileName = namestring[0] + ".html"
                    };
                    db.Writings.Add(wr);
                    db.SaveChanges();

                    int id = wr.WritingID;

                    ap                 = db.AccessPermissions.Find(ap.AccessPermissionID);
                    ap.WritingID       = id;
                    db.Entry(ap).State = EntityState.Modified;
                    db.SaveChanges();

                    if (FormatTags != null)
                    {
                        foreach (var selection in FormatTags)
                        {
                            WritingFormat wf = new WritingFormat()
                            {
                                WritingID = id,
                                FormatID  = Int32.Parse(selection)
                            };
                            db.WritingFormats.Add(wf);
                            db.SaveChanges();
                        }
                    }

                    if (Pseudonyms != null)
                    {
                        foreach (var selection in Pseudonyms)
                        {
                            WritingPseudonym wp = new WritingPseudonym()
                            {
                                WritingID   = id,
                                PseudonymID = Int32.Parse(selection)
                            };
                            db.WritingPseudonyms.Add(wp);
                            db.SaveChanges();
                        }
                    }


                    return(RedirectToAction("Index", "Home", new { @id = id }));
                }
                else
                {
                    ViewBag.FileStatus = "File Type Not valid: Valid file type for edit is currently .PDF";
                    return(View());
                }
            }
            else
            {
                ViewBag.FileStatus = "Invalid file format.";
                return(View());
            }
        }