Esempio n. 1
0
        public ActionResult ConvertToPDF(string viewName, object model, bool inline=false)
        {
            var v = new SautinSoft.PdfVision();
            v.PageStyle.PageSize.A4();

            string html = RenderViewToString(viewName, model);

            var pdfBytes = v.ConvertHtmlStringToPDFStream(html);
            //if(inline)
            //{
                Response.AppendHeader("Content-Disposition", "inline");
            //}
            return File(pdfBytes, "application/pdf", "Portfolio.pdf");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Convert Image class to PDF file
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();

            //v.Serial = "XXXXXXXXXXXXXXX";

            //specify converting options
            v.PageStyle.PageSize.Auto();

            //v.PageStyle.PageMarginLeft.Inch(1);
            //v.ImageStyle.Heightmm(150);
            //v.ImageStyle.WidthInch(10);

            // Create object of Image class from file
            System.Drawing.Image image   = Image.FromFile(@"..\..\image-jpeg.jpg");
            FileInfo             outFile = new FileInfo(@"Result.pdf");

            byte[] imgBytes = null;

            using (MemoryStream ms = new System.IO.MemoryStream())
            {
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                imgBytes = ms.ToArray();
            }

            // Convert image stream to PDF file
            int ret = v.ConvertImageStreamToPDFFile(imgBytes, outFile.FullName);

            if (ret == 0)
            {
                // Open the resulting PDF document in a default PDF Viewer.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName)
                {
                    UseShellExecute = true
                });
            }
        }
Esempio n. 3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        SautinSoft.PdfVision v = new SautinSoft.PdfVision();

        byte[] tiffBytes = null;
        byte[] pdfBytes  = null;

        if (FileUpload1.FileBytes.Length > 0)
        {
            // get bytes from image
            tiffBytes = FileUpload1.FileBytes;
        }

        else
        {
            Result.Text = "Please select image file at first!";
        }

        // convert image stream to pdf stream
        pdfBytes = v.ConvertImageStreamToPdfStream(tiffBytes);

        // show PDF
        if (pdfBytes != null)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "application/PDF";
            // Response.AddHeader("content-disposition", "attachment; filename=Result.pdf");
            Response.AddHeader("content-disposition", "inline; filename=Result.pdf");
            Response.BinaryWrite(pdfBytes);
            Response.Flush();
            Response.End();
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }
Esempio n. 4
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        SautinSoft.PdfVision v = new SautinSoft.PdfVision();

        // Set "Edge mode" to support all modern CSS.
        SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry();

        // Specify top and bottom page margins
        v.PageStyle.PageMarginTop.Mm(5f);
        v.PageStyle.PageMarginBottom.Mm(5f);

        v.PageStyle.PageSize.A4();

        // Be sure that your HTML string has full paths to images and *.css
        // Correct: <img src="http://www.mysite.com/image1.jpg">
        // Incorrect: <img src="../images/image1.jpg">

        string html = ReadFileString(Path.Combine(Server.MapPath(""), "test.htm"));

        byte[] pdfBytes = null;

        // convert html string to pdf stream
        pdfBytes = v.ConvertHtmlStringToPDFStream(html);

        // show PDF
        if (pdfBytes != null)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "application/PDF";
            //Response.AddHeader("content-disposition", "attachment; filename=Result.pdf");
            Response.AddHeader("content-disposition", "inline; filename=Result.pdf");
            Response.BinaryWrite(pdfBytes);
            Response.Flush();
            Response.End();
        }
    }
Esempio n. 5
0
        static void Main(string[] args)
        {
            // Convert HTML file/url to PDF file.
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();

            //v.Serial = "XXXXXXXXXXXXXXX";

            // Specify the conversion options.
            v.PageStyle.PageSize.Auto();
            //v.PageStyle.PageMarginLeft.Inch(1);
            //v.ImageStyle.Heightmm(150);
            //v.ImageStyle.WidthInch(10);

            // Specify top and bottom page margins.
            //v.PageStyle.PageMarginTop.Mm(5f);
            //v.PageStyle.PageMarginBottom.Mm(5f);

            SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry();

            string   inpUrl  = @"https://nationalzoo.si.edu/";
            FileInfo outFile = new FileInfo(@"Result.pdf");

            int ret = v.ConvertHtmlFileToPDFFile(inpUrl, outFile.FullName);

            // 0 - converting successfully
            // 1 - can't open input file, check the input path
            // 2 - can't create output file, check the output path
            // 3 - converting failed
            if (ret == 0)
            {
                // Open the resulting PDF document in a default PDF Viewer.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName)
                {
                    UseShellExecute = true
                });
            }
        }
