This article guides on how to edit PDF document using C#. It has the information to set the development environment, a list of required steps to perform the task, and a runnable sample code to develop a PDF editor application using C#. We will also discuss the necessary classes, methods and properties to perform modifications in a PDF file.
Steps to Modify PDF File using C#
- Configure the IDE to use Aspose.PDF for .NET for editing
- Create an object of the PdfContentEditor class to replace text in the entire file
- Replace some other text along with setting the foreground color and font size, and save to the memory stream
- Load the stream into the PdfFileMend object for adding some text and saving it back to the memory stream
- Load the resultant memory stream into the Document class for adding a page with some text
- Save the final PDF file on the disk with all the above modifications
These steps present the process to modify PDF document using C#. You may use the PdfContentEditor object to replace text in the entire file or replace text with different foreground colors and fonts. The PdfFileMend class is used to add text to an existing page whereas the Document class is used to add a new page and render some text on it.
Code to Change PDF File using C#
This code demonstrates the development of a PDF modifier using C#. We use different classes to modify the contents and save the intermediate results into a temporary memory stream for loading into the next class for performing another task. There are various classes that can be used to modify a PDF file including PdfPageEditor, PdfFileStamp, PdfFileSignature, PdfConverter, and PdfBookmarkEditor to name a few.
This article showed us the working of a software PDF editor using C#. If you want to learn the process of changing the background of a PDF file, refer to the article on how to edit PDF background color using C#.