예제 #1
0
        /// <summary>
        /// Creates PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Load a PDF document.
            PdfLoadedDocument document = new PdfLoadedDocument(GetFullTemplatePath("EmpDetails.pdf", false));

            //Get first page from document
            PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;

            //Create PDF redaction for the page to redact text
            PdfRedaction textRedaction = new PdfRedaction(new RectangleF(343, 147, 60, 17), System.Drawing.Color.Black);
            //Create PDF redaction for the page to redact image
            PdfRedaction imageRedaction = new PdfRedaction(new RectangleF(67, 372, 178, 158), System.Drawing.Color.Black);

            //Adds the redactions to loaded page
            page.Redactions.Add(textRedaction);
            page.Redactions.Add(imageRedaction);

            //Save the PDF document
            document.Save("Redacted.pdf");

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
                Process.Start("Redacted.pdf");
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
예제 #2
0
        /// <summary>
        /// Splits and creates a new PDF document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSplit_Click(object sender, EventArgs e)
        {
            string dataPath1 = File1.ResolveClientUrl(File1.Value);

            if (System.IO.Path.GetExtension(dataPath1).Equals(".pdf"))
            {
                Stream stream1 = File1.PostedFile.InputStream;

                //Load a PDF document
                PdfLoadedDocument ldoc = new PdfLoadedDocument(stream1);

                //Get first page from document
                PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;

                if (x.Text != "" && y.Text != "" && width.Text != "" && height.Text != "")
                {
                    float x1      = float.Parse(x.Text);
                    float y1      = float.Parse(y.Text);
                    float width1  = float.Parse(width.Text);
                    float height1 = float.Parse(height.Text);

                    //Create PDF redaction for the page
                    PdfRedaction redaction = new PdfRedaction(new RectangleF(x1, y1, width1, height1), Color.Black);

                    //Adds the redaction to loaded page
                    lpage.Redactions.Add(redaction);

                    //Save to disk
                    if (this.CheckBox1.Checked)
                    {
                        ldoc.Save("Document1.pdf", Response, HttpReadType.Open);
                    }
                    else
                    {
                        ldoc.Save("Document1.pdf", Response, HttpReadType.Save);
                    }
                }
                else
                {
                    lb_error.Visible = true;
                    lb_error.Text    = "Note: Fill all the fields then redact";
                }
            }
            else
            {
                lb_error.Visible = true;
                lb_error.Text    = "Invalid file type. Please select a PDF file";
            }
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            //Load an existing PDF.
            PdfLoadedDocument document = new PdfLoadedDocument(this.GetFullTemplatePath(@"Redaction.pdf", false));

            //Get first page from document
            PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;

            //Create PDF redaction for the page to redact text
            PdfRedaction textRedaction = new PdfRedaction(new RectangleF(86.998f, 39.565f, 62.709f, 20.802f), System.Drawing.Color.Black);
            //Create PDF redaction for the page to redact text
            PdfRedaction pathRedaction = new PdfRedaction(new RectangleF(83.7744f, 576.066f, 210.0746f, 104.155f), System.Drawing.Color.Black);
            //Create PDF redaction for the page to redact text
            PdfRedaction imageRedaction = new PdfRedaction(new RectangleF(327.848f, 63.97198f, 232.179f, 223.429f), System.Drawing.Color.Black);

            //Adds the redactions to loaded page
            page.Redactions.Add(textRedaction);
            page.Redactions.Add(pathRedaction);
            page.Redactions.Add(imageRedaction);

            //Save and close the PDF document
            document.Save("Redacted.pdf");
            document.Close(true);

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Redacted.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                System.Diagnostics.Process.Start("Redacted.pdf");
#endif
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
        public ActionResult Redaction(string Browser, string x, string y, string width, string height)
        {
            if (Request.Form.Files != null && Request.Form.Files.Count != 0)
            {
                float x1;
                float y1;
                float width1;
                float height1;
                if (x != null && x.Length > 0 && float.TryParse(x.ToString(), out x1) && y != null && y.Length > 0 && float.TryParse(y.ToString(), out y1) && width != null && width.Length > 0 && float.TryParse(width.ToString(), out width1) && height != null && height.Length > 0 && float.TryParse(height.ToString(), out height1))
                {
                    //Load a PDF document
                    PdfLoadedDocument ldoc = new PdfLoadedDocument(Request.Form.Files[0].OpenReadStream());
                    //Get first page from document
                    PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;

                    //Create PDF redaction for the page
                    PdfRedaction redaction = new PdfRedaction(new Syncfusion.Drawing.RectangleF(x1, y1, width1, height1), Syncfusion.Drawing.Color.Black);

                    //Adds the redaction to loaded page
                    lpage.AddRedaction(redaction);
                    ldoc.Redact();
                    //Save the PDF to the MemoryStream
                    MemoryStream ms = new MemoryStream();

                    ldoc.Save(ms);

                    //If the position is not set to '0' then the PDF will be empty.
                    ms.Position = 0;

                    ldoc.Close(true);
                    //Download the PDF document in the browser.
                    FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
                    fileStreamResult.FileDownloadName = "Redaction.pdf";
                    return(fileStreamResult);
                }
                else
                {
                    ViewBag.lab = "Fill proper redaction bounds to redact";
                }
            }
            else
            {
                ViewBag.lab = "Choose PDF document to redact";
            }
            return(View());
        }
예제 #5
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            //Load an existing PDF.
            PdfLoadedDocument document = new PdfLoadedDocument(this.GetFullTemplatePath(@"EmpDetails.pdf", false));

            //Get first page from document
            PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;

            //Create PDF redaction for the page to redact text
            PdfRedaction textRedaction = new PdfRedaction(new RectangleF(343, 147, 60, 17), System.Drawing.Color.Black);
            //Create PDF redaction for the page to redact image
            PdfRedaction imageRedaction = new PdfRedaction(new RectangleF(67, 372, 178, 158), System.Drawing.Color.Black);

            //Adds the redactions to loaded page
            page.Redactions.Add(textRedaction);
            page.Redactions.Add(imageRedaction);

            //Save and close the PDF document
            document.Save("Redacted.pdf");
            document.Close(true);

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Redacted.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                System.Diagnostics.Process.Start("Redacted.pdf");
#endif
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
        public ActionResult Redaction(string Browser, string x, string y, string width, string height, HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);

                float x1;
                float y1;
                float width1;
                float height1;
                if (x != null && x.Length > 0 && float.TryParse(x.ToString(), out x1) && y != null && y.Length > 0 && float.TryParse(y.ToString(), out y1) && width != null && width.Length > 0 && float.TryParse(width.ToString(), out width1) && height != null && height.Length > 0 && float.TryParse(height.ToString(), out height1))
                {
                    //Load a PDF document
                    PdfLoadedDocument ldoc = new PdfLoadedDocument(file.InputStream);
                    //Get first page from document
                    PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;

                    //Create PDF redaction for the page
                    PdfRedaction redaction = new PdfRedaction(new RectangleF(x1, y1, width1, height1), Color.Black);

                    //Adds the redaction to loaded page
                    lpage.Redactions.Add(redaction);

                    //Save to disk
                    if (Browser == "Browser")
                    {
                        return(ldoc.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
                    }
                    else
                    {
                        return(ldoc.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
                    }
                }
                else
                {
                    ViewBag.lab = "Fill proper redaction bounds to redact";
                }
            }
            else
            {
                ViewBag.lab = "Choose PDF document to redact";
            }
            return(View());
        }
        public ActionResult Redaction(string viewTemplate, string RedactPdf, string Browser, string x, string y, string width, string height)
        {
            if (viewTemplate == "View Template")
            {
                string basePath = _hostingEnvironment.WebRootPath;
                string dataPath = string.Empty;
                dataPath = basePath + @"/PDF/";

                //Read the file
                FileStream file = new FileStream(dataPath + "Redaction.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                //Load the template document
                PdfLoadedDocument doc = new PdfLoadedDocument(file);

                //Save the PDF to the MemoryStream
                MemoryStream ms = new MemoryStream();
                doc.Save(ms);

                //If the position is not set to '0' then the PDF will be empty.
                ms.Position = 0;

                //Close the PDF document.
                doc.Close(true);

                //Download the PDF document in the browser.
                FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
                fileStreamResult.FileDownloadName = "RedactionTemplate.pdf";
                return(fileStreamResult);
            }
            else if (RedactPdf == "Redact PDF")
            {
                string basePath = _hostingEnvironment.WebRootPath;
                string dataPath = string.Empty;
                dataPath = basePath + @"/PDF/";

                //Read the file
                FileStream file = new FileStream(dataPath + "Redaction.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                //Load the template document
                PdfLoadedDocument doc = new PdfLoadedDocument(file);

                PdfLoadedPage lpage = doc.Pages[0] as PdfLoadedPage;

                PdfRedaction textRedaction = new PdfRedaction(new Syncfusion.Drawing.RectangleF(86.998f, 39.565f, 62.709f, 20.802f), Syncfusion.Drawing.Color.Black);
                //Create PDF redaction for the page to redact text
                PdfRedaction pathRedaction = new PdfRedaction(new Syncfusion.Drawing.RectangleF(83.7744f, 576.066f, 210.0746f, 104.155f), Syncfusion.Drawing.Color.Black);
                //Create PDF redaction for the page to redact text
                PdfRedaction imageRedation = new PdfRedaction(new Syncfusion.Drawing.RectangleF(327.848f, 63.97198f, 232.179f, 223.429f), Syncfusion.Drawing.Color.Black);

                lpage.AddRedaction(textRedaction);
                lpage.AddRedaction(pathRedaction);
                lpage.AddRedaction(imageRedation);

                doc.Redact();
                //Save the PDF to the MemoryStream
                MemoryStream ms = new MemoryStream();
                doc.Save(ms);

                //If the position is not set to '0' then the PDF will be empty.
                ms.Position = 0;

                //Close the PDF document.
                doc.Close(true);

                //Download the PDF document in the browser.
                FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
                fileStreamResult.FileDownloadName = "Redaction.pdf";
                return(fileStreamResult);
            }
            else
            {
                if (Request.Form.Files != null && Request.Form.Files.Count != 0 && viewTemplate != "View Template")
                {
                    float x1;
                    float y1;
                    float width1;
                    float height1;
                    if (x != null && x.Length > 0 && float.TryParse(x.ToString(), out x1) && y != null && y.Length > 0 && float.TryParse(y.ToString(), out y1) && width != null && width.Length > 0 && float.TryParse(width.ToString(), out width1) && height != null && height.Length > 0 && float.TryParse(height.ToString(), out height1))
                    {
                        //Load a PDF document
                        PdfLoadedDocument ldoc = new PdfLoadedDocument(Request.Form.Files[0].OpenReadStream());
                        //Get first page from document
                        PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;

                        //Create PDF redaction for the page
                        PdfRedaction redaction = new PdfRedaction(new Syncfusion.Drawing.RectangleF(x1, y1, width1, height1), Syncfusion.Drawing.Color.Black);

                        //Adds the redaction to loaded page
                        lpage.AddRedaction(redaction);
                        ldoc.Redact();
                        //Save the PDF to the MemoryStream
                        MemoryStream ms = new MemoryStream();

                        ldoc.Save(ms);

                        //If the position is not set to '0' then the PDF will be empty.
                        ms.Position = 0;

                        ldoc.Close(true);
                        //Download the PDF document in the browser.
                        FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
                        fileStreamResult.FileDownloadName = "Redaction.pdf";
                        return(fileStreamResult);
                    }
                    else
                    {
                        ViewBag.lab = "Fill proper redaction bounds to redact";
                    }
                }
                else
                {
                    ViewBag.lab = "Choose PDF document to redact";
                }
            }
            return(View());
        }
        public ActionResult Redaction(string viewTemplate, string RedactPdf, string Browser, string x, string y, string width, string height, HttpPostedFileBase file)
        {
            if (viewTemplate == "View Template")
            {
                string dataPath = ResolveApplicationDataPath("Redaction.pdf");
                Stream file2    = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                //Load the template document
                PdfLoadedDocument doc = new PdfLoadedDocument(file2);
                return(doc.ExportAsActionResult("RedactionTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else if (RedactPdf == "Redact PDF")
            {
                string dataPath = ResolveApplicationDataPath("Redaction.pdf");
                Stream file2    = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                //Load the template document
                PdfLoadedDocument doc = new PdfLoadedDocument(file2);

                PdfLoadedPage lpage = doc.Pages[0] as PdfLoadedPage;

                PdfRedaction textRedaction = new PdfRedaction(new RectangleF(86.998f, 39.565f, 62.709f, 20.802f), System.Drawing.Color.Black);
                //Create PDF redaction for the page to redact text
                PdfRedaction pathRedaction = new PdfRedaction(new RectangleF(83.7744f, 576.066f, 210.0746f, 104.155f), System.Drawing.Color.Black);
                //Create PDF redaction for the page to redact text
                PdfRedaction imageRedation = new PdfRedaction(new RectangleF(327.848f, 63.97198f, 232.179f, 223.429f), System.Drawing.Color.Black);

                lpage.Redactions.Add(textRedaction);
                lpage.Redactions.Add(pathRedaction);
                lpage.Redactions.Add(imageRedation);

                return(doc.ExportAsActionResult("Redaction.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
            else
            {
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);

                    float x1;
                    float y1;
                    float width1;
                    float height1;
                    if (x != null && x.Length > 0 && float.TryParse(x.ToString(), out x1) && y != null && y.Length > 0 && float.TryParse(y.ToString(), out y1) && width != null && width.Length > 0 && float.TryParse(width.ToString(), out width1) && height != null && height.Length > 0 && float.TryParse(height.ToString(), out height1))
                    {
                        //Load a PDF document
                        PdfLoadedDocument ldoc = new PdfLoadedDocument(file.InputStream);
                        //Get first page from document
                        PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;

                        //Create PDF redaction for the page
                        PdfRedaction redaction = new PdfRedaction(new RectangleF(x1, y1, width1, height1), Color.Black);

                        //Adds the redaction to loaded page
                        lpage.Redactions.Add(redaction);

                        //Save to disk
                        if (Browser == "Browser")
                        {
                            return(ldoc.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
                        }
                        else
                        {
                            return(ldoc.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
                        }
                    }
                    else
                    {
                        ViewBag.lab = "Fill proper redaction bounds to redact";
                    }
                }
                else
                {
                    ViewBag.lab = "Choose PDF document to redact";
                }
            }
            return(View());
        }