Esempio n. 6
0
        private void ConvertImagesToPdf()
        {
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();
            v.PageStyle.PageSize.Auto();
            ArrayList arImageBytes = new ArrayList();

            foreach (var filePath in m_filesPath)
            {
                byte[] imageBytes = null;
                imageBytes = ReadByteArrayFromFile(filePath);
                if (imageBytes != null)
                    arImageBytes.Add(imageBytes);
            }

            string pdfFile = null;

            //Now the arImageBytes contains byte streams of each image
            //Lets convert it to PDF stream in memory
            byte[] pdf = v.ConvertImageStreamArrayToPDFStream(arImageBytes);
            if (pdf != null)
            {
                //Save PDF stream to a file
                pdfFile = Path.Combine(m_FolderName, "hardcopy.pdf");
                File.Delete(pdfFile);
                FileStream fs = File.OpenWrite(pdfFile);
                fs.Write(pdf, 0, pdf.Length);
                fs.Close();
            }

            // Open lesson name form
            LessonNameForm lessonNameForm = new LessonNameForm(pdfFile, m_userName, m_courseId);
            this.Hide();
            lessonNameForm.ShowDialog();

            this.Close();
        }
Esempio n. 7
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            lblTimeElapsed.Text = "";
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();

            watch.Start();

            //Convert many TIFF files to PDF files in the same folder
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();

            string tiffPath = imagesFolder;
            //string[] tiffFiles = Directory.GetFiles(tiffPath, "*.tif");

            var fileNames = new List <String>();

            foreach (string f in Directory.GetFiles(tiffPath, "*.tif"))
            {
                fileNames.Add(f);
            }
            fileNames.Sort();
            foreach (string tiffFile in fileNames)
            {
                v.ConvertImageFileToPDFFile(tiffFile, Path.ChangeExtension(tiffFile, "pdf"));
            }
            //Open the folder with PDF
            //System.Diagnostics.Process.Start(tiffPath);
            //merge 4 PDF files
            string[] pdfFiles = Directory.GetFiles(tiffPath, "*.pdf");
            int      x        = 0;

            foreach (string pdfFile in pdfFiles)
            {
                pdfFiles[x] = @pdfFile;
                x++;
            }


            //int ret = v.MergePDFFileArrayToPDFFile(pdfFiles, @"C:\Development\CDLIS\DocImages\AllRows\mergedfiles.pdf");
            gImagesFolder = tiffPath + "\\MergedPDF";
            Directory.CreateDirectory(gImagesFolder);
            int ret = v.MergePDFFileArrayToPDFFile(pdfFiles, gImagesFolder + "\\MergedPDFs.pdf");

            DirectoryInfo di = new DirectoryInfo(@tiffPath);

            FileInfo[] files = di.GetFiles("*.pdf").Where(p => p.Extension == ".pdf").ToArray();
            foreach (FileInfo file in files)
            {
                try
                {
                    file.Attributes = FileAttributes.Normal;
                    File.Delete(file.FullName);
                }
                catch { }
            }

            //0 - merged successfully
            //1 - error, can't merge PDF documents
            //2 - error, can't create output file, probably it used by another application
            //3 - merging failed
            //4 - merged successfully, but some files were not merged
            //if (ret == 0)
            //{
            //    System.Diagnostics.Process.Start(tiffPath + "\\mergedfiles.pdf");
            //}
            watch.Stop();
            TimeSpan ts = watch.Elapsed;

            GlobalVariables.ElapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                        ts.Hours, ts.Minutes, ts.Seconds,
                                                        ts.Milliseconds / 10);
            lblTimeElapsed.Text = GlobalVariables.ElapsedTime;
        }
