/// <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";
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_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 existing PDF document
                PdfLoadedDocument ldoc = new PdfLoadedDocument(stream1);

                //Create a new PDF compression options
                PdfCompressionOptions options = new PdfCompressionOptions();

                if (this.compressImage.Checked)
                {
                    //Compress image.
                    options.CompressImages = true;
                    options.ImageQuality   = int.Parse(this.imageQuality.SelectedValue);
                }
                else
                {
                    options.CompressImages = false;
                }
                //Compress the font data
                if (this.optFont.Checked)
                {
                    options.OptimizeFont = true;
                }
                else
                {
                    options.OptimizeFont = false;
                }
                //Compress the page contents
                if (this.optPageContents.Checked)
                {
                    options.OptimizePageContents = true;
                }
                else
                {
                    options.OptimizePageContents = false;
                }
                //Remove the metadata information.
                if (this.removeMetadata.Checked)
                {
                    options.RemoveMetadata = true;
                }
                else
                {
                    options.RemoveMetadata = false;
                }

                //Set the options to loaded PDF document
                ldoc.CompressionOptions = options;

                //Save to disk
                if (this.CheckBox1.Checked)
                {
                    ldoc.Save("Document1.pdf", Response, HttpReadType.Open);
                }
                else
                {
                    ldoc.Save("Document1.pdf", Response, HttpReadType.Save);
                }
            }
        }