C# Archives - Tech Insights https://reactconf.org/category/how-to-delete-or-remove-from-pdf-pages-using-c-windows-application/ Unveiling Tomorrow's Tech Today, Where Innovation Meets Insight Sun, 20 Dec 2020 07:36:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://i0.wp.com/reactconf.org/wp-content/uploads/2023/11/cropped-reactconf.png?fit=32%2C32&ssl=1 C# Archives - Tech Insights https://reactconf.org/category/how-to-delete-or-remove-from-pdf-pages-using-c-windows-application/ 32 32 230003556 How to delete or remove pages from PDF files Using C# Windows application https://reactconf.org/how-to-delete-or-remove-from-pdf-pages/ https://reactconf.org/how-to-delete-or-remove-from-pdf-pages/#respond Sun, 20 Dec 2020 07:36:00 +0000 https://reactconf.org/how-to-delete-or-remove-from-pdf-pages/  In this article, I will explain to you, how to delete or Remove a PDF page using the C# Windows Application. This small application features. a.    This application deletes …

The post How to delete or remove pages from PDF files Using C# Windows application appeared first on Tech Insights.

]]>
 In this article, I will explain to you, how to delete or Remove a PDF page using the C# Windows Application.

This small application features.

a.    This application deletes the pdf page by selecting a page number.

b.      This is very useful when real-time work in any workstation, The Client needs this type of requirement or he wants to print pdf documents but inside pdf documents blank pages. So this situation needs to delete a blank page because if every PDF has one or two pages blank it’s cost-effective. So for this purpose, I developed this application.

c.      This application also has a feature to delete multiple PDF document blank pages in one click.

     Steps.

  1.   Create a new Windows application project.
  2.   Drag and drop controls textbox, Combobox, and buttons.
  3.   Install FreeSpire.PDF NuGet Package.
  4.  Include the following namespace in .cs program file.

 

 

 

 

Delete PDF Pages Using C#

To Delete PDF pages using C# here’s the below example.

Source code

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using Spire.Pdf;

 

namespace PDFbuild

{

    public partial class Form1: Form

    {

        public Form1()

        {

            InitializeComponent();

        } 

        private voidbutton1_Click(object sender, EventArgs e)

        {

            FolderBrowserDialog folderDlg = newFolderBrowserDialog();

            folderDlg.ShowNewFolderButton = true;

            // Show the FolderBrowserDialog. 

            DialogResult result = folderDlg.ShowDialog();

            if(result == DialogResult.OK)

            {

                textBox1.Text = folderDlg.SelectedPath;

                Environment.SpecialFolder root = folderDlg.RootFolder;

            } 

        }

 

        private voidbutton2_Click(object sender, EventArgs e)

        {

             if(textBox1.Text == “”)

            {

                MessageBox.Show(“Please select source path”);

                return;

            }

            if(textBox2.Text == “”)

            {

                MessageBox.Show(“Please select destination path “);

                return;

            }

            if(comboBox1.SelectedIndex == 0)

            {

                MessageBox.Show(“Please select page”);

                return;

            } 

            stringroot = textBox1.Text;

            stringdestroot = textBox2.Text;

            string[] fileEntries = Directory.GetFiles(root);      

             intpage=-0;

            if(comboBox1.Text == “1”)

            {

                page = 0;

            }

            if(comboBox1.Text == “2”)

            {

                page = 1;

            }

            if(comboBox1.Text == “3”)

            { page = 2;

            }            

            foreach(string fileName in fileEntries)

            { 

                PdfDocument document = new PdfDocument(); 

                document.LoadFromFile(fileName); 

                document.Pages.RemoveAt(page); 

                stringfilen = Path.GetFileName(fileName);

                document.SaveToFile(destroot + “\”+ filen); 

            }

             MessageBox.Show(“Done”);

        }

 

        private voidbutton3_Click(object sender, EventArgs e)

        {

            FolderBrowserDialog folderDlg = new FolderBrowserDialog();

            folderDlg.ShowNewFolderButton = true;

            // Show the FolderBrowserDialog. 

            DialogResult result = folderDlg.ShowDialog();

            if(result == DialogResult.OK)

            {

                textBox2.Text = folderDlg.SelectedPath;

                Environment.SpecialFolder root = folderDlg.RootFolder;

            }

        }

         private voidForm1_Load(object sender, EventArgs e)

        {

            comboBox1.SelectedIndex = 0;

        }       

    }

} 

 

 

The post How to delete or remove pages from PDF files Using C# Windows application appeared first on Tech Insights.

]]>
https://reactconf.org/how-to-delete-or-remove-from-pdf-pages/feed/ 0 12