Esempio n. 8
0
    protected void btn_adminexcel_Click(object sender, EventArgs e)
    {
        if (Session["User_ID"] != null && Session["User_ID"].ToString() != "")
        {
            try
            {
                string   url   = HttpContext.Current.Request.Url.AbsoluteUri;
                string[] surl  = url.Split('/');
                string   excel = hdn_excel.Value.ToString();
                excel = excel.Replace("localhost:14851", surl[2]);
                //string excel = hdn_excel.Value.ToString();
                string Partno    = hdn_partno1.Value.ToString();
                string Shift     = hdn_shift1.Value.ToString();
                string mach      = hdn_mach1.Value.ToString();
                string operators = hdn_operator.Value.ToString();
                string Operation = hdn_operation1.Value.ToString();
                path = Request.PhysicalApplicationPath + "Document\\" + Partno.ToString() + "\\";
                //string datetime = DateTime.Now.Day.ToString() + "." + DateTime.Now.Month.ToString() + "." + DateTime.Now.Year.ToString();
                //string srchdate = Convert.ToDateTime(hdn_date1.Value).ToString("dd/MM/yyyy");
                DateTime srchdate = DateTime.ParseExact(hdn_date1.Value, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                //string srchingdate = Convert.ToDateTime(hdn_date1.Value).ToString("MM/dd/yyyy");
                DateTime ldate = Convert.ToDateTime(srchdate);
                //DateTime ldate = Convert.ToDateTime(srchingdate);
                string datetime = ldate.Day.ToString() + "." + ldate.Month.ToString() + "." + ldate.Year.ToString();
                createfolder(datetime);
                string html = excel.ToString();
                html = html.Replace("&gt;", ">");
                html = html.Replace("&lt;", "<");
                string filenamerp = "";
                Response.ClearContent();
                Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "QCSheet.xls"));
                Response.ContentType = "application/ms-excel";
                //string date = DateTime.Now.ToString("MM-dd-yyyy");
                string date    = ldate.ToString("MM-dd-yyyy");
                string f_name1 = "QS_Report_" + date.ToString() + "_" + Partno.ToString() + Shift.ToString() + "_" + mach.ToString() + "_" + operators.ToString() + "_" + Operation.ToString() + ".xls";
                string f_name  = "QS_Report_" + date.ToString() + "_" + Partno.ToString() + Shift.ToString() + "_" + mach.ToString() + "_" + operators.ToString() + "_" + Operation.ToString() + ".pdf";
                filenamerp             = f_name1;
                Session["WorkingFile"] = filenamerp.ToString();
                string path1 = Server.MapPath("~/Document/" + Partno.ToString() + "\\" + datetime.ToString() + "\\" + HttpContext.Current.Session["WorkingFile"].ToString());
                //string path1 = Server.MapPath("~/Document/A17724Q" + "\\" + Pidno.ToString());
                FileInfo      fi = new FileInfo(Server.MapPath("../Styles/QualitySheetDesign.css"));
                StringBuilder sb = new StringBuilder();
                StreamReader  sr = fi.OpenText();
                while (sr.Peek() >= 0)
                {
                    sb.Append(sr.ReadLine());
                }
                sr.Close();

                FileInfo      fi1 = new FileInfo(Server.MapPath("../Styles/Dynamicmenu.css"));
                StringBuilder sb1 = new StringBuilder();
                StreamReader  sr1 = fi1.OpenText();
                while (sr1.Peek() >= 0)
                {
                    sb1.Append(sr1.ReadLine());
                }
                sr1.Close();
                FileInfo      fi2 = new FileInfo(Server.MapPath("../Styles/QualityStyle.css"));
                StringBuilder sb2 = new StringBuilder();
                StreamReader  sr2 = fi2.OpenText();
                while (sr2.Peek() >= 0)
                {
                    sb2.Append(sr2.ReadLine());
                }
                sr2.Close();
                string   style = "<html><head><style type='text/css'>" + sb.ToString() + "" + sb1.ToString() + "" + sb2.ToString() + "</style></head><body>" + html.ToString() + "</body></html>";
                FileInfo file  = new FileInfo(path1);
                if (file.Exists)
                {
                    file.Delete();
                    path = Server.MapPath("~/Document/" + Partno.ToString() + "\\" + datetime.ToString() + "\\");
                    File.AppendAllText(path + Session["WorkingFile"].ToString(), style.ToString());
                }
                else
                {
                    path = Server.MapPath("~/Document/" + Partno.ToString() + "\\" + datetime.ToString() + "\\");
                    File.AppendAllText(path + Session["WorkingFile"].ToString(), style.ToString());
                }
                SautinSoft.PdfVision objv = new SautinSoft.PdfVision();
                //objv.ConvertHtmlFileToPDFFile(@"http://localhost:52753/Dynamic/DYNSheets/QualitySheet.aspx", path + Session["WorkingFile"].ToString());
                //objv.ConvertHtmlStringToPDFFile(style.ToString(), path + f_name.ToString());
                string p = path + "/" + Session["WorkingFile"].ToString();
                objqualitysheetbl.insertupdatereportsBL(Session["WorkingFile"].ToString(), p.ToString(), 1, Convert.ToDateTime(DateTime.Today), hdn_shift1.Value.ToString(), hdn_operator.Value.ToString());
            }
            catch (Exception ex)
            {
                //throw ex;
            }
            finally
            {
            }
        }
        else
        {
            HttpContext.Current.Response.Redirect("../Home.aspx", false); HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
    }
Esempio n. 9
0
 public void mostrar_reporte_tokens()
 {
     Process.Start("Tokens.html");
     SautinSoft.PdfVision v = new SautinSoft.PdfVision();
     v.ConvertHtmlFileToPDFFile(@"C:/Users/marco/Documents/GitHub/PROYECTO1_OLC1/Proyecto1_201700328/Proyecto1_201700328/bin/Debug/Tokens.html", @"C:/Users/marco/Documents/GitHub/PROYECTO1_OLC1/Proyecto1_201700328/Proyecto1_201700328/bin/Debug/salida.pdf");
 }